Alertmanager email template (help)

333 views
Skip to first unread message

Jseb Tarot

unread,
Oct 23, 2023, 6:35:29 AM10/23/23
to Prometheus Users

Hello,

I'm trying to change the Alertmanager email template.

I can't seem to adapt an email template to make it work the way my boss wants. Personally, I find the default template to be quite good. However, my boss finds it a bit messy, which is not entirely untrue. In case of an issue, a misinterpretation can be dangerous, especially in a production environment! Anyway, I know that the template is in the binary of the prom/alertmanager container. However, it is possible to redefine the template to replace the default one. I've tested this method:

https://velenux.wordpress.com/2021/04/23/how-to-change-prometheus-alertmanager-e-mail-template/

And it works! But I must admit that, despite my efforts, I can't seem to modify this template because even the slightest error results in an empty email, but that's normal ;). I know that the developers have defined a large number of functions (https://prometheus.io/docs/alerting/latest/notifications/). So, in theory, we should be able to customize the templates. However, I don't know the list of variables I can use, nor the structure that the email template should have.

Can someone help me?

Thank you,

Best regards,


JsT

Adrian Popa

unread,
Oct 23, 2023, 7:45:55 AM10/23/23
to Jseb Tarot, Prometheus Users
Handling the email template was a headache for me as well. Mostly
because it needs to be written in the Go templating language - which I
was unfamiliar with.
But - there is a way to "dump" all the attributes of the alert to
figure out what the structure is and how you can write the template. I
do this inside a hidden DIV inside the email, so I can view it if
necessary by looking at the source of the email:
```
<div name="GLOBAL DEBUG" style="display: none;">
<!-- Print the data structure we've been handed for
debugging -->
<br>
{{ printf "%#v" . }}
<br>
</div>

```
I generally don't use aggregation for email alerts, because I prefer
to see one email per alert.

I've linked my alertmanager/config/template-email-slack.tmpl , for
reference: https://pastebin.com/ufjyZJhm
I'd also like to learn how to best tune the email template.
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/ab81b3d7-90b7-41b3-a128-1b882d7bc484n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages