Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Allow to send SETTINGS action #83707

Merged
merged 5 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/plugins/fleet/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type AgentActionType =
| 'POLICY_CHANGE'
| 'UNENROLL'
| 'UPGRADE'
| 'SETTINGS'
// INTERNAL* actions are mean to interupt long polling calls these actions will not be distributed to the agent
| 'INTERNAL_POLICY_REASSIGN';

Expand Down
33 changes: 22 additions & 11 deletions x-pack/plugins/fleet/server/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,25 @@ export const AgentEventSchema = schema.object({
id: schema.string(),
});

export const NewAgentActionSchema = schema.object({
type: schema.oneOf([
schema.literal('POLICY_CHANGE'),
schema.literal('UNENROLL'),
schema.literal('UPGRADE'),
schema.literal('INTERNAL_POLICY_REASSIGN'),
]),
data: schema.maybe(schema.any()),
ack_data: schema.maybe(schema.any()),
sent_at: schema.maybe(schema.string()),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed sent_at and ack_data as there is no need for them when creating an action

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we change saved object definition and add migrations to match?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's required in the saved_object we update that when the agent acknowledge an action, but it's not on a new action

});
export const NewAgentActionSchema = schema.oneOf([
schema.object({
type: schema.oneOf([
schema.literal('POLICY_CHANGE'),
schema.literal('UNENROLL'),
schema.literal('UPGRADE'),
schema.literal('INTERNAL_POLICY_REASSIGN'),
]),
data: schema.any(),
}),
schema.object({
type: schema.oneOf([schema.literal('SETTINGS')]),
data: schema.object({
log_level: schema.oneOf([
schema.literal('debug'),
schema.literal('info'),
schema.literal('warning'),
schema.literal('error'),
]),
}),
}),
]);
39 changes: 35 additions & 4 deletions x-pack/test/fleet_api_integration/apis/agents/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,51 @@ export default function (providerContext: FtrProviderContext) {
expect(apiResponse.item.data).to.eql({ data: 'action_data' });
});

it('should return a 200 if this a valid SETTINGS action request', async () => {
const { body: apiResponse } = await supertest
.post(`/api/fleet/agents/agent1/actions`)
.set('kbn-xsrf', 'xx')
.send({
action: {
type: 'SETTINGS',
data: { log_level: 'debug' },
},
})
.expect(200);

expect(apiResponse.item.type).to.eql('SETTINGS');
expect(apiResponse.item.data).to.eql({ log_level: 'debug' });
});

it('should return a 400 if this a invalid SETTINGS action request', async () => {
const { body: apiResponse } = await supertest
.post(`/api/fleet/agents/agent1/actions`)
.set('kbn-xsrf', 'xx')
.send({
action: {
type: 'SETTINGS',
data: { log_level: 'thisnotavalidloglevel' },
},
})
.expect(400);

expect(apiResponse.message).to.match(
/\[request body.action\.[0-9]*\.data\.log_level]: types that failed validation/
);
});

it('should return a 400 when request does not have type information', async () => {
const { body: apiResponse } = await supertest
.post(`/api/fleet/agents/agent1/actions`)
.set('kbn-xsrf', 'xx')
.send({
action: {
data: { data: 'action_data' },
sent_at: '2020-03-18T19:45:02.620Z',
},
})
.expect(400);
expect(apiResponse.message).to.eql(
'[request body.action.type]: expected at least one defined value but got [undefined]'
expect(apiResponse.message).to.match(
/\[request body.action\.[0-9]*\.type]: expected at least one defined value but got \[undefined]/
);
});

Expand All @@ -60,7 +92,6 @@ export default function (providerContext: FtrProviderContext) {
action: {
type: 'POLICY_CHANGE',
data: { data: 'action_data' },
sent_at: '2020-03-18T19:45:02.620Z',
},
})
.expect(404);
Expand Down