@@ -398,6 +398,8 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
398398 contactChannels := make (map [* recipient.Contact ]map [string ]struct {})
399399
400400 escalationRecipients := make (map [recipient.Key ]bool )
401+ groupsOrSchedules := make (map [* recipient.Contact ]recipient.Recipient )
402+
401403 for escalationID , state := range currentIncident .EscalationState {
402404 escalation := l .runtimeConfig .GetRuleEscalation (escalationID )
403405 if state .TriggeredAt .Time ().IsZero () {
@@ -446,7 +448,13 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
446448 escalationRecipients [escalationRecipient .Key ] = true
447449
448450 if ! managed || state .Role > incident .RoleRecipient {
449- for _ , c := range escalationRecipient .Recipient .GetContactsAt (ev .Time ) {
451+ r := escalationRecipient .Recipient
452+ _ , isContact := r .(* recipient.Contact )
453+ for _ , c := range r .GetContactsAt (ev .Time ) {
454+ if ! isContact {
455+ groupsOrSchedules [c ] = r
456+ }
457+
450458 if contactChannels [c ] == nil {
451459 contactChannels [c ] = make (map [string ]struct {})
452460 }
@@ -468,7 +476,12 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
468476
469477 isEscalationRecipient := escalationRecipients [recipientKey ]
470478 if ! isEscalationRecipient && (! managed || state .Role > incident .RoleRecipient ) {
479+ _ , isContact := r .(* recipient.Contact )
471480 for _ , contact := range r .GetContactsAt (ev .Time ) {
481+ if ! isContact {
482+ groupsOrSchedules [contact ] = r
483+ }
484+
472485 if contactChannels [contact ] == nil {
473486 contactChannels [contact ] = make (map [string ]struct {})
474487 }
@@ -478,15 +491,23 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
478491 }
479492
480493 for contact , channels := range contactChannels {
494+ rk := recipient .ToKey (contact )
495+ hr := & incident.HistoryRow {
496+ EventID : utils .ToDBInt (ev .ID ),
497+ Time : types .UnixMilli (ev .Time ),
498+ Type : incident .Notified ,
499+ CausedByIncidentHistoryID : causedByIncidentHistoryId ,
500+ }
501+
502+ groupOrSchedule := groupsOrSchedules [contact ]
503+ if groupsOrSchedules != nil {
504+ rk = rk .CopyNonNil (recipient .ToKey (groupOrSchedule ))
505+ }
506+
507+ hr .Key = rk
508+
481509 for chType := range channels {
482- hr := & incident.HistoryRow {
483- Key : recipient .ToKey (contact ),
484- EventID : utils .ToDBInt (ev .ID ),
485- Time : types .UnixMilli (ev .Time ),
486- Type : incident .Notified ,
487- ChannelType : utils .ToDBString (chType ),
488- CausedByIncidentHistoryID : causedByIncidentHistoryId ,
489- }
510+ hr .ChannelType = utils .ToDBString (chType )
490511
491512 l .logger .Infof ("[%s %s] notify %q via %q" , obj .DisplayName (), currentIncident .String (), contact .FullName , chType )
492513
0 commit comments