Skip to content

Commit

Permalink
Write also schedule/contactgroup_id for contact notified histories
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed May 10, 2023
1 parent cab6d2a commit c55d0aa
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions internal/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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{})
}
Expand All @@ -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{})
}
Expand All @@ -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)

Expand Down

0 comments on commit c55d0aa

Please sign in to comment.