I have been experimenting with Grafana scripted dashboards using the example scripted.js and have managed to create a script that takes a device name from a URL argument, queries graphite for the list of available metrics, and generates a dashboard for that device. It works well. Now I want to automate calls to my modified scripted.js so I can programmatically build many dashboards and store the resulting JSON for each one in individual files in /opt/grafana/public/dashboards/static which will the show up in the search list because I configured the following in my grafana ini file:
[dashboards.json] enabled = true path = /opt/grafana/public/dashboards/static
I have managed to do this manually using the Gear Menu -> View JSON -> Save As, copy the file to the static dir, etc., and it works well.
The problem that I have run into is that I cannot figure out how to automate calls to the scripted.js program. If I do something like this…
curl GET "http://grafana/dashboard/script/myscrtiped.js?device=m2g.myrouter.*"
How can I make a call to myscripted.js and get the “Gear Menu -> View JSON” output?
Do I need to do use node.js to talk to http://grafana/dashboard/script/myscrtiped.js?device=m2g.myrouter.* and scrape the resulting dashboard JSON?
It feels like I’m making this much more difficult than it should be.
I found this old issue post…
…where Torkelo talks about some dasboardSrv and datasourceSrv services and also references an example called scripted_gen_and_save.js. I was able to locate the scripted_gen_and_save.js example but executing it under the current version of Grafana generates the following error:
TypeError: services.datasourceSrv.getGrafanaDB is not a function
I’m not sure if scripted_gen_and_save.js would have done what I wanted, I suspect it would have saved the JSON dashboard into the Grafana sqlite database whereas what I want to do is just take the dashboard JSON, save it in a file, and put it in the directory specified by the [dashboards.json] config section I mentioned above.
Thank you for your time and awesome software.