How to access variable, passed through URL in grafana?
Asked Answered
A

3

5

I am trying to make a detailed dashboard in grafana that opens on click. I do it by passing a variable to the dashboard debending on the clicked facility. When the dashboard opens it needs to display value using the passed url variable inst. I just cannot seem to get it working. Here is an example of my dashboard link.

enter image description here

How can i use the variable inst?

Aconite answered 5/11, 2018 at 12:58 Comment(0)
A
3

I figured out the solution on my own. The variable that i wanted to pass was var-inst, the trick to use it is to create a custom template variable named inst and give it a dummy value. After that is done i can use the passed value by using $inst. Note that in order for the variable to be passed i had to go back to my primary dashboard and then i had to click my link again. After that the value got passed and is working perfectly.

Aconite answered 7/11, 2018 at 14:56 Comment(3)
Hi. I tried what you described here, but i cant get it to work. The dummy value is not replaced by the value in the url. When you pass the url value, is your variable var-inst or just inst (since you seem to be referencing $inst later) ?Ontine
Are you able to use those variables inside query region?Tyus
has to be prefixed with var- in my case.Canopy
A
10

I will add gogibogi4's correct answer. The Grafana documentation is lacking on this.
In your drill-down dashboard, add a constant variable. To be retrieved in Grafana, you need the prefix var- then the name of the variable in the query string. Let's assume the variable is "region." The URL coming into the drilldown dashboard should look similar to the following:

/drilldowndashboard/?var-region=NorthWest

Drilldown Dashboard Settings: In the drilldown dashboard settings, create a variable. The Name in this example is "region" Make the type Constant. Under Hide, you can just leave that unselected. Under Constant options, you can write the word "blank" The preview of values will just show the word "blank" but go ahead and save it as it will be replaced in the query.

Query: You can refer to the variable using [[region]] in your data query.

Parent Dashboard: The parent dashboard merely needs to refer to the drilldown dashboard with var-region as a query parameter.

Argumentum answered 25/11, 2020 at 11:37 Comment(2)
Why is something like this not documented? Could not find anything by googlingInaccessible
I found this through googling xD I just want to add the url variable needs ot be prefixed with var-. Then you can refer to it's value with $ prefix in the query.Canopy
A
3

I figured out the solution on my own. The variable that i wanted to pass was var-inst, the trick to use it is to create a custom template variable named inst and give it a dummy value. After that is done i can use the passed value by using $inst. Note that in order for the variable to be passed i had to go back to my primary dashboard and then i had to click my link again. After that the value got passed and is working perfectly.

Aconite answered 7/11, 2018 at 14:56 Comment(3)
Hi. I tried what you described here, but i cant get it to work. The dummy value is not replaced by the value in the url. When you pass the url value, is your variable var-inst or just inst (since you seem to be referencing $inst later) ?Ontine
Are you able to use those variables inside query region?Tyus
has to be prefixed with var- in my case.Canopy
C
0

just referred above answer by gogibogi4 and it worked for me but when I tried to see variable information then I saw I have selected constant as a type but automatically it got converted into datasource and type is selected grafana. when I try to select them manually it didn't worked. this is some kind of bug of grafana I guess.

Cresa answered 28/11, 2022 at 4:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.