Hi,
I am new to Grafana and I am trying Grafana managed alerts right now. I have halfway understood the setup of the alerts, but now I want to customize the text in the emails. For this I want to use Template Variables, but all the instructions I found I either didn’t understand or it just doesn’t work.
-
What Grafana version and what operating system are you using?
Grafana Version 8.0.6 / Ubuntu (latest Version, only for my personal test environment) -
What are you trying to achieve?
I would like to enrich Grafana managed alerts with content from template variables. -
How are you trying to achieve it?
I created a simple alert rule (grafana managed alert):
A - query:
node_cpu_seconds_total{mode=“system”,cpu=“0”}
B - expression:
Reduce / Max / A
C - Expression:
Math / $B > 2140
Alert details:
Summary
{{ $labels.mode }}
{{ $labels.job }}
{{ $values.A }}
{{ $values.B }}
{{ $values.C }}
{{ $values.A.value }}
{{ $labels.A.cpu }}
{{ $labels.A.mode }}
{{ $values.B.value }}
{{ $labels.B.cpu }}
{{ $labels.B.mode }}
Custom Labels
mymode = {{ $labels.mode }}
myjob = {{ $labels.job }}
mybvalue = {{ $values.B }}
mybvaluevalue = {{ $values.B.value }}
-
What happened?
Only the two variables mymode and myjob are resolved correctly and are displayed in the alarm under labels. All other values appear only as strings. -
What did you expect to happen?
All variables should be resolved, especially in the summary. -
Can you copy/paste the configuration(s) that you are having problems with?
see above -
Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
no. No errors. -
Did you follow any online instructions? If so, what is the URL?
Create Grafana managed alert rule | Grafana documentation
Alarm email content:
Firing: 1 alertname
Firing Alert Prom 02
summary: {{ $labels.mode }} {{ $labels.job }} {{ $values.A }} {{ $values.B }} {{ $values.C }} {{ $values.A.value }} {{ $labels.A.cpu }} {{ $labels.A.mode }} {{ $values.B.value }} {{ $labels.B.cpu }} {{ $labels.B.mode }}
Labels:
alertname: Alert Prom 02
cpu: 0
instance: xyz.abc.de:9100
job: node_exporter
mode: system
mybvalue: {{ $values.B }}
mybvaluevalue: {{ $values.B.value }}
myjob: node_exporter
mymode: system
Can someone explain to me exactly how the syntax must be or explain to me what I am misunderstanding or doing wrong?
Are there any further instructions for Grafana managed alerts and template variables?