i have a question regarding the notification template.
How can I display the exact values that triggered the alarm in the Google Chat notification? (Sometimes these can be several values)
example: (Exact values for rx and tx in alarm)
myalert:
{{ define "myalert" }}
<font color="#FFB600"><b>[{{.Status}}]</b></font>: {{ .Labels.alertname }}
--------------------------------
<font color="#FFB600"><b>[Value]</b></font>: {{ or .ValueString "[no value]" }}
--------------------------------
{{ if gt (len .Annotations) 0 }} <font color="#FFB600"><b>[Annotations]</b></font>:{{ range .Annotations.SortedPairs }}
{{ .Name }}: {{ .Value }}{{ end }}
--------------------------------
<font color="#FFB600"><b>[Dashboard]</b></font>: <a href="{{ .DashboardURL }}">{{ .DashboardURL }}</a>
{{ end }}
{{ end }}
mymassage:
{{ define "mymessage" }}{{ if gt (len .Alerts.Firing) 0 }} <font color="#FF2A00"><b>**Firing**</b></font>
{{ range .Alerts.Firing }} {{ template "myalert" .}} {{ end }}{{ end }} {{ if gt (len .Alerts.Resolved) 0 }} <font color="#17D600"><b>**Resolved**</b></font>
{{ range .Alerts.Resolved }} {{ template "myalert" .}} {{ end }}{{ end }}{{ end }}
Or is it possible to see somewhere how the Deafult alerting was in the Grafana 8 version ?
can you help me with this in a little more detail. I have a value output in the chat, which also contains labels. Here we have too much labels information. Can I somehow reduce this to the most important?
e.g
grafana template = …[Value]: {{ or .ValueString “[no value]” }}…
Google Chat = …
I would like to try then like you did in your example, can you help me one more tip for the correct spelling in the template, how would I adjust something like that for example so that I have such an alerting.
Instead of using Classic Conditions change the alert rule to use Reduce expression and then either a Threshold or Math expression. This will allow you to use $labels in both annotations and notification templates.
Add a summary description to your alert rule with the following template:
instance={{ index $labels "instance" }} value={{ index $values "B" }}
You should change "B" to the Ref ID of the Reduce expression if its different.
Create a custom notification template like this and use it in your contact point:
{{ define "alert.summarize" -}}
{{ index .Labels "alertname" }}: {{ index .Annotations "summary" }}
{{- end }}
{{ define "alerts.summarize" -}}
{{ if .Alerts.Firing }}{{ len .Alerts.Firing }} firing alert(s)
{{ range .Alerts.Firing -}}
{{ template "alert.summarize" . }}
{{ end }}{{ end }}
{{ if .Alerts.Resolved }}{{ len .Alerts.Resolved }} resolved alert(s)
{{ range .Alerts.Resolved -}}
{{ template "alert.summarize" . }}
{{ end }}{{ end }}
{{ end }}
Hi @georgerobinson. Please I need help with value string in grafana v9.4 I used Valuestring: {{ .ValueString }} in my custom grafana template, and got the output below