From 1951593cc95950cbcfaf9c59cd29b9427f2f0c01 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 19 Nov 2015 15:49:37 +0100 Subject: [PATCH] Always have alertname in first position --- notify/impl.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/notify/impl.go b/notify/impl.go index 1abec92f..dd7fd405 100644 --- a/notify/impl.go +++ b/notify/impl.go @@ -120,11 +120,19 @@ func generateTemplateData(ctx context.Context, as ...*types.Alert) *TemplateData data.Alerts = append(data.Alerts, alert) } + sortStart := 0 for k, v := range groupLabels { data.GroupLabels[string(k)] = string(v) - data.GroupLabelnames = append(data.GroupLabelnames, string(k)) + + // Always have the alertname label at the first position. + if k == model.AlertNameLabel { + data.GroupLabelnames = append([]string{string(k)}, data.GroupLabelnames...) + sortStart = 1 + } else { + data.GroupLabelnames = append(data.GroupLabelnames, string(k)) + } } - sort.Strings(data.GroupLabelnames) + sort.Strings(data.GroupLabelnames[sortStart:]) if len(alerts) >= 1 { common := alerts[0].Labels.Clone()