How to set a proper severity level using the dynamic label

Hi,

I know it’s a stupid question since I read a few people have been discussed this topic before (e.g. here: One Alert rule with severity/thresholds: warn, critical etc)

But when I tried to execute on my own Grafana 10, unfortunately I have no luck.

I set the CPU threshold to > 80% and set the label of the severity like this:

{{if gt $values.B.Value 80.0}}Warning{{else if gt $values.B.Value 90.0}}Critical{{else}}Info{{end}}

When the alert fires because it breaks the minimum threshold (>80), it sends the proper severity level which is a Warning. But somehow when the value of the query is >90, the alerts couldn’t send a proper severity level which is Critical. Am I missing something here?

Here I attached the detail of the alert rule below

@mjacobson Can you help with this one?

Hi @fajrinfa, the issue here is likely the order of the conditionals. With the template as you have it defined, it will check that the value is above 80 first and only if that isn’t true will it check if it’s above 90. If you swap the order it should do what you want:

{{if gt $values.B.Value 90.0}}Critical{{else if gt $values.B.Value 80.0}}Warning{{else}}Info{{end}}

Hope that helps!

2 Likes

Thanks for your response @mjacobson!

I switched the order and it works as my expectation. Thanks for your assistance :slightly_smiling_face: