Need help using variables in an Email notification message

two steps forward, 1K back. I just cant seem to get templates working. Do all alerts auto magically pick up template or do you have to explicitly associate alerts with templates. Or is this done via some sort of tagging/labeling?

Thanks

I think I also am going in that direction. alerts in grafana are not yet fully matured. would have been nice to have it all in one place but alas

I define a template called “Telegram” and then refer to it in the relevant contact point under “Optional Telegram Settings → Message” with the expression {{ template "Telegram" . }}

1 Like

:wink: thanks sir! And where is this in the documentation? Been staring at it half day

It’s on a screenshot here: Notification templating | Grafana documentation

but then nowhere in the documentation do you see mymessage. I got a lot of digging to do. thanks

1 Like

Hello Victor, I am in process of setting up Grafana notifications and this a new setup. I am also struggling around customizing the email subject and message in Grafana Alerts. If you able to further enhance the template, Would you like to share please.
Also , please advise if it is better to use Zabbix for notifications OR I should stuck with Grafana. ( As my setup is new, I have not setup any Alerts from grafana, I can setup in Zabbix from scratch )?

Hello @ahussain19

I like the E-mail template as it is so I’ve never tried to customize it, sorry.

Also, if you use the newfangled Grafana alert rules which can produce multiple alarms, you pretty much have no choice IMHO.

victor hello ,

with this template i get some info , thanks for sharing…
"
{{ if gt (len .Alerts.Firing) 0 }}
FIRING: {{ len .Alerts.Firing }} alerts
{{ range .Alerts.Firing }}
{{ if gt (len .Annotations) 0 }}
Summary: {{ .Annotations.summary }}
Description: {{ .Annotations.description }}
Labels: {{ range .Labels.SortedPairs }} {{ .Name }}: {{ .Value }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
RESOLVED: {{ len .Alerts.Resolved }} alerts
{{ range .Alerts.Resolved }}
{{ if gt (len .Annotations) 0 }}
Summary: {{ .Annotations.summary }}
Description: {{ .Annotations.description }}
Labels: {{ range .Labels.SortedPairs }} {{ .Name }}: {{ .Value }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
"

have someone get value of metric which is showing in graf ?

in default template grafana/default_template.go at main · grafana/grafana · GitHub
is described like this , but didn’t work or i am doing something wrong

{{ define “__text_values_list” }}{{ $len := len .Values }}{{ if $len }}{{ $first := gt $len 1 }}{{ range $refID, $value := .Values -}}
{{ $refID }}={{ $value }}{{ if $first }}, {{ end }}{{ $first = false }}{{ end -}}
{{ else }}[no value]{{ end }}{{ end }}

{{ define “__text_alert_list” }}{{ range . }}
Value: {{ template “__text_values_list” . }}

have someone simple solution for this ?

[ var=‘B0’ metric=‘Logins’ labels={name=Logins, instance=exporter:80, job=exporter} value=1527 ]

i need this value value=1527 :slight_smile: