diff --git a/internal/listener/listener.go b/internal/listener/listener.go index 80a1e63c0..468567d11 100644 --- a/internal/listener/listener.go +++ b/internal/listener/listener.go @@ -398,6 +398,8 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) { contactChannels := make(map[*recipient.Contact]map[string]struct{}) escalationRecipients := make(map[recipient.Key]bool) + groupsOrSchedules := make(map[*recipient.Contact]recipient.Recipient) + for escalationID, state := range currentIncident.EscalationState { escalation := l.runtimeConfig.GetRuleEscalation(escalationID) if state.TriggeredAt.Time().IsZero() { @@ -446,7 +448,13 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) { escalationRecipients[escalationRecipient.Key] = true if !managed || state.Role > incident.RoleRecipient { - for _, c := range escalationRecipient.Recipient.GetContactsAt(ev.Time) { + r := escalationRecipient.Recipient + _, isContact := r.(*recipient.Contact) + for _, c := range r.GetContactsAt(ev.Time) { + if !isContact { + groupsOrSchedules[c] = r + } + if contactChannels[c] == nil { contactChannels[c] = make(map[string]struct{}) } @@ -468,7 +476,12 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) { isEscalationRecipient := escalationRecipients[recipientKey] if !isEscalationRecipient && (!managed || state.Role > incident.RoleRecipient) { + _, isContact := r.(*recipient.Contact) for _, contact := range r.GetContactsAt(ev.Time) { + if !isContact { + groupsOrSchedules[contact] = r + } + if contactChannels[contact] == nil { contactChannels[contact] = make(map[string]struct{}) } @@ -478,15 +491,23 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) { } for contact, channels := range contactChannels { + rk := recipient.ToKey(contact) + hr := &incident.HistoryRow{ + EventID: utils.ToDBInt(ev.ID), + Time: types.UnixMilli(ev.Time), + Type: incident.Notified, + CausedByIncidentHistoryID: causedByIncidentHistoryId, + } + + groupOrSchedule := groupsOrSchedules[contact] + if groupsOrSchedules != nil { + rk = rk.CopyNonNil(recipient.ToKey(groupOrSchedule)) + } + + hr.Key = rk + for chType := range channels { - hr := &incident.HistoryRow{ - Key: recipient.ToKey(contact), - EventID: utils.ToDBInt(ev.ID), - Time: types.UnixMilli(ev.Time), - Type: incident.Notified, - ChannelType: utils.ToDBString(chType), - CausedByIncidentHistoryID: causedByIncidentHistoryId, - } + hr.ChannelType = utils.ToDBString(chType) l.logger.Infof("[%s %s] notify %q via %q", obj.DisplayName(), currentIncident.String(), contact.FullName, chType)