Skip to content
Snippets Groups Projects
Commit b02937d8 authored by Aaron Johnson's avatar Aaron Johnson
Browse files

only use uid for dashboard when version 5.0.0 or newer

parent 5cbbb1d5
No related branches found
No related tags found
No related merge requests found
......@@ -24,9 +24,9 @@ def main(args, settings):
is_api_support_page_param = left_ver_newer_than_right_ver(api_version, "6.2.0")
if is_api_support_page_param:
save_dashboards_above_Ver6_2(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print)
save_dashboards_above_Ver6_2(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version)
else:
save_dashboards(folder_path, log_file, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print)
save_dashboards(folder_path, log_file, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version)
def get_all_dashboards_in_grafana(page, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug):
......@@ -52,12 +52,16 @@ def save_dashboard_setting(dashboard_name, file_name, dashboard_settings, folder
print("dashboard: {0} -> saved to: {1}".format(dashboard_name, file_path))
def get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print):
def get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version):
file_path = folder_path + '/' + log_file
if dashboards:
with open(u"{0}".format(file_path), 'w') as f:
for board in dashboards:
board_uri = "uid/{0}".format(board['uid'])
if left_ver_newer_than_right_ver(api_version, "4.6.3"):
board_uri = "uid/{0}".format(board['uid'])
else:
board_uri = board['uri']
(status, content) = get_dashboard(board_uri, grafana_url, http_get_headers, verify_ssl, client_cert, debug)
if status == 200:
save_dashboard_setting(
......@@ -70,7 +74,7 @@ def get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file,
f.write('{0}\t{1}\n'.format(board['uid'], to_python2_and_3_compatible_string(board['title'])))
def save_dashboards_above_Ver6_2(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print):
def save_dashboards_above_Ver6_2(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version):
limit = 5000 # limit is 5000 above V6.2+
current_page = 1
while True:
......@@ -80,13 +84,13 @@ def save_dashboards_above_Ver6_2(folder_path, log_file, grafana_url, http_get_he
break
else:
current_page += 1
get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print)
get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version)
print_horizontal_line()
def save_dashboards(folder_path, log_file, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print):
def save_dashboards(folder_path, log_file, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version):
current_page = 1
dashboards = get_all_dashboards_in_grafana(current_page, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug)
print_horizontal_line()
get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print)
get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version)
print_horizontal_line()
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