Multiple condtions within one alert rule

Dear community members,

I have a query which returns the current condition of the system as numerical values.
0 = Shutdown
1 = Debugging
2 = Update in Process
3 = Normal
4 = Error

The query returns only timestamp and the number 0,1,2,3 or 4.

I want to create a alert rule and set four alert conditions within this rule instead of the default C rule which applies a threshold.

I want to name each of these four conditions with the name for that value. Namely, Shutdown for condition 1, Debugging for condition 2, Update for condition 3, and Error for condition 4.

I will keep the condtion B as it is. But, inside each of these custom condtions, I want to check with a math expression
For example, $B == 0 for Shutdown condition. Similarly for the other conditions.

This works as I have imagined, but for only one condition as the rule allows setting only one condtion as the alert condition. I don’t want to make 4 alert rules for each of these conditions and make the task more process heavy.

To summarize, I am asking if it is possible to have multiple alert conditions active within one alert rule. If there is another way of doing what I have explained, I am open to suggestions as well.

Thank you in advance!

No, it’s not possible to have multiple conditions. I think you can achieve this with some template magic. As far as I understand the end result is a notification that mentions the state of the system.

You can create an annotation System state and it’s value a template following docs Annotation and label template reference | Grafana documentation

for example

{{ $value := $values.B.Value }}
{{if eq $value 0.0}}
    Shutdown
{{else if eq $value 1.0}}
    Debugging
{{else if eq $value 2.0}}
    Update in Process
{{else if eq $value 3.0}}
    Normal
{{else if eq $value 4.0}}
    Error
{{else}}
    Unknown
{{end}}
1 Like

Thank you. This was a good start point for the solution.