Dynamic datasource for Grafana

I am trying to upgrade from Grafana 1.9.0 (precise) to Grafana 2.6.0 (xenial). I noticed that the config.js file is now deprecated, per this. My old config file would run a JavaScript function, which would take the domain from the requesting URI, that would catenate a domain to one of the hostnames of a datasource. I noticed that there is no longer a static file for datasources, per this discussion. How would I replicate the same functionality?

I currently have a black screen and a typeerror.

app.ca0ab6f9.js:11 TypeError: Cannot read property ‘version’ of undefined
at new (app.ca0ab6f9.js:27)
at e (app.ca0ab6f9.js:9)
at Object.f [as instantiate] (app.ca0ab6f9.js:9)
at Object. (app.ca0ab6f9.js:9)
at Object.e [as invoke] (app.ca0ab6f9.js:9)
at Object.$get (app.ca0ab6f9.js:9)
at Object.e [as invoke] (app.ca0ab6f9.js:9)
at app.ca0ab6f9.js:9
at d (app.ca0ab6f9.js:9)
at Object.e [as invoke] (app.ca0ab6f9.js:9)

If using a config file, does not work for you then using Enviromental Variables is a way to dynamically set config values.

For the data source creation, then I would recommend using the HTTP API. Here is an example using curl:

curl -X POST -H "Authorization: Bearer yourtoken" -H "Content-Type: application/json" -d '{
}' http://grafana.staged-by-discourse.com/api/datasources

Can you explain a bit more about the process of creating data sources dynamically? Do you need to do that when you start Grafana or when a user logs on?

I have an instance of Grafana and an instance of graphite (datasource) in a private subnet. I created a haproxy instance to allow viewers to see the content. So I have an internal grafana, URL: grafana.companyname.com, and internal datasource, URL: graphite.companyname.com, that is viewable when I am on my VPN because my datasource will have the correct domain.

To accommodate for the external viewers, the haproxy instance would proxy connections for URL: grafana.outsidecompany.com to our internal grafana instance and URL: graphite.outsidecompany.com. I added a javascript function to grab the domain from the requesting URI and append it to the graphite datasource, so that data can be shown whether I am on my VPN or not on it.

So my function would append either “.companyname.com” or “.outsidecompany.com” to my URL for the graphite datasource. I am trying to replicate this functionality again.