0

I presume Im doing something wrong because every time I run my api script from the backend, it says "success" but when i go to the grafana UI, the dashboard I just created is no where to be found.

here's the full script:

#!/usr/bin/env python

import requests,sys,json

url = "http://admin:admin@10.10.10.10:3000/api/dashboards/home"
headers = {
    'Authorization': 'Bearer eyJrIjoiazJblahblahMiLCJuIjoiYXBpa2V5Y3VybCIsImlkIjoyf',
    'Content-Type': 'application/json',
}
creategrdb = '''{
    "dashboard": {
        "id": null,
        "title": "API Test Dashboard 3",
        "originalTitle": "API Test Dashboard 3",
        "timezone": "browser",
        "rows": [
            {
                "collapse": false,
                "editable": true,
                "height": "250px",
                "panels": [],
                "title": "Row"
            }
        ],
        "schemaVersion": 6,
        "version": 0
    }
}'''
response = requests.post('http://10.10.10.10:3000/api/dashboards/db', headers=headers, data=creategrdb, verify=True)
print (response.text)

When I run this script, I get this:

{"id":17,"slug":"api-test-dashboard-3","status":"success","uid":"wtKFBr6ik","url":"/d/wtKFBr6ik/api-test-dashboard-3","version":1}

Which indicates success.

But when I go to the grafana UI to make sure the dashboard was created, I see nothing.

When I run the script again, it aborts with this:

{"message":"A dashboard with the same name in the folder already exists","status":"name-exists"}

Indicating the dashboard IS created somewhere, but where that "somewhere" is, seems to be a mystery.

And the user im logging into the UI as, is "admin" who has all the superuser privileges. So i doubt its a problem of permissions.

any ideas?

Dev Ops
  • 127
  • 1
  • 10
  • Has it been created in the dashboard table of the db? Also set the logging to debug and see what that produces. – Phil Apr 09 '19 at 10:26

2 Answers2

3

Update (now better solved)

Make sure to set "org_id" within you individual dashboard definition to "1". That's it. That solved it for me.

Update I could "solve" the problem:

In my case, in the database, table dashboard I could see the dashboards that were not visible in the UI. I browsed through the columns to spot any differences and what I noticed was that the columns

  • created_by
  • updated_by
  • org_id

were set to -1, where "normal" dashboards had a positive value. Setting those values to 1 solved the issue for me. Steps:

  1. stop the grafana server
  2. Access the database manually (located at /var/lib/grafana/ under linux)
  3. Open a database client with root priviledges
  4. Edit the above-mentioned cells and write the changes to the database
  5. Exit the client and restart grafana

Hope this will resolve it to anyone reading this! Problem with this approach: You re-enable dashboards that are already there, but I only found a way to do this manually. I will see if I can prevent these cols being set to -1 in the first place and keep this here up to date should I make any progress.

Original Answer

Any updates on this? I get the exact same behaviour. I find the new dashboard in the database and am also able to verify it was registered because I can copy the uid from the success response and do a GET on it - which returns that supposedly but invisible dashboard. So it's definitely "there", but it does not show up in the UI and I can not load it via the url derived from its uid.

Adding datasources via endpoints works fine though

2

I encountered a variant on this one: the folder_id was set to -1, causing the same problem. The url was accessible (copied from the session where i imported the new dashboard) but the dashboard was not listed in new sessions. Changing this id to 1 (general folder) fixed the issue although I do not know why it happened. This was the first time I had this issue. enter image description here

tlips
  • 121
  • 1
  • 4