From 35d455e93187b52887a88ab290638833ebc79495 Mon Sep 17 00:00:00 2001 From: George Robinson Date: Fri, 16 Jun 2023 15:06:43 +0100 Subject: [PATCH] Show the alertname for each alert in plain text email (#70183) --- emails/templates/ng_alert_notification.txt | 13 +++++++------ public/emails/ng_alert_notification.txt | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/emails/templates/ng_alert_notification.txt b/emails/templates/ng_alert_notification.txt index 0848d16804120..28e466d16df40 100644 --- a/emails/templates/ng_alert_notification.txt +++ b/emails/templates/ng_alert_notification.txt @@ -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" -]] diff --git a/public/emails/ng_alert_notification.txt b/public/emails/ng_alert_notification.txt index 7db5996f3db28..357a6a1ff4cbf 100644 --- a/public/emails/ng_alert_notification.txt +++ b/public/emails/ng_alert_notification.txt @@ -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" -}}