"Template variables are not supported in alert queries" while setting up Alert

Hello,

I am trying to setup a Grafana Alert. My DS is Prometheus and I can see my graphs correctly.

I have 3 queries running and I want to setup an Alert when the max() value goes above a threshold. When trying to Test Rule, I get the ERROR “Template variables are not supported in alert queries”

I am trying to understand what is the issue behind this.

It’s what the error says, template variables are not supported in alerting queries. You need to remove the template variable from your alert query

2 Likes

There is a long discussion on why alerting with template variable is difficult and maybe not what people actually want:

Globbing or regex in your query is an alternative: https://github.com/grafana/grafana/issues/6557#issuecomment-324338023

1 Like

I meet this problem too.
I have a main-table-panel, and when i click the item in this table, it will jump into child dashboard, with url “var-item_name=value”. Then, i can not set alert in child dashboard. Because i use variable in my dashboard.
What is the best best practice to achieve this goal?

Do you want to create an alert for one server (10.0.0.14) or for all servers in the template variable dropdown?

1 Like

@daniellee That’s a great question. I’ll take whatever is currently possible.
I have a dashboard with a variable, and I want that dashboard to generate an alert.

I get an error that alerts are not supported once you have a variable.

Must I have a dashboard without a variable to have alerts?

1 Like

yes it’s not error,but if template not supported,just tell us before we use alert,or remove templete from grafana,a misleading function

What I did was simply duplicate the query and remove all template vars (i.e. $somevar) from it, disable the query on the “eye” icon and use it for alerting only.

1 Like

Any news on this? At least support CONSTANTS, that should be easy to do…

3 Likes

Template variables just need a flag to be able to say “The alarm for this variable is not important”, i.e. because the variable is set up to show additional informational series, or filter by sections of data that wouldn’t matter for an alarm, but does matter for the user (i.e. show the CPU usage while a specific analytics process was running, but I still want an alarm on my CPU usage, from the same chart - it’s not friendly to say "well I can give you a big picture of everything on this chart, but then you need to see the same data again on a different chart to be able to see the alarms on it), and for drill-downs etc… then, currently, if ALL template variables are not important for an alarm, the alarm can be enabled (until we then figure out later how to then split alarms by specific Template variables).

I am still waiting for support for just constants!

In my company we launch several environments every day, each with its own dashboard, I can’t even express how wonderful it would be to be able to use variables in alarms (what we need most), thresholds, and gauges.

With constant variables it would be enough to automate almost the entire process.

There should be more information about this. I also new user and try to learn grafana. Shuld not be so hard to create a alert.

Got this problem too, I think it will be good if alerting system check “Include All option” and if it set - use “custom all value”:
image

If “Include All option” not set - then show error.

Or even you can introduce default value in template.

Supporting for constant is important and required. Grafana needs this function indeed.