Merge pull request #153 from prometheus/subject

Improve default subject template
This commit is contained in:
Brian Brazil 2015-11-23 16:40:45 +00:00
commit d090400d3d
2 changed files with 11 additions and 3 deletions

View File

@ -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()

View File

@ -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" . }}