Dynamic dashboard Query variable label

Hi!

I have a dashboard query variable that queries an elasticsearch datasource for a field value - it’s a hostname, to be specific.

I’m using this hostname as a parameter to Text panel that shows netdata dashboards, which I then set to repeat across all values of the variable. IKR?! So cool. :sunglasses:

The documents that the hostnames come from also store a friendly name for each host, so I can get a list of friendly names. I want to have the associated friendly name as the title of each relevant panel.

It’d be great if a variable could actually be a Tuple, where one part is the value and the other the label.
Is this even possible?

Yes, I think what you want is possible. Will depend on how you actually query the labels you want to use. See if Filter variables with regex | Grafana Labs maybe works for you?

Ok, cool! So at the moment my query looks something like this:

{"find" : "terms" , "field" : "node.public_hostname"}

I suppose I need to bring back multiple fields…?
eg:

{"find" : "terms" , "fields" : ["node.public_hostname", "node.name"]}

or similar?

Not sure how to do this.

I tried creating another variable that hung off the first one, like so:

{"find" : "terms" , "field" : "node.name", "query": "node.public_hostname:$Nodes"}

Which works for the first panel, but doesn’t repeat correctly - subsequent panels just show the first one back:

The only way I can see it working so far is to concatenate both values into a single field and then split it out using regex. Is that right?

I created a new field with the node.public_hostname and node.name concatenated. I then set a regex on the Variable that targeted this field to be:

/(?<text>.*):(?<value>.*)/

and I set the panel title as: ${Nodes.__text} but when I select multiple items it just concatenates all the selected variables in all the panel titles rather than repeating the panel and each title having its own correct value. :frowning:

1 Like

Ok, I think something had cached in my dashboard from last time. I changed the panel title back to ${Nodes} and it all worked as it should.

1 Like

Cool, glad you got it! And it’s great that you’ve shared your approach so that others in the same boat can hopefully pick it up too. I unfortunately have zero experience with elasticsearch, so would not have been able to contribute anything very meaningful here apart from point you to the regex :).

FWIW, with some other query languages (SQL, GraphQL) there are actually ways to select the “text” and “value” fields separately, without needing to use regex to split a single set of query results. But again, not sure how that plays out with ES.