Dashboard import with datasource variable

Version=4.6.1

Is it still expected that we can import a dashboard with datasource variables which reference a datasource defined globally in the ‘inputs’ array ref? Example JSON

{
  'dashboard' => {
     foo
  },
  'inputs' => [
    {
      'name' => 'DS_PROMETHEUS',
      'pluginId' => 'prometheus',
      'type' => 'datasource',
      'value' => 'myDS'
    }
  ],
  'message' => 'my message'
}

With panels referencing the datasource with:
‘datasource’ => ‘${DS_PROMETHEUS}’

My import is successful but none of the templates or panels have translated ${DS_PROMETHEUS}.

What am I missing?

Hi,

Per default when you export a dashboard, the selected data source will not be included, but the type of data source will be. Then when you import the dashboard you’ll be prompted to select a data source of that type. And it sounds that you’ve done this and it works as expected.

Now talking about data sources as template variables, you usually have a drop down where you select the data source you want to use.

Do you have the template variable DS_PROMETHEUS visible as a drop down in the dashboard? You may need to go into dashboard cog wheel → templating → DS_PROMETHEUS and update the variable. Maybe easier to assist you if you include a screenshot of your dashboard/data source template variable and/or the complete dashboard json.

Marcus

I am not using templating for the datasource selection. This grafana instance has multiple datasources configured but my script knows which one is correct. I am trying to set this at the top level of the json in the “inputs” array of hashes. Problem is when I reference back to it it doesn’t seem to work.

I’m still not quite sure what you mean.

Are you using the import page in Grafana UI when you import or how do you import your dashboard?

Found this documentation, but they’re using __inputs, nut inputs.

Could you please include the dashboard json you’re trying to import here so that I can try it out?

Marcus

I am using the API to import. The JSON was exported from the UI and than I modified a few items in the JSON to remove specific references since it will be loaded into multiple grafana instances. The JSON from my original message is accurate. Full JSON exceeds char limit for this forum.

Are you using this endpoint when you import?

Please refer to Which endpoint to use to import dashboard?

endpoint is api/dashboards/db (POST)

Like I said it is successfully imported just the datasources are not correct in each panel. I am also setting id=null.

{
  "dashboard" : {
    "id" : null
  }
}

thx for help talking through this

Your asking “Is it still expected that we can import a dashboard with datasource variables which reference a datasource defined globally in the ‘inputs’ array ref?”

Do you imply that this has worked in earlier versions? I haven’t heard of it earlier.

I am drawing a blank if/when last time I used this API format. I updated my end to just put the actual datasource into the JSON before import and no longer reference a global variable. Works fine. Thanks again

1 Like