How to copy dashboard to other organisations in Grafana

痞子三分冷 提交于 2021-01-05 09:29:07

问题


I'm using Grafana to show some data. I have 20 organisations and they all use the same dashboards (Dash1, Dash2, Dash3). Thus I can use the same json data for all dashboards in all organisations.

But I do not want to update it manually every time when I change something, thus I'm trying to create a python script which will do it for me.

I run the script as follows:

python update_dashboards.py Dash1

The python code is as follows:

try:
    dashboard_name = sys.argv[1]
    response = settings.get_request_with_token(settings.api_url + "search?query=" + dashboard_name) 
    dashboard = json.loads(response)
    if len(dashboard) < 1:
        print("There is no dashboard data.")
    else:
        dashboard_data = dashboard[0]
        dashboard_uri = str(dashboard_data["uri"])
        dashboard_data = dashboard_api.get_dashboard(dashboard_uri)
        // Here I get dashboard details

except IndexError:
    print("Please provide dashboard name!")

Thus I give the name of the dashboard that I want to copy to all organisations.

With my code I get successfully the dashboard that I want to copy.

My question is how can I now use this dashboard to copy it to all other organizations?


回答1:


I'd think to use the API to create new dashboards. You can use requests and create a payload with what you already have in your script. You also need a key to use the API.

payload = {"authorization": "yourkey", "content": thedashboard} 
url = yougrafanaaddress/api/dashboards/db
r = requests.post(url, data=payload)


来源:https://stackoverflow.com/questions/49275920/how-to-copy-dashboard-to-other-organisations-in-grafana

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!