@@ -104,11 +104,13 @@ describe('alertInstanceSummaryFromEventLog', () => {
104104 Object {
105105 "instances": Object {
106106 "instance-1": Object {
107+ "actionGroupId": undefined,
107108 "activeStartDate": undefined,
108109 "muted": true,
109110 "status": "OK",
110111 },
111112 "instance-2": Object {
113+ "actionGroupId": undefined,
112114 "activeStartDate": undefined,
113115 "muted": true,
114116 "status": "OK",
@@ -184,7 +186,7 @@ describe('alertInstanceSummaryFromEventLog', () => {
184186 const events = eventsFactory
185187 . addExecute ( )
186188 . addNewInstance ( 'instance-1' )
187- . addActiveInstance ( 'instance-1' )
189+ . addActiveInstance ( 'instance-1' , 'action group A' )
188190 . advanceTime ( 10000 )
189191 . addExecute ( )
190192 . addResolvedInstance ( 'instance-1' )
@@ -202,6 +204,7 @@ describe('alertInstanceSummaryFromEventLog', () => {
202204 Object {
203205 "instances": Object {
204206 "instance-1": Object {
207+ "actionGroupId": undefined,
205208 "activeStartDate": undefined,
206209 "muted": false,
207210 "status": "OK",
@@ -218,7 +221,7 @@ describe('alertInstanceSummaryFromEventLog', () => {
218221 const eventsFactory = new EventsFactory ( ) ;
219222 const events = eventsFactory
220223 . addExecute ( )
221- . addActiveInstance ( 'instance-1' )
224+ . addActiveInstance ( 'instance-1' , 'action group A' )
222225 . advanceTime ( 10000 )
223226 . addExecute ( )
224227 . addResolvedInstance ( 'instance-1' )
@@ -236,6 +239,7 @@ describe('alertInstanceSummaryFromEventLog', () => {
236239 Object {
237240 "instances": Object {
238241 "instance-1": Object {
242+ "actionGroupId": undefined,
239243 "activeStartDate": undefined,
240244 "muted": false,
241245 "status": "OK",
@@ -253,10 +257,10 @@ describe('alertInstanceSummaryFromEventLog', () => {
253257 const events = eventsFactory
254258 . addExecute ( )
255259 . addNewInstance ( 'instance-1' )
256- . addActiveInstance ( 'instance-1' )
260+ . addActiveInstance ( 'instance-1' , 'action group A' )
257261 . advanceTime ( 10000 )
258262 . addExecute ( )
259- . addActiveInstance ( 'instance-1' )
263+ . addActiveInstance ( 'instance-1' , 'action group A' )
260264 . getEvents ( ) ;
261265
262266 const summary : AlertInstanceSummary = alertInstanceSummaryFromEventLog ( {
@@ -271,6 +275,79 @@ describe('alertInstanceSummaryFromEventLog', () => {
271275 Object {
272276 "instances": Object {
273277 "instance-1": Object {
278+ "actionGroupId": "action group A",
279+ "activeStartDate": "2020-06-18T00:00:00.000Z",
280+ "muted": false,
281+ "status": "Active",
282+ },
283+ },
284+ "lastRun": "2020-06-18T00:00:10.000Z",
285+ "status": "Active",
286+ }
287+ ` ) ;
288+ } ) ;
289+
290+ test ( 'alert with currently active instance with no action group in event log' , async ( ) => {
291+ const alert = createAlert ( { } ) ;
292+ const eventsFactory = new EventsFactory ( ) ;
293+ const events = eventsFactory
294+ . addExecute ( )
295+ . addNewInstance ( 'instance-1' )
296+ . addActiveInstance ( 'instance-1' , undefined )
297+ . advanceTime ( 10000 )
298+ . addExecute ( )
299+ . addActiveInstance ( 'instance-1' , undefined )
300+ . getEvents ( ) ;
301+
302+ const summary : AlertInstanceSummary = alertInstanceSummaryFromEventLog ( {
303+ alert,
304+ events,
305+ dateStart,
306+ dateEnd,
307+ } ) ;
308+
309+ const { lastRun, status, instances } = summary ;
310+ expect ( { lastRun, status, instances } ) . toMatchInlineSnapshot ( `
311+ Object {
312+ "instances": Object {
313+ "instance-1": Object {
314+ "actionGroupId": undefined,
315+ "activeStartDate": "2020-06-18T00:00:00.000Z",
316+ "muted": false,
317+ "status": "Active",
318+ },
319+ },
320+ "lastRun": "2020-06-18T00:00:10.000Z",
321+ "status": "Active",
322+ }
323+ ` ) ;
324+ } ) ;
325+
326+ test ( 'alert with currently active instance that switched action groups' , async ( ) => {
327+ const alert = createAlert ( { } ) ;
328+ const eventsFactory = new EventsFactory ( ) ;
329+ const events = eventsFactory
330+ . addExecute ( )
331+ . addNewInstance ( 'instance-1' )
332+ . addActiveInstance ( 'instance-1' , 'action group A' )
333+ . advanceTime ( 10000 )
334+ . addExecute ( )
335+ . addActiveInstance ( 'instance-1' , 'action group B' )
336+ . getEvents ( ) ;
337+
338+ const summary : AlertInstanceSummary = alertInstanceSummaryFromEventLog ( {
339+ alert,
340+ events,
341+ dateStart,
342+ dateEnd,
343+ } ) ;
344+
345+ const { lastRun, status, instances } = summary ;
346+ expect ( { lastRun, status, instances } ) . toMatchInlineSnapshot ( `
347+ Object {
348+ "instances": Object {
349+ "instance-1": Object {
350+ "actionGroupId": "action group B",
274351 "activeStartDate": "2020-06-18T00:00:00.000Z",
275352 "muted": false,
276353 "status": "Active",
@@ -287,10 +364,10 @@ describe('alertInstanceSummaryFromEventLog', () => {
287364 const eventsFactory = new EventsFactory ( ) ;
288365 const events = eventsFactory
289366 . addExecute ( )
290- . addActiveInstance ( 'instance-1' )
367+ . addActiveInstance ( 'instance-1' , 'action group A' )
291368 . advanceTime ( 10000 )
292369 . addExecute ( )
293- . addActiveInstance ( 'instance-1' )
370+ . addActiveInstance ( 'instance-1' , 'action group A' )
294371 . getEvents ( ) ;
295372
296373 const summary : AlertInstanceSummary = alertInstanceSummaryFromEventLog ( {
@@ -305,6 +382,7 @@ describe('alertInstanceSummaryFromEventLog', () => {
305382 Object {
306383 "instances": Object {
307384 "instance-1": Object {
385+ "actionGroupId": "action group A",
308386 "activeStartDate": undefined,
309387 "muted": false,
310388 "status": "Active",
@@ -322,12 +400,12 @@ describe('alertInstanceSummaryFromEventLog', () => {
322400 const events = eventsFactory
323401 . addExecute ( )
324402 . addNewInstance ( 'instance-1' )
325- . addActiveInstance ( 'instance-1' )
403+ . addActiveInstance ( 'instance-1' , 'action group A' )
326404 . addNewInstance ( 'instance-2' )
327- . addActiveInstance ( 'instance-2' )
405+ . addActiveInstance ( 'instance-2' , 'action group B' )
328406 . advanceTime ( 10000 )
329407 . addExecute ( )
330- . addActiveInstance ( 'instance-1' )
408+ . addActiveInstance ( 'instance-1' , 'action group A' )
331409 . addResolvedInstance ( 'instance-2' )
332410 . getEvents ( ) ;
333411
@@ -343,11 +421,13 @@ describe('alertInstanceSummaryFromEventLog', () => {
343421 Object {
344422 "instances": Object {
345423 "instance-1": Object {
424+ "actionGroupId": "action group A",
346425 "activeStartDate": "2020-06-18T00:00:00.000Z",
347426 "muted": true,
348427 "status": "Active",
349428 },
350429 "instance-2": Object {
430+ "actionGroupId": undefined,
351431 "activeStartDate": undefined,
352432 "muted": true,
353433 "status": "OK",
@@ -365,19 +445,19 @@ describe('alertInstanceSummaryFromEventLog', () => {
365445 const events = eventsFactory
366446 . addExecute ( )
367447 . addNewInstance ( 'instance-1' )
368- . addActiveInstance ( 'instance-1' )
448+ . addActiveInstance ( 'instance-1' , 'action group A' )
369449 . addNewInstance ( 'instance-2' )
370- . addActiveInstance ( 'instance-2' )
450+ . addActiveInstance ( 'instance-2' , 'action group B' )
371451 . advanceTime ( 10000 )
372452 . addExecute ( )
373- . addActiveInstance ( 'instance-1' )
453+ . addActiveInstance ( 'instance-1' , 'action group A' )
374454 . addResolvedInstance ( 'instance-2' )
375455 . advanceTime ( 10000 )
376456 . addExecute ( )
377- . addActiveInstance ( 'instance-1' )
457+ . addActiveInstance ( 'instance-1' , 'action group B' )
378458 . advanceTime ( 10000 )
379459 . addExecute ( )
380- . addActiveInstance ( 'instance-1' )
460+ . addActiveInstance ( 'instance-1' , 'action group B' )
381461 . getEvents ( ) ;
382462
383463 const summary : AlertInstanceSummary = alertInstanceSummaryFromEventLog ( {
@@ -392,11 +472,13 @@ describe('alertInstanceSummaryFromEventLog', () => {
392472 Object {
393473 "instances": Object {
394474 "instance-1": Object {
475+ "actionGroupId": "action group B",
395476 "activeStartDate": "2020-06-18T00:00:00.000Z",
396477 "muted": false,
397478 "status": "Active",
398479 },
399480 "instance-2": Object {
481+ "actionGroupId": undefined,
400482 "activeStartDate": undefined,
401483 "muted": false,
402484 "status": "OK",
@@ -452,14 +534,17 @@ export class EventsFactory {
452534 return this ;
453535 }
454536
455- addActiveInstance ( instanceId : string ) : EventsFactory {
537+ addActiveInstance ( instanceId : string , actionGroupId : string | undefined ) : EventsFactory {
538+ const kibanaAlerting = actionGroupId
539+ ? { instance_id : instanceId , action_group_id : actionGroupId }
540+ : { instance_id : instanceId } ;
456541 this . events . push ( {
457542 '@timestamp' : this . date ,
458543 event : {
459544 provider : EVENT_LOG_PROVIDER ,
460545 action : EVENT_LOG_ACTIONS . activeInstance ,
461546 } ,
462- kibana : { alerting : { instance_id : instanceId } } ,
547+ kibana : { alerting : kibanaAlerting } ,
463548 } ) ;
464549 return this ;
465550 }
0 commit comments