Templating regex exclude not working

templating

#1

I tried to exclude some hostname from the templating output.

Template query to get the hostname from InfluxDB,
SHOW TAG VALUES FROM system WITH KEY=host

As SHOW TAG VALUES doesn’t support time in WHERE clause, I tried to exclude some down hosts using template regex option.

Can you help me , how to exclude below hosts on templating regex option

ansys001.example.local
net001.example.local

Regex tried : /^(?!ansys.example.local$).*$/


#2

You can use regex in the influxdb query as well to filter, or the regex option in grafana.

Not sure what the regex should look like.


#3

Negative lookaheads are hard. Have you tried use the !~ operator (negative regex) in the the WHERE clause instead?

Something like: WHERE host !~ /^ansys*.example.local$/


#4

I was just tackling this issue today.

My dashboard template variable is for a customer list from InfluxDB data source. The initial query looks like:
SHOW TAG VALUES FROM "series_name" WITH KEY = "customer"

Of course, I don’t want to look at any of my internal, test, or demo accounts, so I needed to use the regex to exclude those. I’m using the negative lookahead as daniellee mentioned, but since this is in the templating section and not the metrics, it’s a little different. My regex line has:
/^(?!abc|.*demo|.*test)/

This is working for me at this time. I hope it helps you out.