alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Accessing current date / other functions in the Alertmanager Go templates

Open ddewaele opened this issue 8 years ago • 4 comments

We're using AlertManager to send out emails.

Question 1 : Emails apps like Inbox group emails to create conversations based on the email title. Our current email title is something like "X services failing" so that makes for horrible grouping / conversations.

The requirement would now be to group them per day by including the date in the subject.

However, I'm not able to access the current date in the Go Templates.

Is there another way of doing this ?

  • Can it be passed on as a label by prometheus (using the alert.rules) ?
  • Can something be done in the alertmanager configuration ?

Question 2 : As a general remark , we often get requirements to change the email templates. For example :

  • Change the sorting of the alerts
  • Add how long an alert was active (current date - startsAt)
  • ...

These seem to be very difficult to implement using the Go templates as a lot of these functions aren't available (no sorting, no access to date functons / current date, ....)

How should we go about this ?

ddewaele avatar Jan 13 '17 06:01 ddewaele

+1

copernico avatar Apr 26 '17 19:04 copernico

#1178 is related to the second question

tzz avatar Apr 07 '18 01:04 tzz

Hi! 👋 I think being able to access the current date/time in an Alertmanager template is a valid use case. Have you considered contributing this change? You can find the functions in template/template.go.

grobinson-grafana avatar Nov 19 '23 13:11 grobinson-grafana

Adding sprig support would be a solution for this. Requested in https://github.com/prometheus/alertmanager/issues/3726. @ddewaele can we close this in favor of https://github.com/prometheus/alertmanager/issues/3726 ?

TheMeier avatar Mar 20 '24 06:03 TheMeier