How can i use custom variables to chain

With reference to the above link, How can i achieve the following.
I have two variables say region and servers. How can i map regions to server.

region1: reg1-serv1, reg1-serv2
region2: reg2-serv1, reg2-serv2
region3: reg3-serv1, reg3-serv2

region: region1, region2, region3
servers // This variable is dependent on what region i select.

I was unable to achieve the same with custom variables. Also i was unable to chain custom variables.

Any help/example is appreciated.

1 Like

Hi subhdeep,

I ran into a similar issue recently. Chaining doesn’t appear to be supported with custom variables, but I was able to use variable key-value pairs in combination with Regex (I’m using InfluxDB) to get something approximating the required functionality. In your case, I’d define custom variables as
region1 : reg1-serv1|reg1-serv2, region2 : reg2-serv1|reg2-serv2, region3 : reg3-serv1|reg3-serv2
Notice the pipe | operators.

Although this will create only a single dropdown menu for “region” (and not another one for “servers” within that region), at least you’ll be able to inject the server names into queries.
With InfluxQL (assuming you’re querying measurements but it’ll work elsewhere; see here):
SELECT mean("value") FROM /^(${region:pipe})$/ WHERE $timeFilter GROUP BY time($__interval) fill(null)
Notice that I used the “pipe” option for variable formatting to properly join strings in case of multi-value selection, and ^( and )$ to ensure full string matches. Seems to work with single and multi-value selections.
Query inspector should give you something like this
"SELECT mean("value") FROM /^(reg1-serv1|reg1-serv2|reg2-serv1|reg2-serv2|reg3-serv1|reg3-serv2)$/ WHERE time >= now() - 30d and time <= now() GROUP BY time(30m) fill(null)"
when using “all” for “region”. Works similarly when using Flux.
You may need to adjust this to ensure compatibility with your data source.

Hope this helps!

2 Likes

Hey guys!

I’m running into the same issue. I have one variable var1 whose value should be the the key for two other variables var 2 and var 3.

var1 = hello then var2 = $var1 : “hi” , var3 = $var1 : “there”

I’m not sure if this is supported

@alexgovannytejada Any findings? did you found if it’s supported?

If it is just a static list of things then try CollectionLookup of infinity datasource

Thanks a lot. It’s Worked for me.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.