Not being able to acess variables in grafana alert template

So my template preview looks like:

metric=‘umidade’ labels={} value=96.78

So in my research it seems i should able to acess {{ .Metric }} and {{ .Value }}, but i try to put in the template and symply does not print anything.

The {{ .ValueString}} works and prints : [ metric=‘umidade’ labels={} value=96.78 ].
Like it should, so i dont know why the {{ .Metric }} and {{ .Value }} dont work.

I tried then using Regex function to extract both “metric” and “value” from
{{ .ValueString}} but regex functions are undefined in grafan 8.4.5 which im using.

then i tried using this to extract the value from the map:
{{- $valueStr := .ValueString -}}
{{ with $valueStr }}
{{ range $k, $v := . }}
Alerting value: {{ $v }}
But also did not print anything.

In my annotations i try to add labels like this:
image

which im not sure its supposed to work, but it didnt.

So it seems im a bunch of thing that should work are not working for me, anybody could help?

The query loks like this ( ididnt write the query and dont really know the language being used):
SELECT sensor_values.value AS umidade,
$__time(sensor_values.created_at)
FROM farm_io_devices
INNER JOIN sensors
ON sensors.farm_io_device_id = farm_io_devices.id
AND sensors.deleted_at IS NULL
INNER JOIN sensor_values
ON sensor_values.sensor_id = sensors.id
WHERE farm_io_devices.deleted_at IS NULL
AND sensor_values.value != 0
AND sensors.sensor_type = 1 – temperature: 0 humidity: 1 luminosity: 2 vpd: 3
AND farm_io_devices.id IN(‘5735’) – device id
AND $__timeFilter(sensor_values.created_at)
ORDER BY sensor_values.created_at

Hi! Metric does not exist in templates, it’s just a feature of Classic Conditions.

1 Like