I'm setting up Grafana v8.3.4 alerts. If I use a template like the following
{{ define "test_message" }}
{{ range .Alerts.Firing }}
{{ print .ValueString }}
{{ end }}
{{ end }}
And test the e-mail notification using this template and the predefined message:
I get:
[ metric='foo' labels={instance=bar} value=10 ]
In the example above there's only one metric, but there could be more.
Question: Is there any way to loop through the returned metrics and display it as a table in the e-mail?
It would look something like:
Metric Name | Value |
---|---|
foo | 10 |
x | 22 |
y | 7 |
...
[UPDATE 6/24/2022] @Luis Almeida's answer led me to the right path, so I'm marking it as the correct answer even though my final solution was a little different.
Here are a couple of other links that also helped:
How to template annotations and labels - Grafana's Official Documentatio n Unified Alerting Grafana 8 | Prometheus | Victoria | Telegraf | Notifications | Alert Templating