forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.ts
423 lines (393 loc) · 9.35 KB
/
agent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type {
AGENT_TYPE_EPHEMERAL,
AGENT_TYPE_PERMANENT,
AGENT_TYPE_TEMPORARY,
FleetServerAgentComponentStatuses,
} from '../../constants';
export type AgentType =
| typeof AGENT_TYPE_EPHEMERAL
| typeof AGENT_TYPE_PERMANENT
| typeof AGENT_TYPE_TEMPORARY;
export type AgentStatus =
| 'offline'
| 'error'
| 'online'
| 'inactive'
| 'enrolling'
| 'unenrolling'
| 'unenrolled'
| 'updating'
| 'degraded';
export type SimplifiedAgentStatus =
| 'healthy'
| 'unhealthy'
| 'updating'
| 'offline'
| 'inactive'
| 'unenrolled';
export type AgentActionType =
| 'UNENROLL'
| 'UPGRADE'
| 'SETTINGS'
| 'POLICY_REASSIGN'
| 'CANCEL'
| 'FORCE_UNENROLL'
| 'UPDATE_TAGS'
| 'REQUEST_DIAGNOSTICS'
| 'POLICY_CHANGE'
| 'INPUT_ACTION';
type FleetServerAgentComponentStatusTuple = typeof FleetServerAgentComponentStatuses;
export type FleetServerAgentComponentStatus = FleetServerAgentComponentStatusTuple[number];
export interface NewAgentAction {
type: AgentActionType;
data?: any;
ack_data?: any;
sent_at?: string;
agents: string[];
created_at?: string;
id?: string;
expiration?: string;
start_time?: string;
minimum_execution_duration?: number;
rollout_duration_seconds?: number;
source_uri?: string;
total?: number;
}
export interface AgentAction extends NewAgentAction {
type: AgentActionType;
data?: any;
sent_at?: string;
id: string;
created_at: string;
ack_data?: any;
}
export interface AgentMetadata {
[x: string]: any;
}
// SO definition for this type is declared in server/types/interfaces
interface AgentBase {
type: AgentType;
active: boolean;
enrolled_at: string;
unenrolled_at?: string;
unenrollment_started_at?: string;
upgraded_at?: string | null;
upgrade_started_at?: string | null;
access_api_key_id?: string;
default_api_key?: string;
default_api_key_id?: string;
policy_id?: string;
policy_revision?: number | null;
last_checkin?: string;
last_checkin_status?: 'error' | 'online' | 'degraded' | 'updating';
last_checkin_message?: string;
user_provided_metadata: AgentMetadata;
local_metadata: AgentMetadata;
tags?: string[];
components?: FleetServerAgentComponent[];
agent?: FleetServerAgentMetadata;
}
export interface AgentMetrics {
cpu_avg?: number;
memory_size_byte_avg?: number;
}
export interface OutputMap {
[key: string]: {
api_key_id: string;
type: string;
to_retire_api_key_ids?: FleetServerAgent['default_api_key_history'];
};
}
export interface Agent extends AgentBase {
id: string;
access_api_key?: string;
// @deprecated
default_api_key_history?: FleetServerAgent['default_api_key_history'];
outputs?: OutputMap;
status?: AgentStatus;
packages: string[];
sort?: Array<number | string | null>;
metrics?: AgentMetrics;
}
export interface CurrentUpgrade {
actionId: string;
complete: boolean;
nbAgents: number;
nbAgentsAck: number;
version: string;
startTime?: string;
}
export interface ActionErrorResult {
agentId: string;
error: string;
timestamp: string;
hostname?: string;
}
export interface ActionStatus {
actionId: string;
// how many agents are successfully included in action documents
nbAgentsActionCreated: number;
// how many agents acknowledged the action sucessfully (completed)
nbAgentsAck: number;
// how many agents failed
nbAgentsFailed: number;
version?: string;
startTime?: string;
type: AgentActionType;
// how many agents were actioned by the user
nbAgentsActioned: number;
status: 'COMPLETE' | 'EXPIRED' | 'CANCELLED' | 'FAILED' | 'IN_PROGRESS' | 'ROLLOUT_PASSED';
expiration?: string;
completionTime?: string;
cancellationTime?: string;
newPolicyId?: string;
creationTime: string;
hasRolloutPeriod?: boolean;
latestErrors?: ActionErrorResult[];
revision?: number;
policyId?: string;
}
export interface AgentDiagnostics {
id: string;
name: string;
createTime: string;
filePath: string;
status: 'READY' | 'AWAITING_UPLOAD' | 'DELETED' | 'IN_PROGRESS' | 'FAILED';
actionId: string;
error?: string;
}
// Generated from FleetServer schema.json
/**
* Fleet Server agent component unit
*/
export interface FleetServerAgentComponentUnit {
id: string;
type: 'input' | 'output';
status: FleetServerAgentComponentStatus;
message: string;
payload?: {
[key: string]: any;
};
}
/**
* Fleet server agent component
*/
export interface FleetServerAgentComponent {
id: string;
type: string;
status: FleetServerAgentComponentStatus;
message: string;
// In some case units could be missing
units?: FleetServerAgentComponentUnit[];
}
/**
* An Elastic Agent that has enrolled into Fleet
*/
export interface FleetServerAgent {
/**
* The version of the document in the index
*/
_version?: number;
/**
* Shared ID
*/
shared_id?: string;
/**
* Type
*/
type: AgentType;
/**
* Active flag
*/
active: boolean;
/**
* Date/time the Elastic Agent enrolled
*/
enrolled_at: string;
/**
* Date/time the Elastic Agent unenrolled
*/
unenrolled_at?: string;
/**
* Date/time the Elastic Agent unenrolled started
*/
unenrollment_started_at?: string;
/**
* Date/time the Elastic Agent was last upgraded
*/
upgraded_at?: string | null;
/**
* Date/time the Elastic Agent started the current upgrade
*/
upgrade_started_at?: string | null;
/**
* ID of the API key the Elastic Agent must used to contact Fleet Server
*/
access_api_key_id?: string;
agent?: FleetServerAgentMetadata;
/**
* User provided metadata information for the Elastic Agent
*/
user_provided_metadata: AgentMetadata;
/**
* Local metadata information for the Elastic Agent
*/
local_metadata: AgentMetadata;
/**
* The policy ID for the Elastic Agent
*/
policy_id?: string;
/**
* The current policy revision_idx for the Elastic Agent
*/
policy_revision_idx?: number | null;
/**
* The current policy coordinator for the Elastic Agent
*/
policy_coordinator_idx?: number;
/**
* Date/time the Elastic Agent was last updated
*/
last_updated?: string;
/**
* Date/time the Elastic Agent checked in last time
*/
last_checkin?: string;
/**
* Last checkin status
*/
last_checkin_status?: 'error' | 'online' | 'degraded' | 'updating';
/**
* Last checkin message
*/
last_checkin_message?: string;
/**
* ID of the API key the Elastic Agent uses to authenticate with elasticsearch
*/
default_api_key_id?: string;
/**
* API key the Elastic Agent uses to authenticate with elasticsearch
*/
default_api_key?: string;
/**
* Date/time the Elastic Agent was last updated
*/
updated_at?: string;
/**
* Packages array
*/
packages?: string[];
/**
* The last acknowledged action sequence number for the Elastic Agent
*/
action_seq_no?: number;
/**
* A list of tags used for organizing/filtering agents
*/
tags?: string[];
/**
* Default API Key History
*/
default_api_key_history?: Array<{
id: string;
retired_at: string;
}>;
/**
* Components array
*/
components?: FleetServerAgentComponent[];
/**
* Outputs map
*/
outputs?: OutputMap;
}
/**
* An Elastic Agent metadata
*/
export interface FleetServerAgentMetadata {
/**
* The unique identifier for the Elastic Agent
*/
id: string;
/**
* The version of the Elastic Agent
*/
version: string;
[k: string]: any;
}
/**
* An Elastic Agent action
*/
export interface FleetServerAgentAction {
/**
* The unique identifier for action document
*/
_id?: string;
/**
* The action sequence number
*/
_seq_no?: number;
/**
* The unique identifier for the Elastic Agent action. There could be multiple documents with the same action_id if the action is split into two separate documents.
*/
action_id?: string;
/**
* Date/time the action was created
*/
'@timestamp'?: string;
/**
* The action expiration date/time
*/
expiration?: string;
/**
* The action type. APP_ACTION is the value for the actions that suppose to be routed to the endpoints/beats.
*/
type?: string;
/**
* The input identifier the actions should be routed to.
*/
input_id?: string;
/**
* The Agent IDs the action is intended for. No support for json.RawMessage with the current generator. Could be useful to lazy parse the agent ids
*/
agents?: string[];
/**
* Date when the agent should execute that agent. This field could be altered by Fleet server for progressive rollout of the action.
*/
start_time?: string;
/**
* @deprecated
* Minimun execution duration in seconds, used for progressive rollout of the action.
*/
minimum_execution_duration?: number;
/**
* Rollout duration in seconds, used for progressive rollout of the action.
*/
rollout_duration_seconds?: number;
/**
* The opaque payload.
*/
data?: {
[k: string]: unknown;
};
total?: number;
/** Trace id */
traceparent?: string | null;
// signed data + signature
signed?: {
data: string;
signature: string;
};
[k: string]: unknown;
}
export interface ActionStatusOptions {
errorSize: number;
page?: number;
perPage?: number;
}