Skip to content
Snippets Groups Projects
Commit be46d7cc authored by Felix Sperling's avatar Felix Sperling
Browse files

add compatibility for older grafana versions

parent b61baae5
No related branches found
No related tags found
No related merge requests found
......@@ -132,8 +132,13 @@ def delete_snapshot(key, grafana_url, http_post_headers):
return int(r.status_code)
def delete_dashboard(board_uri, grafana_url, http_post_headers):
r = requests.delete('{0}/api/dashboards/uid/{1}'.format(grafana_url, board_uri), headers=http_post_headers)
def delete_dashboard_by_uid(uid, grafana_url, http_post_headers):
r = requests.delete('{0}/api/dashboards/uid/{1}'.format(grafana_url, uid), headers=http_post_headers)
return int(r.status_code)
def delete_dashboard_by_slug(slug, grafana_url, http_post_headers):
r = requests.delete('{0}/api/dashboards/db/{1}'.format(grafana_url, slug), headers=http_post_headers)
return int(r.status_code)
......@@ -168,8 +173,15 @@ def create_datasource(payload, grafana_url, http_post_headers, verify_ssl, clien
client_cert, debug)
def delete_datasource(uid, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
r = requests.delete('{0}/api/datasources/uid/{1}'.format(grafana_url, uid), headers=http_post_headers)
def delete_datasource_by_uid(uid, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
url = '{0}/api/datasources/uid/{1}'.format(grafana_url, uid)
r = requests.delete(url, headers=http_post_headers)
return int(r.status_code)
def delete_datasource_by_id(id_, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
url = '{0}/api/datasources/{1}'.format(grafana_url, id_)
r = requests.delete(url, headers=http_post_headers)
return int(r.status_code)
......
from grafana_backup.dashboardApi import search_dashboard, delete_dashboard
from grafana_backup.dashboardApi import search_dashboard, delete_dashboard_by_uid, delete_dashboard_by_slug
from grafana_backup.commons import to_python2_and_3_compatible_string, print_horizontal_line
......@@ -40,7 +40,11 @@ def get_all_dashboards_in_grafana(page, limit, grafana_url, http_get_headers, ve
def get_individual_dashboard_and_delete(dashboards, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, uid_support):
if dashboards:
for board in dashboards:
status = delete_dashboard(board['uid'], grafana_url, http_get_headers)
if uid_support:
status = delete_dashboard_by_uid(board['uid'], grafana_url, http_get_headers)
else:
status = delete_dashboard_by_slug(board['slug'], grafana_url, http_get_headers)
if status == 200:
print("deleted dashboard {0}".format(board['title']))
else:
......
from grafana_backup.dashboardApi import search_datasource, delete_datasource
from grafana_backup.dashboardApi import search_datasource, delete_datasource_by_uid, delete_datasource_by_id
from grafana_backup.commons import print_horizontal_line
def main(args, settings):
grafana_url = settings.get('GRAFANA_URL')
http_get_headers = settings.get('HTTP_POST_HEADERS')
debug = settings.get('DEBUG')
verify_ssl = settings.get('VERIFY_SSL')
grafana_url = settings.get('GRAFANA_URL')
client_cert = settings.get('CLIENT_CERT')
debug = settings.get('DEBUG')
uid_support = settings.get('UID_SUPPORT')
pretty_print = settings.get('PRETTY_PRINT')
http_get_headers = settings.get('HTTP_POST_HEADERS')
get_all_datasources_and_delete(grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print)
get_all_datasources_and_delete(grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, uid_support)
print_horizontal_line()
def get_all_datasources_and_delete(grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print):
def get_all_datasources_and_delete(grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, uid_support):
status_code_and_content = search_datasource(grafana_url, http_get_headers, verify_ssl, client_cert, debug)
if status_code_and_content[0] == 200:
datasources = status_code_and_content[1]
print("There are {0} datasources:".format(len(datasources)))
for datasource in datasources:
print(datasource)
status = delete_datasource(datasource['uid'], grafana_url, http_get_headers, verify_ssl, client_cert, debug)
if uid_support:
status = delete_datasource_by_uid(datasource['uid'], grafana_url, http_get_headers, verify_ssl, client_cert, debug)
else:
status = delete_datasource_by_id(datasource['id'], grafana_url, http_get_headers, verify_ssl, client_cert, debug)
if status == 200:
print("datasource:{0} is deleted".format(datasource['name']))
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment