Please avoid posting in the Grafana parent category. Whenever possible choose a subcategory.
Hi All,
We are looking to create some custom template to send the notification in good format. We able to get some sort of data there but not able to present in defined format. We are looking to split the lines in template but it looks like taking all the contents as string and wrapping as per text.
Please find below the screen shot
Regards,
Shashi
THANK YOU!!
~ the grafana team
Hi,
We are using the below template to make the alert message.
{{ define “myalert” }}
[{{.Status}}] - {{ .Labels.alertname }},
{{ with .ValueString }}
Metric Values : {{- . | reReplaceAll \[\s
“” | reReplaceAll \],\s
“\n” | reReplaceAll \]
“” | reReplaceAll var='[A-Z0-9a-z]+'\s
“” | reReplaceAll labels=\{[A-Za-z0-9_\-\=\s\.:,]+\}\s
“\n” | reReplaceAll metric='(.*)'
" $1 " | reReplaceAll value=([0-9\.]+)
“($1),” }}
{{ end }}
Labels:
{{ range .Labels.SortedPairs }}
{{ .Name }}: {{ .Value }},
{{ end }}
{{ if gt (len .Annotations) 0 }}
Annotations:
{{ range .Annotations.SortedPairs }}
{{ .Name }}: {{ .Value }},
{{ end }}
{{ end }}
{{ if gt (len .SilenceURL ) 0 }}
Silence alert: {{ .SilenceURL }},
{{ end }}
{{ if gt (len .DashboardURL ) 0 }}
Go to dashboard: {{ .DashboardURL }}.
{{ end }}
{{ end }}
=============
{{ define “mymessage” }}
{{ if gt (len .Alerts.Firing) 0 }}
{{ len .Alerts.Firing }} firing:
{{ range .Alerts.Firing }} {{ template “myalert” .}} {{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
{{ len .Alerts.Resolved }} resolved:
{{ range .Alerts.Resolved }} {{ template “myalert” .}} {{ end }}
{{ end }}
{{ end }}
Regards,
Shashi
Check out this post - it’s for slack, but has steps to get the query response labels into your message template.
welcome to the community @baileyheit1 !
This is a really common question and I’m still learning how to access the values out of the alert query too. I hope this is a helpful example - I tried to make it very detailed for the benefit of other community users, even though I can tell you already know how to do some of these steps
With an alert query that looks like this - I created this with our sample TestDataDB datasource and manually added some labels that are similar to the on…