There are a couple of changes I would recommend:
-
Instead of using Classic Conditions change the alert rule to use Reduce expression and then either a Threshold or Math expression. This will allow you to use
$labels
in both annotations and notification templates. -
Add a summary description to your alert rule with the following template:
instance={{ index $labels "instance" }} value={{ index $values "B" }}
You should change "B"
to the Ref ID of the Reduce expression if its different.
- Create a custom notification template like this and use it in your contact point:
{{ define "alert.summarize" -}}
{{ index .Labels "alertname" }}: {{ index .Annotations "summary" }}
{{- end }}
{{ define "alerts.summarize" -}}
{{ if .Alerts.Firing }}{{ len .Alerts.Firing }} firing alert(s)
{{ range .Alerts.Firing -}}
{{ template "alert.summarize" . }}
{{ end }}{{ end }}
{{ if .Alerts.Resolved }}{{ len .Alerts.Resolved }} resolved alert(s)
{{ range .Alerts.Resolved -}}
{{ template "alert.summarize" . }}
{{ end }}{{ end }}
{{ end }}