Skip to content
Snippets Groups Projects
Commit cf8db3d5 authored by Mikel's avatar Mikel
Browse files

Fix PEP8 E302 - Expected 2 blank lines between functions and classes

parent a24719b1
No related branches found
No related tags found
No related merge requests found
......@@ -5,17 +5,20 @@ def left_ver_newer_than_right_ver(current_version, specefic_version):
return int(''.join(ver.split("-")[0].split(".")))
return convertVersion(current_version) > convertVersion(specefic_version)
def print_horizontal_line():
print('')
print("########################################")
print('')
def log_response(resp):
status_code = resp.status_code
print("[DEBUG] status: {0}".format(status_code))
print("[DEBUG] body: {0}".format(resp.json()))
return resp
def to_python2_and_3_compatible_string(some_string):
if sys.version_info[0] > 2:
return some_string
......
......@@ -22,54 +22,65 @@ def import_grafana_settings(settings_file_name):
return settings_dict
def health_check():
url = GRAFANA_URL + '/api/health'
print("grafana health: {0}".format(url))
return send_grafana_get(url)
def search_dashboard(page, limit):
url = GRAFANA_URL + '/api/search/?type=dash-db&limit={0}&page={1}'.format(limit, page)
print("search dashboard in grafana: {0}".format(url))
return send_grafana_get(url)
def get_dashboard(board_uri):
url = GRAFANA_URL + "/api/dashboards/{0}".format(board_uri)
print("query dashboard uri: {0}".format(url))
(status_code, content) = send_grafana_get(url)
return (status_code, content)
def search_alert_channels():
url = GRAFANA_URL + '/api/alert-notifications'
print("search alert channels in grafana: {0}".format(url))
return send_grafana_get(url)
def create_alert_channel(payload):
return send_grafana_post(GRAFANA_URL + '/api/alert-notifications', payload)
def delete_dashboard(board_uri):
r = requests.delete(GRAFANA_URL + "/api/dashboards/db/{0}".format(board_uri), headers=HTTP_POST_HEADERS)
return int(status_code)
def create_dashboard(payload):
return send_grafana_post(GRAFANA_URL + '/api/dashboards/db', payload)
def search_datasource():
print("search datasources in grafana:")
return send_grafana_get(GRAFANA_URL + '/api/datasources')
def create_datasource(payload):
return send_grafana_post(GRAFANA_URL + '/api/datasources', payload)
def search_folders():
print("search folder in grafana:")
return send_grafana_get(GRAFANA_URL + '/api/search/?type=dash-folder')
def get_folder(uid):
(status_code, content) = send_grafana_get(GRAFANA_URL + "/api/folders/{0}".format(uid))
print("query folder:{0}, status:{1}".format(uid, status_code))
return (status_code, content)
def get_folder_id_from_old_folder_url(folder_url):
if folder_url != "":
# Get folder uid
......@@ -84,15 +95,18 @@ def get_folder_id_from_old_folder_url(folder_url):
return folder_data['id']
return 0
def create_folder(payload):
return send_grafana_post(GRAFANA_URL + '/api/folders', payload)
def send_grafana_get(url):
r = requests.get(url, headers=HTTP_GET_HEADERS, verify=VERIFY_SSL)
if DEBUG:
log_response(r)
return (r.status_code, r.json())
def send_grafana_post(url, json_payload):
r = requests.post(url, headers=HTTP_POST_HEADERS, data=json_payload, verify=VERIFY_SSL)
if DEBUG:
......
......@@ -13,6 +13,7 @@ folder_path = args.path
import_grafana_settings(args.conf_filename)
log_file = 'alert_channels_{0}.txt'.format(datetime.today().strftime('%Y%m%d%H%M'))
def get_all_alert_channels_in_grafana():
(status, content) = search_alert_channels()
if status == 200:
......@@ -24,13 +25,15 @@ def get_all_alert_channels_in_grafana():
else:
print("query alert channels failed, status: {0}, msg: {1}".format(status, content))
return []
def save_alert_channel(channel_name, file_name, alert_channel_setting):
file_path = folder_path + '/' + str(file_name) + '.alert_channel'
with open(file_path, 'w') as f:
f.write(json.dumps(alert_channel_setting))
print("alert_channel:{0} is saved to {1}".format(channel_name, file_path))
def get_individual_alert_channel_and_save(channels):
file_path = folder_path + '/' + log_file
if channels:
......
......@@ -14,6 +14,7 @@ settings_dict = import_grafana_settings(args.conf_filename)
globals().update(settings_dict) # To be able to use the settings here, we need to update the globals of this module
log_file = 'dashboards_{0}.txt'.format(datetime.today().strftime('%Y%m%d%H%M'))
def get_all_dashboards_in_grafana(page, limit=SEARCH_API_LIMIT):
(status, content) = search_dashboard(page, limit)
if status == 200:
......@@ -26,6 +27,7 @@ def get_all_dashboards_in_grafana(page, limit=SEARCH_API_LIMIT):
print("get dashboards failed, status: {0}, msg: {1}".format(status, content))
return []
def save_dashboard_setting(dashboard_name, file_name, dashboard_settings):
file_path = folder_path + '/' + file_name + '.dashboard'
print(dashboard_settings)
......@@ -48,6 +50,7 @@ def get_individual_dashboard_setting_and_save(dashboards):
)
f.write('{0}\t{1}\n'.format(board['uid'], to_python2_and_3_compatible_string(board['title'])))
def save_dashboards_above_Ver6_2():
limit = 5000 # limit is 5000 above V6.2+
current_page = 1
......@@ -60,7 +63,8 @@ def save_dashboards_above_Ver6_2():
current_page += 1
get_individual_dashboard_setting_and_save(dashboards)
print_horizontal_line()
def save_dashboards():
dashboards = get_all_dashboards_in_grafana(1)
print_horizontal_line()
......
......@@ -20,7 +20,6 @@ def save_datasource(file_name, datasource_setting):
f.write(json.dumps(datasource_setting))
print("datasource:{0} is saved to {1}".format(file_name, file_path))
def get_all_datasources_and_save():
status_code_and_content = search_datasource()
if status_code_and_content[0] == 200:
......
......@@ -13,6 +13,7 @@ folder_path = args.path
import_grafana_settings(args.conf_filename)
log_file = 'folders_{0}.txt'.format(datetime.today().strftime('%Y%m%d%H%M'))
def get_all_folders_in_grafana():
status_and_content_of_all_folders = search_folders()
status = status_and_content_of_all_folders[0]
......
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