diff --git a/emails/templates/ng_alert_notification.txt b/emails/templates/ng_alert_notification.txt index 758beb49afe..cc8e1ab8c11 100644 --- a/emails/templates/ng_alert_notification.txt +++ b/emails/templates/ng_alert_notification.txt @@ -1,38 +1,62 @@ -[[HiddenSubject .Subject "[[.Title]]"]] +[[- define "__default_message" -]] +You have [[ len .Alerts.Firing ]] firing alert(s), and [[ len .Alerts.Resolved ]] resolved alert(s) for [[ .GroupLabels ]] -[[.Title]] ----------------- +[[ if .Alerts.Firing -]] +([[ len .Alerts.Firing ]]) FIRING +----------- +[[ template "__default_alerts_summarize" .Alerts.Firing ]] +[[- end ]] -[[ .Alerts | len ]] alert[[ if gt (len .Alerts) 1 ]]s[[ end ]] for -[[ range .GroupLabels.SortedPairs ]] -[[ .Name ]] = [[ .Value ]] -[[ end ]] -[[ if gt (len .Alerts.Firing) 0 ]]([[ .Alerts.Firing | len ]]) Firing[[ end ]] -[[ range .Alerts.Firing ]] -Labels: -[[ range .Labels.SortedPairs ]] -[[ .Name ]] = [[ .Value ]] -[[ end ]] -[[ if gt (len .Annotations) 0 ]] -Annotations: -[[ end ]] -[[ range .Annotations.SortedPairs ]] -[[ .Name ]] = [[ .Value ]] -[[ end ]] -[[ end ]][[ if gt (len .Alerts.Resolved) 0 ]]([[ .Alerts.Resolved | len ]]) Resolved[[ end ]] -[[ range .Alerts.Resolved ]] -Labels: -[[ range .Labels.SortedPairs ]] -[[ .Name ]] = [[ .Value ]] -[[ end ]] -[[ if gt (len .Annotations) 0 ]] -Annotations: -[[ end ]] -[[ range .Annotations.SortedPairs ]] -[[ .Name ]] = [[ .Value ]] -[[ end ]] -[[ end ]]View your Alert rule: -[[.RuleUrl]] +[[ if .Alerts.Resolved -]] +([[ len .Alerts.Resolved ]]) RESOLVED +------------- +[[ template "__default_alerts_summarize" .Alerts.Resolved ]] +[[- end ]] +Go to the Alerts page: [[ .AlertPageUrl ]] +[[- end -]] -Go to the Alerts page: -[[.AlertPageUrl]] +[[- define "__default_alerts_summarize" -]] +[[- range . ]] +[[ template "__default_alert_labels" . ]] +[[ template "__default_alert_annotations" . ]] +[[- end ]] +[[- end -]] + +[[- define "__default_alert_labels" -]] +[[- if gt (len .Labels) 3 -]] +Labels: [[ template "__default_sorted_pairs" .Labels ]] +[[- else -]] +Labels: [[ .Labels.SortedPairs ]] +[[- end -]] +[[- end -]] + +[[- define "__default_alert_annotations" -]] +[[- $annotations := .Annotations -]] +[[- if index $annotations "summary" -]] +Summary: [[ index .Annotations "summary" ]] +[[- $annotations = $annotations.Remove (toStrings (list "summary")) ]] +[[ end -]] +[[- if index $annotations "description" -]] +Description: [[ index $annotations "description" ]] +[[- $annotations = $annotations.Remove (toStrings (list "description")) ]] +[[ end -]] +[[- if index $annotations "runbook_url" -]] +Runbook: [[ index $annotations "runbook_url" ]] +[[- $annotations = $annotations.Remove (toStrings (list "runbook_url")) ]] +[[ end -]] +[[- if $annotations -]] +Annotations: [[ template "__default_sorted_pairs" $annotations ]] +[[ end -]] +[[- end -]] + +[[- define "__default_sorted_pairs" -]] +[[ range .SortedPairs ]] + [[ .Name ]] = [[ .Value ]] +[[- end ]] +[[- end -]] + +[[- if .Message -]] + [[ .Message ]] +[[ else -]] + [[ template "__default_message" . ]] +[[- end ]] diff --git a/public/emails/ng_alert_notification.txt b/public/emails/ng_alert_notification.txt index c002c21809a..da32894257a 100644 --- a/public/emails/ng_alert_notification.txt +++ b/public/emails/ng_alert_notification.txt @@ -1,41 +1,64 @@ -{{HiddenSubject .Subject "{{.Title}}"}} +{{- define "__default_message" -}} +You have {{ len .Alerts.Firing }} firing alert(s), and {{ len .Alerts.Resolved }} resolved alert(s) for {{ .GroupLabels }} -{{.Title}} ----------------- +{{ if .Alerts.Firing -}} +({{ len .Alerts.Firing }}) FIRING +----------- +{{ template "__default_alerts_summarize" .Alerts.Firing }} +{{- end }} -{{ .Alerts | len }} alert{{ if gt (len .Alerts) 1 }}s{{ end }} for -{{ range .GroupLabels.SortedPairs }} -{{ .Name }} = {{ .Value }} -{{ end }} -{{ if gt (len .Alerts.Firing) 0 }}({{ .Alerts.Firing | len }}) Firing{{ end }} -{{ range .Alerts.Firing }} -Labels: -{{ range .Labels.SortedPairs }} -{{ .Name }} = {{ .Value }} -{{ end }} -{{ if gt (len .Annotations) 0 }} -Annotations: -{{ end }} -{{ range .Annotations.SortedPairs }} -{{ .Name }} = {{ .Value }} -{{ end }} -{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}({{ .Alerts.Resolved | len }}) Resolved{{ end }} -{{ range .Alerts.Resolved }} -Labels: -{{ range .Labels.SortedPairs }} -{{ .Name }} = {{ .Value }} -{{ end }} -{{ if gt (len .Annotations) 0 }} -Annotations: -{{ end }} -{{ range .Annotations.SortedPairs }} -{{ .Name }} = {{ .Value }} -{{ end }} -{{ end }}View your Alert rule: -{{.RuleUrl}} +{{ if .Alerts.Resolved -}} +({{ len .Alerts.Resolved }}) RESOLVED +------------- +{{ template "__default_alerts_summarize" .Alerts.Resolved }} +{{- end }} +Go to the Alerts page: {{ .AlertPageUrl }} +{{- end -}} -Go to the Alerts page: -{{.AlertPageUrl}} +{{- define "__default_alerts_summarize" -}} +{{- range . }} +{{ template "__default_alert_labels" . }} +{{ template "__default_alert_annotations" . }} +{{- end }} +{{- end -}} +{{- define "__default_alert_labels" -}} +{{- if gt (len .Labels) 3 -}} +Labels: {{ template "__default_sorted_pairs" .Labels }} +{{- else -}} +Labels: {{ .Labels.SortedPairs }} +{{- end -}} +{{- end -}} + +{{- define "__default_alert_annotations" -}} +{{- $annotations := .Annotations -}} +{{- if index $annotations "summary" -}} +Summary: {{ index .Annotations "summary" }} +{{- $annotations = $annotations.Remove (toStrings (list "summary")) }} +{{ end -}} +{{- if index $annotations "description" -}} +Description: {{ index $annotations "description" }} +{{- $annotations = $annotations.Remove (toStrings (list "description")) }} +{{ end -}} +{{- if index $annotations "runbook_url" -}} +Runbook: {{ index $annotations "runbook_url" }} +{{- $annotations = $annotations.Remove (toStrings (list "runbook_url")) }} +{{ end -}} +{{- if $annotations -}} +Annotations: {{ template "__default_sorted_pairs" $annotations }} +{{ end -}} +{{- end -}} + +{{- define "__default_sorted_pairs" -}} +{{ range .SortedPairs }} + {{ .Name }} = {{ .Value }} +{{- end }} +{{- end -}} + +{{- if .Message -}} + {{ .Message }} +{{ else -}} + {{ template "__default_message" . }} +{{- end }} Sent by Grafana v{{.BuildVersion}} (c) {{now | date "2006"}} Grafana Labs