diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 4380a913..96188edf 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -40,6 +40,7 @@ const ( AlertSummaryCN = "summaryCn" ReceiverName = "receiver" + ReceiverType = "receiver-type" Verify = "verify" Notification = "notification" diff --git a/pkg/history/history.go b/pkg/history/history.go index 8c776817..22f7b3a4 100644 --- a/pkg/history/history.go +++ b/pkg/history/history.go @@ -41,11 +41,13 @@ func (s *historyStage) Exec(ctx context.Context, l log.Logger, data interface{}) _ = level.Debug(l).Log("msg", "Start history stage", "seq", ctx.Value("seq")) - input := data.(map[string]*template.Alert) + input := data.(map[string][]*template.Alert) d := &template.Data{} for _, alert := range input { - if alert.NotifySuccessful { - d.Alerts = append(d.Alerts, alert) + for _, t := range alert { + if t.NotifySuccessful { + d.Alerts = append(d.Alerts, t) + } } } diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index 13411db4..d211017b 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -75,11 +75,14 @@ func (s *notifyStage) Exec(ctx context.Context, l log.Logger, data interface{}) _ = level.Debug(l).Log("msg", "Start notify stage", "seq", ctx.Value("seq")) input := data.(map[internal.Receiver][]*template.Data) - alertMap := make(map[string]*template.Alert) - for _, dataList := range input { - for _, d := range dataList { + alertMap := make(map[string][]*template.Alert) + for r, dataList := range input { + receiver := r + ds := convertor.DeepClone(dataList) + s.addExtensionLabels(receiver, ds) + for _, d := range ds { for _, alert := range d.Alerts { - alertMap[alert.ID] = alert + alertMap[alert.ID] = append(alertMap[alert.ID], alert) } } } @@ -91,7 +94,9 @@ func (s *notifyStage) Exec(ctx context.Context, l log.Logger, data interface{}) for _, alert := range alerts { if a := alertMap[alert.ID]; a != nil { - a.NotifySuccessful = true + for _, t := range a { + t.NotifySuccessful = true + } } } } @@ -125,7 +130,12 @@ func (s *notifyStage) Exec(ctx context.Context, l log.Logger, data interface{}) func (s *notifyStage) addExtensionLabels(receiver internal.Receiver, data []*template.Data) { for _, d := range data { for _, alert := range d.Alerts { - alert.Labels[constants.ReceiverName] = receiver.GetName() + if alert.Labels[constants.ReceiverName] == "" { + alert.Labels[constants.ReceiverName] = receiver.GetName() + } + if alert.Labels[constants.ReceiverType] == "" { + alert.Labels[constants.ReceiverType] = receiver.GetType() + } } } }