I’m currently implementing a new Icinga2 installation and am now using Grafana on top of InfluxDB to show the graphs (replacing the outdated PNP4Naigos and Nagiosgraph). So far everything works. The dashboard is based on the Icinga2 template (https://grafana.com/dashboards/381).
I went one step further and wanted to add a custom template variable to dynamically Enable/Disable threshold viewing. I figured I add another custom variable (in “Templating”), naming the variable $thresholds and give two choices as values: “No,Yes”.
The variable selection shows up as I needed it to on top of the dashboard.
A threshold query (e.g. warning) in the metrics of a graph looks like this:
SELECT mean("warn") FROM "nrpe_check_load" WHERE ("metric" = 'load1' AND "hostname" =~ /^$hostname$/) AND $timeFilter GROUP BY time($interval) fill(null)
Now I want to use the $thresholds variable in this query. To be precise: I only want the query to be true (executed) when the $thresholds value is set to “Yes”.
I tried it this way:
SELECT mean("warn") FROM "nrpe_check_load" WHERE ("metric" = 'load1' AND "hostname" =~ /^$hostname$/) AND $thresholds = "Yes" AND $timeFilter GROUP BY time($interval) fill(null)
But without success. Is it even possible to use a variable as a field? Or maybe there’s a different approach to achieve this?
I went through the documentation but couldn’t find examples using variables in the query not being used as values (unless I missed it).
Thx in advance for any suggestions.