How To Use Alert Message Templates in Grafana

Hi @grant2 @melori.arellano I was trying to connect screenshots to my template, but it doesn’t work (Grafana v9.2.4). I use Microsoft Teams. This is my template:

{{ define “myalert” }}
{{ if gt (len .Annotations) 0 }}
{{ range .Annotations.SortedPairs }}

  • {{ .Name }}: {{ .Value }}
    {{ end }}
    {{ end }}

{{ if gt (len .PanelURL) 0 }}
Go to panel:

  • {{ .PanelURL }}
    {{ end }}
    {{ end }}

{{ define “mymessage” }}
{{ if gt (len .Alerts.Firing) 0 }}
{{ len .Alerts.Firing }} firing:
{{ range .Alerts.Firing }} {{ template “myalert” . }} {{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
{{ len .Alerts.Resolved }} resolved:
{{ range .Alerts.Resolved }} {{ template “myalert” . }} {{ end }}
{{ end }}
{{ end }}

Mb I need to connect some function to my template.
By the way I have screenshots with default template, but it didn`t work with my custom template.

Hi! Screenshots are added to notifications (including Microsoft Teams) irrespective of the default or custom templates. Have you tried the troubleshooting instructions Use images in notifications | Grafana documentation?

1 Like

Thank you for the quick response.
I didn’t see this troubleshooting instructions. I am going to read and try, thank you!

Hello, I perform all steps as it was in the example, but I didn’t work. My setup:

Why I have in the preview aler value for B and C?

annotation settings:

I have two templates:

I tested it for e-mail

As the result I received email:

Hi @georgerobinson
I saw your manual “Set up image rendering” and I noticed that image rendering is not supported at this time. You can check it in attachments.

Can you please explain why it’s not supported, and when do you plan to fix it?

Hi! I’m afraid I’m not the author of this page, but what it is saying is that you cannot screenshot entire dashboards, just individual panels within a dashboard. This isn’t an issue for alerting as if you add an alert to a panel its only the panel that will be screenshot.

1 Like

how about email? where i can find the documentation to custom email message notification. Thanks


Hi! I would like to share the 9.4 docs for templating notifications and would love to get some feedback from the community on what is good, what could be improved, and what is missing.

Thank you!

George, Alerting squad

@georgerobinson That’s a nice try!
With v9 alerts messages are now very difficult to read, and it seems that the only way to customise messages is to use templates…
Unfortunately how-to instructions are quite difficult to find, even among Grafana docs…
Your doc Create message templates | Grafana documentation is a good start, but it would be very helpful to have a few examples for Slack notifications but for single alerts!!
Do you have by chance any examples to share?

Hi! Thanks for the feedback. I’m not sure I understand why you would want a notification template that only works for a single alert? What would happen if you had two alerts in the same notification?

In v8 alert notifications were forwarded one at a time (see attached screenshot).
Using the example as per your doc, alerts will be displayed one at a time as well?


Hi @georgerobinson

I think maybe @robertojobet may be referring to the fact that when multiple alerts are put into a single Slack notification, it can be a bit difficult to read. For example, this is a Slack notification containing 2 alerts. It would be nicer to have them separated, but I believe that is not possible based on Grafana’s settings for the notification channel.

1 Like

Hi @grant2
This is exactly what I’m referring to!
I presume that with the snippet that @georgerobinson is referring to in his docs, in case let’s say that 10 alerts are triggered all 10 alerts would be displayed in a single notification?!
That would be a nightmare…

If you would like each alert to be sent as a separate Slack message you can do this by changing the grouping in your notification policy. You will want to remove any labels in “Group by”. Grouping is unrelated to templates, and I would recommend writing templates that support any number of alerts per message in case you want to change the grouping later.

Thanks George. I will try this out next week.

Hi!, i need help…


I am not able to accommodate my template, I need help!


is a simple query. It only warns when a windows service is down…

Could you give me a hand to understand better?

thanks! Sorry my english!

Hi! I’m sorry but I’m not sure I understand the issue you’re having with templates. Is it with writing templates or something else?

hello! I don’t really have any problem… what I want is for it to look better, but I don’t understand how variables are handled

i try to used variables to accommodate my template, but I can’t get the data right


The description field:

Servicio:{{ $labels.instance }} Estado de servicio: {{ $value.D }}

but in the alert, says:


Would be great if one could develop alerts for example in vscode with a special plugin that does intellisense abd typeaheads