Documentation of Alert Templating in Serious Need of Improvement!

Hi @georgerobinson

Thank you so much for the help. I will try to upgrade and let you know.

@georgerobinson One more thing, One last one please help regarding the outlook mail subject, we are not getting colored emojis while receiving an emails form Grafana.
Can you please help me how to get colored emoji’s?

Hi! Are coloured emojis supported in Microsoft Outlook?

1 Like

@georgerobinson Not sure. I am trying this first time with Emoji’s.

OK, can you confirm that emojis work in Microsoft Outlook (for example, send yourself an email with an emoji in it)?

Hi @georgerobinson

I am able to see the colored emoji in the Body but not in the Subject.

OK, that could be a limitation of Microsoft Outlook then.

image

using red heart

:heart:

Okay got it @georgerobinson

Thank you so much for the help.

1 Like

Hi! I would like to share the 9.4 docs for templating notifications and would love to get some feedback from the community on what is good, what could be improved, and what is missing.

Thank you!

George, Alerting squad

4 Likes

@georgerobinson thank you for pointing out the documentation about customizing notifications.
Can I ask you something though, in my case the content I have been getting on Value parameter was full before updating grafana to the latest? E.g

**Firing**

Value: [ var='B0' metric='Value' labels={server=my_webapp_url} value=4 ]
Labels:

But on the latest Grafana it is not showing the details

Value: B=3

I don’t wanna touch anything on grafana notification template, I just wanna have the same content as before. BTW am using the http_response input plugin on telegraf.

1 Like

Hi! Grafana 9.3 changed the default template to print just the values of each expression instead of the value string, as we received a lot of feedback about it not being useful. We haven’t removed the value string from Grafana though, so feel free to use it in your own template if you prefer it.

1 Like

@georgerobinson ow so that was the reason, thanks for letting me know. I have never used a template in grafana before, can you please tell me how can I achieve that, customization of my own template?

Thanks

You’ll want to check out the documentation Customize notifications | Grafana documentation. You can then copy the default template from Grafana v9.2.8.

For example, something like this:

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

{{ define "custom.alert_message" }}{{ range . }}
Value: {{ or .ValueString "[no value]" }}
Labels:
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}Annotations:
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}
{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}
{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}
{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }}
{{ end }}{{ end }}{{ end }}

{{ define "custom.title" }}{{ template "custom.subject" . }}{{ end }}

{{ define "custom.message" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**
{{ template "custom.alert_message" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}
{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
{{ template "custom.alert_message" .Alerts.Resolved }}{{ end }}{{ end }}
1 Like

Hello @georgerobinson I tried to copy the default template from Grafana v9.2.8 but still there is no output from Value prop.

please can you please tell me what templating code I should set in Value: :cry::cry:

@georgerobinson any thoughts on @elhananjair post, I could use the same.

Hi! Can I see the template you have copied, and also how you are using the template from your contact point?

@georgerobinson thank you for replying
Template I have copied:

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

{{ define "__text_alert_list" }}{{ range . }}

Value: {{ or .ValueString "[no value]" }}

Labels:

{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}

{{ end }}Annotations:

{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}

{{ end }}{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}

{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}

{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}

{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }}

{{ end }}{{ end }}{{ end }}

{{ define "default.title" }}{{ template "__subject" . }}{{ end }}

{{ define "default.message" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**

{{ template "__text_alert_list" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}

{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**

{{ template "__text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}

{{ define "__teams_text_alert_list" }}{{ range . }}

Value: {{ or .ValueString "[no value]" }}

Labels:

{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}

{{ end }}

Annotations:

{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}

{{ end }}

{{ if gt (len .GeneratorURL) 0 }}Source: [{{ .GeneratorURL }}]({{ .GeneratorURL }})

{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: [{{ .SilenceURL }}]({{ .SilenceURL }})

{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: [{{ .DashboardURL }}]({{ .DashboardURL }})

{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: [{{ .PanelURL }}]({{ .PanelURL }})

{{ end }}

{{ end }}{{ end }}

{{ define "teams.default.message" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**

{{ template "__teams_text_alert_list" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}

{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**

{{ template "__teams_text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}`

I just copied the above template into Message Template section in contact points

Hi! You need to change the names of each template as per my example, otherwise it will conflict with the default template. You can then use this template from your contact point. For example: {{ template "custom.message" . }}

1 Like

name of each template? does the name of template you are saying implies “ACSO_Message_Template” in my case from the screenshot? or is it a key found in the template code?

How do I use the template defined in the Message template to be used in contact points which in my case is Telegram?

I am really sorry, it’s confusing me the way created templates would be used in contact points.