How to include separate labels into custom email template for notification

65 views
Skip to first unread message

Владимир organ2

unread,
Jun 30, 2020, 9:53:52 AM6/30/20
to Prometheus Users
Hi, folk.
I wanna use custom email template for notification. I've found some template (in attachment). Changed it a little. And now title of email looks like this:

But It's unreadable. I want to create some template which will look like:

[FIRING:1] {{ .labels.custom_host }}:{{ .labels.alertname }}

I want to include only few labels (custom_name and alertname) into email title. How can I do it?




Here's the row from default.tmpl which is intended for creating email title:

{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}

default.tmpl

Владимир organ2

unread,
Jul 1, 2020, 11:12:33 AM7/1/20
to Prometheus Users
I figured out that this part using for creating [FIRING:1] or [RESOLVED] and it works.
{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ end }}
But I don't now what I should insert inside for getting only one label.

If I insert {{ .labels.alertname }} inside it just broke my email
{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .labels.alertname }} {{ end }}


Владимир organ2

unread,
Jul 2, 2020, 4:10:21 AM7/2/20
to Prometheus Users
I managed to do it!!!.
If you wanna make your own subject (title) with particular labels you should use {{ .GroupLabels.your_label }} and put it in this row:


{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] __put here___ {{ end }}

Now my notification looks like this:

Reply all
Reply to author
Forward
0 new messages