Updating variables automatically in grafana

  • What Grafana version and what operating system are you using?
    7.5.7

  • What are you trying to achieve?
    I want to automatically update a variable in a dashboard.
    e.g. I have variable with a list of sites, site1 site2…
    I have a dropdown that can select the various sites. But as sites are built/added to the system then I want this variable to be automatically be updated.
    Si if site3 was built the dropdown would then show site1, site2, and site3.

Currently we currently have bot in Slack that listens for “site list” and when someone types that a python sript goes and gets that from the back end and outputs the list. I am thinking something along these lines in grafana. can this be done?

  • How are you trying to achieve it?
    using grafana variables, but mabe I should use data source

  • What happened?
    na - looking at how to do it.

  • What did you expect to happen?
    na - looking at how to do it.

  • Can you copy/paste the configuration(s) that you are having problems with?
    na - looking at how to do it.

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    na - looking at how to do it.

  • Did you follow any online instructions? If so, what is the URL?

not really but below are some link on my initial investigation on this.

slack method for annotations which maybe related,

thinking a git approach might work, but won’t achieve full automation,

using variables in grafana

Hi @hatman,

Considering what you’re trying to do, have you considered using a JSON datasource?

how would i apply that to my example? tks

rereading your question, perhaps I’m not understanding you. If your query has a template variable that is making a db query and returning sites, then after you add a new site it should get represented in the next query, right?

So you want to have a slackbot that listens for site list in a Slack channel, and then calls the Grafana API and grabs a list of all sites, and then prints it in the channel?

Hi,
For the dashboard itself, you can set your variable to be refreshed on dashboard load or Time Range Change.
That would fulfill the automatic pickup of new sites (and the drop-down).
About the slack bot, I am not sure to understand why you want to go through Grafana rather than the initial datasource ?

I think that is the question how do I set your variable to be refreshed? My varible might have 2 sites but then there are now 5 sites. how do I get my variable to see this change? tks

re slack bot, that was just an example or analogy of what I wanted to try and do.