"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.

2 Likes

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

4 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!

1 Like

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.

1 Like

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.

1 Like

Hi there,

I have a repeating dashboard set up, based on tags (variable). I want to set up alerts for each repeated panel (which is monitoring a different service based on the tags). However, I am reading that we can’t use the variable in the alert rules.

I have hundreds of services (each service has a unique tag,) and to manually create all those panels just so each can have an alert rule set up seems like a major usability issue. If you can use “tags” as a variable for repeating panels, you should be able to use the same variables for the alerts, right? Or is there some other way I should approach this?

To clarify further, I have:

  1. A dashboard setup with multiple variables (query, tag,) which can be used to select All, multiple, or a single “service” (a tag).
  2. On this dashboard, there is a single repeating horizontal row (one row per tag). This iterates through all the service tags, and creates a row for each.
  3. I want to have an alert for each repeated graph in each repeated row, but when I use the service tag variable in the alert query it returns an empty set / null.

How else can I do this? The “repeat” feature is really useful, but it looks like the variables don’t carry over to alerting.

2 Likes

i need the same requires

1 Like

While setting up alert getting this error

1 Like

This is currently not possible. There is already a feature request for this in github.

How did you achieve this?
I have the same requirement. I have a table of devices in rows with links. on click of a device I have another dashboard where the monitoring is specific to the device selected. Now I want to set alert on the child dashboard