Daniel Chepenko
Daniel Chepenko

Reputation: 2268

Grafana: Template variables are not supported in alert queries

Hi I want to create a simple alert in grafana to check whether there is no data for the last 5 minutes.

But I get an error

Template variables are not supported in alert queries

Well, according to this issue templates are not supporting in grafana yet. I have two questions:

  1. What is templating?

  2. How can I avoid this error?

enter image description here

Upvotes: 31

Views: 60637

Answers (4)

ruhong
ruhong

Reputation: 1903

Under the Metrics tab, add new metric that will be hidden in the chart and is used for alerting only. Duplicate the query and remove all template variables (i.e. $somevar) from it. Replace the template variable with a hard-coded value you want to create alert for. Hide the metric by clicking on the “eye” icon.

Source: https://community.grafana.com/t/template-variables-are-not-supported-in-alert-queries-while-setting-up-alert/2514/8

Upvotes: 29

Marcel Zebrowski
Marcel Zebrowski

Reputation: 1007

It means that you have to use hard coded variables inside your queries.

This is bad:

where host =~ /^$host$/

This is good:

where host =~ mymachine.com

Your problem is located inside you metrics.

Upvotes: 7

didlich
didlich

Reputation: 119

regarding your screenshot, you are using the condition

WHEN last() of query(A,5m,now) HAS NO VALUE

so the part with

query(A,5m,now)

is reusing the query from "Metrics" tab, and if you are using a variable inside this query then the alert is reporting this error

look at this simple query:

up{job="node_exporter", instance="$instance"}

here I want to use as instance the user selected VM name from drop-down menu, which is represented by the variable $instance

if I create an alert on this query, then I will get the error Template variables are not supported in alert queries

Upvotes: 8

Bilal Ali Jafri
Bilal Ali Jafri

Reputation: 986

Dont Use templating in Grafana while creatig alerts as it doesn't support templating in alerting.

Try to Hardcode the whole formula and then give a try.

In easy language dont use Drop Down or templating variable which you have defined in templating section on top

Templating are for dynamic dashboards when you dont want to use formula again and again. You can repeat the graphs of each value selected in variable of templating

Upvotes: 10

Related Questions