Variables not being used

Hey Guys,

First time poster - so please be gentle. I’ve beat my head against the wall trying to understand why a particular alert won’t fill in the variables.

I have created a pretty basic CPU threshold alert:

When the threshold gets crossed, it does successfully generate an alert:

[ var='B0' metric='CPU - XX.XX.XX.XX:9100' labels={instance=XX.XX.XX.XX:9100} value=37.43333333275385 ]

However, when I put use any of the following variables, they do not get picked up when they get delivered to slack:

Variable Tests

  1. {{$values.C0.Value}}
  2. {{humanizePercentage $values.C0.Value}}
  3. {{$values.A0.Value}}
  4. {{$values.B0.Value}}
  5. {{$values.C0.Value}}
  6. {{$values.B0.Value}}
  7. {{ $values.B }}
  8. {{$values.A.Value}}
  9. {{$values.B.Value}}
  10. {{$values.C.Value}}

This is what they look like in Slack:

(As you can see, I’ve tried every variation of the values variable). I have other alerts in production that do work successfully with these variables.

Can someone please point me to what I’m obviously overlooking.

Hi and welcome.

What version of Grafana are you using?
At first glance, I would have expected your query to work like this:

Can you share the output of what you see when you click Preview alerts?

Hi @grant2

Thanks for giving me a hand. I like the cleanup in B. Thanks for the tip.

This is the output:

[ var='B' labels={instance=xx.xx.xx.xx:9100} value=16.7944444446928 ], [ var='C' labels={instance=xx.xx.xx.xx:9100} value=1 ]

Alas, the alerts still do not show the values where the variables are :frowning:

Grafana version is v9.2.1 (34f7baebda)

Do these work?

{{ $values.B.Labels.instance }}
{{ $values.B.Value }})
{{ $values.C.Labels.instance }}
{{ $values.C.Value }})

No Dice:

{{ index $values.B.Labels “instance” }}

Does the above make any difference?

Nope - it just shows that as regular text in the Slack notification. I also tried email to see if it was unique to our Slack implementation, and it showed the same behavior.

Hi! Is this a message template or a template for a custom annotation?

I am having the same issue. I’m trying to make add dynamic information into custom alert labels. We are using Grafana 8.1.2. I do have a “Classic condition” operation on the alert which is “B” but I’m trying to pull from “A”. The below all render as plain text in the alert instead of the dynamic data I’m wanting. Any ideas or help would be much appreciated.

{{ $values.A0.Labels }}
{{ $values.A0 }}
{{ $values.A }}
{{ $values.A.Labels.instance }}
{{ $values.A0.Labels.instance }}

Hi! If A is the query in your alert then you cannot use $values.A because A is a time series, not a single value. This is also why you either need a Reduce expression or Classic Condition as Grafana can only alert on single values, not time series.

I think in your example you will want to use $values.B0, which is the Classic Condition. The number at the end corresponds to the condition in the Classic Condition.

If it helps the documentation on templating labels and annotations can be found here Templating labels and annotations | Grafana documentation.

That makes sense. Thanks!