If statement syntax for an alert message

I’m trying to nail an if statement I have in the message of a grafana alert. I have an influx data source returning a value H1 which can either be 1 or 0. I want these mapped to “Open” and “Closed”

I figured the if statement would be
{{if eq .Values.H1 1}} Open {{ else }} Closed {{ end }}

I have tested and know {{.Values.H1}} returns 1 currently. I’ve also tried the 1 in quotes incase the influx value is being read as a string but same issue where nothing is returned in the message.

Cheers.

welcome @Brammerz !

Instead of Values. try using $values. variable + the RefID of the Alert condition.

{{if gt $values.C.Value 90.0 }}open{{else}}closed{{end}}

Here’s how I template the data returned from a query when a certain condition is met. In my case the RefID is C .

Next, add the template to the label. I named it status. The value of the label status will dynamically change to open or closed if according to the Threshold expression C above (which I marked as my Alert condition).

Finally, in the alert notification, I can see the value of the label switched to closed

Hope it helps!