Alerting: Add resolved count to notification title when both firing and resolved present (#46697)

* Alerting: Add resolved count to notification title when both firing and resolved are present

* Fix test case default_template_test.go
This commit is contained in:
Matthew Jacobson 2022-03-29 17:22:28 +02:00 committed by GitHub
parent 48113beeeb
commit 932f43b220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -12,7 +12,7 @@ import (
const DefaultMessageTitleEmbed = `{{ template "default.title" . }}` const DefaultMessageTitleEmbed = `{{ template "default.title" . }}`
var DefaultTemplateString = ` var DefaultTemplateString = `
{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }} {{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }}{{ end }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
{{ define "__text_alert_list" }}{{ range . }} {{ define "__text_alert_list" }}{{ range . }}
Value: {{ or .ValueString "[no value]" }} Value: {{ or .ValueString "[no value]" }}

View File

@ -86,7 +86,7 @@ func TestDefaultTemplateString(t *testing.T) {
}{ }{
{ {
templateString: DefaultMessageTitleEmbed, templateString: DefaultMessageTitleEmbed,
expected: `[FIRING:2] (alert1)`, expected: `[FIRING:2, RESOLVED:2] (alert1)`,
}, },
{ {
templateString: `{{ template "default.message" .}}`, templateString: `{{ template "default.message" .}}`,