Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/fleet/common/return_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ReturnTypeDelete extends BaseReturnType {
export interface ReturnTypeCheckin extends BaseReturnType {
action: 'checkin';
actions: Array<{
id: string;
type: string;
data?: object;
}>;
Expand Down
66 changes: 66 additions & 0 deletions x-pack/legacy/plugins/fleet/dev_docs/actions_and_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Agent Fleet: actions protocol

Agent is using `actions` and `events` to comunicate with fleet during checkin.

## Actions

Action are returned to the agent during the checkin [see](./api/agents_checkin)
Agent should aknowledge the fact they received an action for that they can send one of this two events during checkin:

```js
{
"events": [{
{
"type": "ACTION",
"subtype": "ACKNOWLEDGED"
"message": "acknowledge action : 1",
"action_id": "action_id_1" ,
"timestamp": "2018-01-02T.."
}, {
"type": "ACTION",
"subtype": "UNKNOWN"
"message": "Unsupported action : 2",
"action_id": "action_id_2" ,
"timestamp": "2018-01-02T.."
}]
}
```

### POLICY_CHANGE

This action is send when a new policy is available, the policy is available under the `data` field.

```js
{
"type": "POLICY_CHANGE",
"id": "action_id_1",
"data": {
"policy": {
"id": "policy_id",
"outputs": {
"default": {
"api_key": "slfhsdlfhjjkshfkjh:sdfsdfsdfsdf",
"id": "default",
"name": "Default",
"type": "elasticsearch",
"url": "https://localhost:9200",
}
},
"streams": [
{
"metricsets": [
"container",
"cpu"
],
"id": "string",
"type": "etc",
"output": {
"use_output": "default"
}
}
]
}
}
}]
}
```
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/fleet/dev_docs/api/agents_checkin.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Authorization: ApiKey VALID_ACCESS_API_KEY
{
"action": "checkin",
"success": true,
"policy": {
},
"actions": []
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
EuiHorizontalRule,
EuiSelect,
EuiSpacer,
EuiSuperSelect,
EuiText,
EuiTitle,
} from '@elastic/eui';
Expand All @@ -41,7 +40,6 @@ interface RouterProps {

export const AgentEnrollmentFlyout: React.FC<RouterProps> = ({ onClose, policies }) => {
const libs = useLibs();
const [selectedPolicy, setSelectedPolicy] = useState('');
const [quickInstallType, setQuickInstallType] = useState<'shell' | 'container' | 'tools'>(
'shell'
);
Expand Down Expand Up @@ -133,21 +131,6 @@ export const AgentEnrollmentFlyout: React.FC<RouterProps> = ({ onClose, policies
<EnrollmentApiKeysTable />
</>
)}
<EuiSpacer size="m" />
<EuiFormRow
label={
<FormattedMessage
id="xpack.fleet.agentEnrollment.enrollIntoSelectionTitle"
defaultMessage="Enroll into policy"
/>
}
>
<EuiSuperSelect
options={policies.map(p => ({ value: p.id, inputDisplay: p.name }))}
valueOfSelected={selectedPolicy || ''}
onChange={value => setSelectedPolicy(value)}
/>
</EuiFormRow>
</>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const ShellEnrollmentInstructions: React.FC<Props> = ({ kibanaUrl, apiKey
const [isManualInstallationOpen, setIsManualInstallationOpen] = useState<boolean>(false);

// Build quick installation command
const quickInstallInstructions = `API_KEY=${apiKey.api_key} curl ${kibanaUrl}/api/fleet/install/${currentPlatform} | bash`;
const quickInstallInstructions = `API_KEY=${apiKey.api_key} sh -c "$(curl ${kibanaUrl}/api/fleet/install/${currentPlatform})"`;

return (
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
SavedObjectsCreateOptions,
SavedObjectsBulkGetObject,
SavedObjectsUpdateResponse,
SavedObjectsBulkUpdateObject,
SavedObjectsBulkUpdateOptions,
SavedObjectsBulkUpdateResponse,
} from 'src/core/server';
import { FrameworkUser } from '../framework/adapter_types';

Expand All @@ -33,6 +36,12 @@ export interface SODatabaseAdapter {
options?: SavedObjectsCreateOptions
): Promise<SavedObjectsBulkResponse<T>>;

bulkUpdate<T extends SavedObjectAttributes = any>(
user: FrameworkUser,
objects: Array<SavedObjectsBulkUpdateObject<T>>,
options?: SavedObjectsBulkUpdateOptions
): Promise<SavedObjectsBulkUpdateResponse<T>>;

delete(
user: FrameworkUser,
type: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
SavedObjectsUpdateResponse,
SavedObjectsClient as SavedObjectsClientType,
SavedObjectsLegacyService,
SavedObjectsBulkUpdateObject,
SavedObjectsBulkUpdateOptions,
} from 'src/core/server';
import { ElasticsearchPlugin } from 'src/legacy/core_plugins/elasticsearch';
import { SODatabaseAdapter as SODatabaseAdapterType } from './adapter_types';
Expand Down Expand Up @@ -78,6 +80,20 @@ export class SODatabaseAdapter implements SODatabaseAdapterType {
return await this.getClient(user).bulkCreate(objects, options);
}

/**
* Persists multiple documents batched together as a single request
*
* @param objects
* @param options
*/
async bulkUpdate<T extends SavedObjectAttributes = any>(
user: FrameworkUser,
objects: Array<SavedObjectsBulkUpdateObject<T>>,
options?: SavedObjectsBulkUpdateOptions
) {
return await this.getClient(user).bulkUpdate(objects, options);
}

/**
* Deletes a SavedObject
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
SavedObjectsCreateOptions,
SavedObjectsBulkGetObject,
SavedObjectsUpdateResponse,
SavedObjectsBulkUpdateObject,
SavedObjectsBulkUpdateOptions,
} from 'src/core/server';
import { SODatabaseAdapter as SODatabaseAdapterType } from './adapter_types';
import { SODatabaseAdapter } from './default';
Expand All @@ -43,7 +45,24 @@ export class MemorizeSODatabaseAdapter implements SODatabaseAdapterType {
);
}

async bulkCreate<T extends SavedObjectAttributes = any>(
public async bulkUpdate<T extends SavedObjectAttributes = any>(
user: FrameworkUser,
objects: Array<SavedObjectsBulkUpdateObject<T>>,
options?: SavedObjectsBulkUpdateOptions
) {
return Slapshot.memorize(
`bulkUpdate`,
() => {
if (!this.soAdadpter) {
throw new Error('An adapter must be provided when running tests online');
}
return this.soAdadpter.bulkUpdate(user, objects, options);
},
{ pure: false }
);
}

public async bulkCreate<T extends SavedObjectAttributes = any>(
user: FrameworkUser,
objects: Array<SavedObjectsBulkCreateObject<T>>,
options?: SavedObjectsCreateOptions
Expand Down
5 changes: 5 additions & 0 deletions x-pack/legacy/plugins/fleet/server/kibana.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export const initServerWithKibana = (hapiServer: any) => {
policyId: event.policyId,
});
}

if (event.type === 'updated') {
await libs.agentsPolicy.updateAgentsForPolicyId(user, event.policyId);
}

if (event.type === 'deleted') {
await libs.agents.unenrollForPolicy(user, event.policyId);
await libs.apiKeys.deleteEnrollmentApiKeyForPolicyId(user, event.policyId);
Expand Down
Loading