@@ -399,6 +399,9 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
399
399
contactChannels := make (map [* recipient.Contact ]map [string ]struct {})
400
400
401
401
escalationRecipients := make (map [recipient.Key ]bool )
402
+ groupsOrSchedules := make (map [* recipient.Contact ]recipient.Key )
403
+ groupsOrSchedulesWithoutMembers := make (map [recipient.Recipient ]bool )
404
+
402
405
for escalationID , state := range currentIncident .EscalationState {
403
406
escalation := l .runtimeConfig .GetRuleEscalation (escalationID )
404
407
if state .TriggeredAt .Time ().IsZero () {
@@ -447,7 +450,14 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
447
450
escalationRecipients [escalationRecipient .Key ] = true
448
451
449
452
if ! managed || state .Role > incident .RoleRecipient {
450
- for _ , c := range escalationRecipient .Recipient .GetContactsAt (ev .Time ) {
453
+ r := escalationRecipient .Recipient
454
+ _ , isContact := r .(* recipient.Contact )
455
+ contacts := r .GetContactsAt (ev .Time )
456
+ for _ , c := range contacts {
457
+ if ! isContact {
458
+ groupsOrSchedules [c ] = recipient .ToKey (r )
459
+ }
460
+
451
461
if contactChannels [c ] == nil {
452
462
contactChannels [c ] = make (map [string ]struct {})
453
463
}
@@ -457,6 +467,10 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
457
467
contactChannels [c ][c.DefaultChannel ] = struct {}{}
458
468
}
459
469
}
470
+
471
+ if ! isContact && len (contacts ) == 0 {
472
+ groupsOrSchedulesWithoutMembers [r ] = true
473
+ }
460
474
}
461
475
}
462
476
}
@@ -469,25 +483,43 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
469
483
470
484
isEscalationRecipient := escalationRecipients [recipientKey ]
471
485
if ! isEscalationRecipient && (! managed || state .Role > incident .RoleRecipient ) {
472
- for _ , contact := range r .GetContactsAt (ev .Time ) {
486
+ _ , isContact := r .(* recipient.Contact )
487
+ contacts := r .GetContactsAt (ev .Time )
488
+ for _ , contact := range contacts {
489
+ if ! isContact {
490
+ groupsOrSchedules [contact ] = recipient .ToKey (r )
491
+ }
492
+
473
493
if contactChannels [contact ] == nil {
474
494
contactChannels [contact ] = make (map [string ]struct {})
475
495
}
476
496
contactChannels [contact ][contact.DefaultChannel ] = struct {}{}
477
497
}
498
+
499
+ if ! isContact && len (contacts ) == 0 {
500
+ groupsOrSchedulesWithoutMembers [r ] = true
501
+ }
478
502
}
479
503
}
480
504
481
505
for contact , channels := range contactChannels {
506
+ rk := recipient .ToKey (contact )
507
+ hr := & incident.HistoryRow {
508
+ EventID : utils .ToDBInt (ev .ID ),
509
+ Time : types .UnixMilli (ev .Time ),
510
+ Type : incident .Notified ,
511
+ CausedByIncidentHistoryID : causedByIncidentHistoryId ,
512
+ }
513
+
514
+ groupOrSchedule := groupsOrSchedules [contact ]
515
+ if groupsOrSchedules != nil {
516
+ rk = rk .CopyNonNil (groupOrSchedule )
517
+ }
518
+
519
+ hr .Key = rk
520
+
482
521
for chType := range channels {
483
- hr := & incident.HistoryRow {
484
- Key : recipient .ToKey (contact ),
485
- EventID : utils .ToDBInt (ev .ID ),
486
- Time : types .UnixMilli (time .Now ()),
487
- Type : incident .Notified ,
488
- ChannelType : utils .ToDBString (chType ),
489
- CausedByIncidentHistoryID : causedByIncidentHistoryId ,
490
- }
522
+ hr .ChannelType = utils .ToDBString (chType )
491
523
492
524
l .logger .Infof ("[%s %s] notify %q via %q" , obj .DisplayName (), currentIncident .String (), contact .FullName , chType )
493
525
@@ -516,6 +548,21 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
516
548
}
517
549
}
518
550
551
+ for gs , _ := range groupsOrSchedulesWithoutMembers {
552
+ hr := & incident.HistoryRow {
553
+ Key : recipient .ToKey (gs ),
554
+ EventID : utils .ToDBInt (ev .ID ),
555
+ Time : types .UnixMilli (ev .Time ),
556
+ Type : incident .Notified ,
557
+ CausedByIncidentHistoryID : causedByIncidentHistoryId ,
558
+ }
559
+
560
+ _ , err = currentIncident .AddHistory (hr , false )
561
+ if err != nil {
562
+ l .logger .Errorln (err )
563
+ }
564
+ }
565
+
519
566
_ , _ = fmt .Fprintln (w )
520
567
}
521
568
0 commit comments