Skip to content

Commit

Permalink
Show the alertname for each alert in plain text email (grafana#70183)
Browse files Browse the repository at this point in the history
  • Loading branch information
grobinson-grafana authored Jun 16, 2023
1 parent 9b1f1df commit 35d455e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions emails/templates/ng_alert_notification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ Go to the Alerts page: [[ .AlertPageUrl ]]

[[- define "__default_alerts_summarize" -]]
[[- range . ]]
[[ template "__default_alert_labels" . ]]
[[- 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 -]]
[[- $labels := .Labels -]]
[[- if index $labels "alertname" ]]
Alertname: [[ index .Labels "alertname" -]]
[[ $labels = $labels.Remove (toStrings (list "alertname")) ]]
[[- end ]]
Labels: [[ template "__default_sorted_pairs" $labels ]]
[[- end -]]

[[- define "__default_alert_annotations" -]]
Expand Down
13 changes: 7 additions & 6 deletions public/emails/ng_alert_notification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ Go to the Alerts page: {{ .AlertPageUrl }}

{{- define "__default_alerts_summarize" -}}
{{- range . }}
{{ template "__default_alert_labels" . }}
{{- 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 -}}
{{- $labels := .Labels -}}
{{- if index $labels "alertname" }}
Alertname: {{ index .Labels "alertname" -}}
{{ $labels = $labels.Remove (toStrings (list "alertname")) }}
{{- end }}
Labels: {{ template "__default_sorted_pairs" $labels }}
{{- end -}}

{{- define "__default_alert_annotations" -}}
Expand Down

0 comments on commit 35d455e

Please sign in to comment.