How to keep ValueString in notification templates in Grafana 9.3 and later

There are a couple of changes I would recommend:

  1. 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.

  2. 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.

  1. 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 }}