Skip to content

Commit c1a263c

Browse files
authored
[Fleet] Allow to send SETTINGS action (#83707)
1 parent a2598ea commit c1a263c

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

x-pack/plugins/fleet/common/types/models/agent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type AgentActionType =
2626
| 'POLICY_CHANGE'
2727
| 'UNENROLL'
2828
| 'UPGRADE'
29+
| 'SETTINGS'
2930
// INTERNAL* actions are mean to interupt long polling calls these actions will not be distributed to the agent
3031
| 'INTERNAL_POLICY_REASSIGN';
3132

x-pack/plugins/fleet/server/routes/agent/actions_handlers.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ describe('test actions handlers schema', () => {
2525
NewAgentActionSchema.validate({
2626
type: 'POLICY_CHANGE',
2727
data: 'data',
28-
sent_at: '2020-03-14T19:45:02.620Z',
2928
})
3029
).toBeTruthy();
3130
});
@@ -34,7 +33,6 @@ describe('test actions handlers schema', () => {
3433
expect(() => {
3534
NewAgentActionSchema.validate({
3635
data: 'data',
37-
sent_at: '2020-03-14T19:45:02.620Z',
3836
});
3937
}).toThrowError();
4038
});
@@ -55,7 +53,6 @@ describe('test actions handlers', () => {
5553
action: {
5654
type: 'POLICY_CHANGE',
5755
data: 'data',
58-
sent_at: '2020-03-14T19:45:02.620Z',
5956
},
6057
},
6158
params: {

x-pack/plugins/fleet/server/types/models/agent.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,26 @@ export const AgentEventSchema = schema.object({
6262
id: schema.string(),
6363
});
6464

65-
export const NewAgentActionSchema = schema.object({
66-
type: schema.oneOf([
67-
schema.literal('POLICY_CHANGE'),
68-
schema.literal('UNENROLL'),
69-
schema.literal('UPGRADE'),
70-
schema.literal('INTERNAL_POLICY_REASSIGN'),
71-
]),
72-
data: schema.maybe(schema.any()),
73-
ack_data: schema.maybe(schema.any()),
74-
sent_at: schema.maybe(schema.string()),
75-
});
65+
export const NewAgentActionSchema = schema.oneOf([
66+
schema.object({
67+
type: schema.oneOf([
68+
schema.literal('POLICY_CHANGE'),
69+
schema.literal('UNENROLL'),
70+
schema.literal('UPGRADE'),
71+
schema.literal('INTERNAL_POLICY_REASSIGN'),
72+
]),
73+
data: schema.maybe(schema.any()),
74+
ack_data: schema.maybe(schema.any()),
75+
}),
76+
schema.object({
77+
type: schema.oneOf([schema.literal('SETTINGS')]),
78+
data: schema.object({
79+
log_level: schema.oneOf([
80+
schema.literal('debug'),
81+
schema.literal('info'),
82+
schema.literal('warning'),
83+
schema.literal('error'),
84+
]),
85+
}),
86+
}),
87+
]);

x-pack/test/fleet_api_integration/apis/agents/actions.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,51 @@ export default function (providerContext: FtrProviderContext) {
3636
expect(apiResponse.item.data).to.eql({ data: 'action_data' });
3737
});
3838

39+
it('should return a 200 if this a valid SETTINGS action request', async () => {
40+
const { body: apiResponse } = await supertest
41+
.post(`/api/fleet/agents/agent1/actions`)
42+
.set('kbn-xsrf', 'xx')
43+
.send({
44+
action: {
45+
type: 'SETTINGS',
46+
data: { log_level: 'debug' },
47+
},
48+
})
49+
.expect(200);
50+
51+
expect(apiResponse.item.type).to.eql('SETTINGS');
52+
expect(apiResponse.item.data).to.eql({ log_level: 'debug' });
53+
});
54+
55+
it('should return a 400 if this a invalid SETTINGS action request', async () => {
56+
const { body: apiResponse } = await supertest
57+
.post(`/api/fleet/agents/agent1/actions`)
58+
.set('kbn-xsrf', 'xx')
59+
.send({
60+
action: {
61+
type: 'SETTINGS',
62+
data: { log_level: 'thisnotavalidloglevel' },
63+
},
64+
})
65+
.expect(400);
66+
67+
expect(apiResponse.message).to.match(
68+
/\[request body.action\.[0-9]*\.data\.log_level]: types that failed validation/
69+
);
70+
});
71+
3972
it('should return a 400 when request does not have type information', async () => {
4073
const { body: apiResponse } = await supertest
4174
.post(`/api/fleet/agents/agent1/actions`)
4275
.set('kbn-xsrf', 'xx')
4376
.send({
4477
action: {
4578
data: { data: 'action_data' },
46-
sent_at: '2020-03-18T19:45:02.620Z',
4779
},
4880
})
4981
.expect(400);
50-
expect(apiResponse.message).to.eql(
51-
'[request body.action.type]: expected at least one defined value but got [undefined]'
82+
expect(apiResponse.message).to.match(
83+
/\[request body.action\.[0-9]*\.type]: expected at least one defined value but got \[undefined]/
5284
);
5385
});
5486

@@ -60,7 +92,6 @@ export default function (providerContext: FtrProviderContext) {
6092
action: {
6193
type: 'POLICY_CHANGE',
6294
data: { data: 'action_data' },
63-
sent_at: '2020-03-18T19:45:02.620Z',
6495
},
6596
})
6697
.expect(404);

0 commit comments

Comments
 (0)