mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-04 04:52:05 +00:00
Merge pull request #153 from prometheus/subject
Improve default subject template
This commit is contained in:
commit
d090400d3d
@ -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()
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{ define "__subject" }}{{$dot := .}}[{{ .Status }}] {{ range $k := .GroupLabelnames }}{{ index $dot.GroupLabels $k }} {{ end }}{{if gt (len .AlertCommonLabels) (len .GroupLabels) }}({{ range $k := .AlertCommonLabelnames }}{{ if eq "" (index $dot.GroupLabels $k) }}{{ index $dot.AlertCommonLabels $k }}{{ end }}){{ end }}{{ end }}{{ end }}
|
||||
{{ define "__subject" }}{{$dot := .}}[{{ .Status }}:{{ .Alerts | len }}] {{ range $k := .GroupLabelnames }}{{ index $dot.GroupLabels $k }} {{ end }}{{if gt (len .AlertCommonLabels) (len .GroupLabels) }}({{ range $k := .AlertCommonLabelnames }}{{ if eq "" (index $dot.GroupLabels $k) }}{{ index $dot.AlertCommonLabels $k }}{{ end }}{{ end }}){{ end }}{{ end }}
|
||||
|
||||
{{ define "slack.default.fallback" }}
|
||||
{{ template "__subject" . }}
|
||||
|
Loading…
Reference in New Issue
Block a user