Grafana - using variables in the "Message" field of Email and other contacts

Colleagues, what’s the syntax and list of variables than can be used in the “Message” field of an Email contact point (please see the image)? These should be documented somewhere? I’ve tried putting just plain text into this field and it works as expected (arrives in the body of the message). When I try variables in different formats (like $Description, ${Description}, {{Description}} etc) I get inconsistent results. I also would like to know how I can change the Subject field of the notification Email (now I see there a concatenated list of label values which is not what I’d want).

Heya Vicror,

You can use {{ .Annotations.summary }} for example.
If you want specific values you have to do this in your alarm config. For example in your summary you can use {{ $labels.host_name }} {{ humanizePercentage $values.C.Value }}. C is the step in your alarm. host_name is a label that comes from my query.
Also be aware that this only works for non “Classic conditions”.

> You can use {{ .Annotations.summary }} for example.
Does not seem to be the case. If I put “This is a mail alert {{ .Annotations.summary }}” into the message box, I only see the plain text part.

If a put something like “This is a mail alert {{ .Annotations.summary }}
This is a test label ${Label}.” into the box, I only get the first line of text in the E-mails. I also see no way to modify the Subject of the Emails. Clearly there must be documentation somewhere about the syntax.

E.g. where are my annotations being lost?

There are issues with mail notifications at the moment. See link below:
https://github.com/grafana/grafana/issues/42946

Because of this i don’t use any custom notifications for mail.
We also use Slack and there i use a header template to format the title and two message templates depending if the alert is a single value or multi value.

Here are some usefull links:
For annotations and lebale:
https://grafana.com/docs/grafana/latest/alerting/unified-alerting/alerting-rules/alert-annotation-label/#labels

For alerting templates
https://grafana.com/docs/grafana/latest/alerting/unified-alerting/message-templating/
And also this one:
https://grafana.com/blog/2020/02/25/step-by-step-guide-to-setting-up-prometheus-alertmanager-with-slack-pagerduty-and-gmail/
The unified alerting is a Prometheus alerting, so most things concerning templates do work.

Currently the documentation still needs a lot of work.
Been in contact with Grafana support about alerting templates and miss fires for the last 10 days.

How can I figure out if I’m using (by default) legacy or unified alerting in grafana-server 8.3.3 ? I think I’m a bit confused about all this. E,g. I can create a named template in “Contact points” -> Message Template, but I see no way of referring to that named template in an Email contact point configuration. I expected a dropdown menu or something with named templates.

Nor do I see a link to named templates in the Telegram contact point.

If you use a local Grafana install, you can look into your grafana.ini file.
https://grafana.com/docs/grafana/latest/alerting/unified-alerting/opt-in/

On Grafana Cloud unified alerting is the default.

Purely based on the screenshot of your mail i think you are using unified alerting, but better check to be sure.

In my grafana.ini I have the [unified_alerting] parameter commented out: ;enabled = false so really no way to tell which is the current default.

My email contact looks like this.

In your ini file you also have legacy alerting.
If that is disabled you use Unified alerting.

In your ini file you also have legacy alerting.
You would laugh at it but it is commented out too

# Disable legacy alerting engine & UI features
;enabled = true```

My email contact looks similar

Ok, can you make alerts without using grafs?
If yes, you use unified alerting.

Yes, you use unified alerting.
Look the same as mine.

Not quite. I’m lacking the “Alertmanager” dropdown

Well, my alerting works when there is a label match, so probably it’s unified. But I cannot use variables

I’ll review the links you’ve sent me, thanks a lot for them.

So, your syntax to refer to a template is just {{ template "Test2" .}} ?