How to get alertname in notification title

  • What Grafana version and what operating system are you using?
    Grafana 8.1.2 with NGAlert enabled

  • What are you trying to achieve?
    I want to see alert name in notifications titles using my own template

  • How are you trying to achieve it?
    I’ve created template:

{{ define "template_title" }}
[{{.Status}}] {{ .Labels.alertname }}
{{ end }}

and set it as templated title of the Slack message.
image

I get this code here - Message templating | Grafana documentation

  • What happened?
    Alert message in Slack is empty with just status
    image

  • What did you expect to happen?
    I expect to get normal alert message

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

No

Can you screenshot your full alert config? If you are using Grafana managed alerts with a classic condition, templating will not work.

You must use a multi-dimensional rule.

Hi Matt!
I don’t know how it works, but now I use template based on default one and get only title.

{{ define "template_title" }}
[{{ .Status | toUpper }}: {{ if eq .Status "firing" }}{{ .Alerts.Firing | len }}{{ else if eq .Status "resolved" }}{{.Alerts.Resolved | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }}
{{ end }}

And yes, I use multi-dimensional rules everywhere.
I can’t explain why {{ .Labels.alertname }} isn’t working

2 Likes