Skip to content

Commit ed387dd

Browse files
authored
add policy details and update SO limit requests (#71789)
1 parent 5f6389a commit ed387dd

File tree

6 files changed

+252
-53
lines changed

6 files changed

+252
-53
lines changed

x-pack/plugins/security_solution/server/usage/collector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export const registerCollector: RegisterCollector = ({
6666
},
6767
policies: {
6868
malware: {
69-
success: { type: 'long' },
70-
warning: { type: 'long' },
69+
active: { type: 'long' },
70+
inactive: { type: 'long' },
7171
failure: { type: 'long' },
7272
},
7373
},

x-pack/plugins/security_solution/server/usage/endpoints/endpoint.mocks.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,108 @@ export const mockFleetObjectsResponse = (
7676
],
7777
});
7878

79+
const mockPolicyPayload = (malwareStatus: 'success' | 'warning' | 'failure') =>
80+
JSON.stringify({
81+
'endpoint-security': {
82+
Endpoint: {
83+
configuration: {
84+
inputs: [
85+
{
86+
id: '0d466df0-c60f-11ea-a5c5-151665e785c4',
87+
policy: {
88+
linux: {
89+
events: {
90+
file: true,
91+
network: true,
92+
process: true,
93+
},
94+
logging: {
95+
file: 'info',
96+
},
97+
},
98+
mac: {
99+
events: {
100+
file: true,
101+
network: true,
102+
process: true,
103+
},
104+
logging: {
105+
file: 'info',
106+
},
107+
malware: {
108+
mode: 'prevent',
109+
},
110+
},
111+
windows: {
112+
events: {
113+
dll_and_driver_load: true,
114+
dns: true,
115+
file: true,
116+
network: true,
117+
process: true,
118+
registry: true,
119+
security: true,
120+
},
121+
logging: {
122+
file: 'info',
123+
},
124+
malware: {
125+
mode: 'prevent',
126+
},
127+
},
128+
},
129+
},
130+
],
131+
},
132+
policy: {
133+
applied: {
134+
id: '0d466df0-c60f-11ea-a5c5-151665e785c4',
135+
response: {
136+
configurations: {
137+
malware: {
138+
concerned_actions: [
139+
'load_config',
140+
'workflow',
141+
'download_global_artifacts',
142+
'download_user_artifacts',
143+
'configure_malware',
144+
'read_malware_config',
145+
'load_malware_model',
146+
'read_kernel_config',
147+
'configure_kernel',
148+
'detect_process_events',
149+
'detect_file_write_events',
150+
'connect_kernel',
151+
'detect_file_open_events',
152+
'detect_sync_image_load_events',
153+
],
154+
status: `${malwareStatus}`,
155+
},
156+
},
157+
},
158+
status: `${malwareStatus}`,
159+
},
160+
},
161+
},
162+
agent: {
163+
id: 'testAgentId',
164+
version: '8.0.0-SNAPSHOT',
165+
},
166+
host: {
167+
architecture: 'x86_64',
168+
id: 'a4148b63-1758-ab1f-a6d3-f95075cb1a9c',
169+
os: {
170+
Ext: {
171+
variant: 'Windows 10 Pro',
172+
},
173+
full: 'Windows 10 Pro 2004 (10.0.19041.329)',
174+
name: 'Windows',
175+
version: '2004 (10.0.19041.329)',
176+
},
177+
},
178+
},
179+
});
180+
79181
/**
80182
*
81183
* @param running - allows us to set whether the mocked endpoint is in an active or disabled/failed state
@@ -102,6 +204,7 @@ export const mockFleetEventsObjectsResponse = (
102204
message: `Application: endpoint-security--8.0.0[d8f7f6e8-9375-483c-b456-b479f1d7a4f2]: State changed to ${
103205
running ? 'RUNNING' : 'FAILED'
104206
}: `,
207+
payload: mockPolicyPayload(running ? 'success' : 'failure'),
105208
config_id: testConfigId,
106209
},
107210
references: [],

x-pack/plugins/security_solution/server/usage/endpoints/endpoint.test.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import * as fleetSavedObjects from './fleet_saved_objects';
2020
describe('test security solution endpoint telemetry', () => {
2121
let mockSavedObjectsRepository: jest.Mocked<ISavedObjectsRepository>;
2222
let getFleetSavedObjectsMetadataSpy: jest.SpyInstance<Promise<SavedObjectsFindResponse<Agent>>>;
23-
let getFleetEventsSavedObjectsSpy: jest.SpyInstance<Promise<
23+
let getLatestFleetEndpointEventSpy: jest.SpyInstance<Promise<
2424
SavedObjectsFindResponse<AgentEventSOAttributes>
2525
>>;
2626

2727
beforeAll(() => {
28-
getFleetEventsSavedObjectsSpy = jest.spyOn(fleetSavedObjects, 'getFleetEventsSavedObjects');
28+
getLatestFleetEndpointEventSpy = jest.spyOn(fleetSavedObjects, 'getLatestFleetEndpointEvent');
2929
getFleetSavedObjectsMetadataSpy = jest.spyOn(fleetSavedObjects, 'getFleetSavedObjectsMetadata');
3030
mockSavedObjectsRepository = savedObjectsRepositoryMock.create();
3131
});
@@ -39,6 +39,13 @@ describe('test security solution endpoint telemetry', () => {
3939
Object {
4040
"active_within_last_24_hours": 0,
4141
"os": Array [],
42+
"policies": Object {
43+
"malware": Object {
44+
"active": 0,
45+
"failure": 0,
46+
"inactive": 0,
47+
},
48+
},
4249
"total_installed": 0,
4350
}
4451
`);
@@ -58,6 +65,13 @@ describe('test security solution endpoint telemetry', () => {
5865
total_installed: 0,
5966
active_within_last_24_hours: 0,
6067
os: [],
68+
policies: {
69+
malware: {
70+
failure: 0,
71+
active: 0,
72+
inactive: 0,
73+
},
74+
},
6175
});
6276
});
6377
});
@@ -67,7 +81,7 @@ describe('test security solution endpoint telemetry', () => {
6781
getFleetSavedObjectsMetadataSpy.mockImplementation(() =>
6882
Promise.resolve(mockFleetObjectsResponse())
6983
);
70-
getFleetEventsSavedObjectsSpy.mockImplementation(() =>
84+
getLatestFleetEndpointEventSpy.mockImplementation(() =>
7185
Promise.resolve(mockFleetEventsObjectsResponse())
7286
);
7387

@@ -85,14 +99,21 @@ describe('test security solution endpoint telemetry', () => {
8599
count: 1,
86100
},
87101
],
102+
policies: {
103+
malware: {
104+
failure: 1,
105+
active: 0,
106+
inactive: 0,
107+
},
108+
},
88109
});
89110
});
90111

91112
it('should show one endpoint installed and it is active', async () => {
92113
getFleetSavedObjectsMetadataSpy.mockImplementation(() =>
93114
Promise.resolve(mockFleetObjectsResponse())
94115
);
95-
getFleetEventsSavedObjectsSpy.mockImplementation(() =>
116+
getLatestFleetEndpointEventSpy.mockImplementation(() =>
96117
Promise.resolve(mockFleetEventsObjectsResponse(true))
97118
);
98119

@@ -110,6 +131,13 @@ describe('test security solution endpoint telemetry', () => {
110131
count: 1,
111132
},
112133
],
134+
policies: {
135+
malware: {
136+
failure: 0,
137+
active: 1,
138+
inactive: 0,
139+
},
140+
},
113141
});
114142
});
115143
});

x-pack/plugins/security_solution/server/usage/endpoints/fleet_saved_objects.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ export const getFleetSavedObjectsMetadata = async (savedObjectsClient: ISavedObj
1919
type: AGENT_SAVED_OBJECT_TYPE,
2020
fields: ['packages', 'last_checkin', 'local_metadata'],
2121
filter: `${AGENT_SAVED_OBJECT_TYPE}.attributes.packages: ${FLEET_ENDPOINT_PACKAGE_CONSTANT}`,
22+
perPage: 10000,
2223
sortField: 'enrolled_at',
2324
sortOrder: 'desc',
2425
});
2526

26-
export const getFleetEventsSavedObjects = async (
27+
export const getLatestFleetEndpointEvent = async (
2728
savedObjectsClient: ISavedObjectsRepository,
2829
agentId: string
2930
) =>
3031
savedObjectsClient.find<AgentEventSOAttributes>({
3132
type: AGENT_EVENT_SAVED_OBJECT_TYPE,
3233
filter: `${AGENT_EVENT_SAVED_OBJECT_TYPE}.attributes.agent_id: ${agentId} and ${AGENT_EVENT_SAVED_OBJECT_TYPE}.attributes.message: "${FLEET_ENDPOINT_PACKAGE_CONSTANT}"`,
34+
perPage: 1, // Get the most recent endpoint event.
3335
sortField: 'timestamp',
3436
sortOrder: 'desc',
3537
search: agentId,

0 commit comments

Comments
 (0)