Skip to content
Snippets Groups Projects
Commit 16c2dd18 authored by Miles Hampson's avatar Miles Hampson
Browse files

Style and tooling issues

* Use the PEP 8 recommended whitespace formatting for .py files
* Add intellij files to the .gitignore file patterns
parent d68cf67b
No related branches found
No related tags found
No related merge requests found
*.pyc
.idea
\ No newline at end of file
......@@ -13,4 +13,3 @@ with open(file_path, 'r') as f:
datasource = json.loads(data)
print("create datasource: {0}".format(datasource['name']))
create_datasource(json.dumps(datasource))
import requests, json
from grafanaSettings import *
def search_dashboard():
print "search dashboard in grafana:"
r = send_grafana_get(grafana_url + '/api/search/')
return r.content
def get_dashboard(board_uri):
r = send_grafana_get(grafana_url + "/api/dashboards/{0}".format(board_uri))
status_code = r.status_code
content = r.content
print "query dashboard:{0}, status:{1}".format(board_uri, status_code)
return (status_code, content)
def update_or_create_dashboard(payload):
r = send_grafana_post(grafana_url + '/api/dashboards/db', payload)
status_code = r.status_code
......@@ -20,11 +23,13 @@ def update_or_create_dashboard(payload):
print "msg: {0}".format(r.content)
return int(status_code)
def search_datasource():
r = send_grafana_get(grafana_url + '/api/datasources')
print "search datasources in grafana:"
return r.content
def create_datasource(payload):
r = send_grafana_post(grafana_url + '/api/datasources', payload)
status_code = r.status_code
......@@ -32,12 +37,12 @@ def create_datasource(payload):
print "msg: {0}".format(r.content)
return int(status_code)
def send_grafana_get(url):
r = requests.get(url, headers=http_get_headers)
return r
def send_grafana_post(url, json_payload):
r = requests.post(url, headers=http_post_headers, data=json_payload)
return r
return r
\ No newline at end of file
......@@ -8,6 +8,7 @@ args = parser.parse_args()
folder_path = args.path
def get_all_dashboards_in_grafana():
content_of_all_dashboards = search_dashboard()
dashboards = json.loads(content_of_all_dashboards)
......@@ -16,19 +17,21 @@ def get_all_dashboards_in_grafana():
print board['title']
return dashboards
def save_dashboard_setting(file_name, dashboard_settings):
file_path = folder_path + '/' + file_name + '.dashboard'
with open(file_path , 'w') as f:
f.write(dashboard_settings)
print "dashboard:{0} are saved to {1}".format(file_name, file_path)
def get_indivisual_dashboard_setting_and_save(dashboards):
for board in dashboards:
status_code_and_content = get_dashboard(board['uri'])
if status_code_and_content[0] == 200:
#print(status_code_and_content[1])
# print(status_code_and_content[1])
save_dashboard_setting(board['title'], status_code_and_content[1])
#save_dashboard_setting(board['title'], json.dumps(status_code_and_content[1]))
# save_dashboard_setting(board['title'], json.dumps(status_code_and_content[1]))
dashboards = get_all_dashboards_in_grafana()
......
......@@ -8,20 +8,21 @@ args = parser.parse_args()
folder_path = args.path
def save_datasource(file_name, datasource_setting):
file_path = folder_path + '/' + file_name + '.datasource'
with open(file_path, 'w') as f:
f.write(json.dumps(datasource_setting))
print "datasource:{0} is saved to {1}".format(file_name, file_path)
def get_all_datasources_and_save():
content_of_datasources = search_datasource()
datasources = json.loads(content_of_datasources)
print "There are {0} datasources:".format(len(datasources))
for datasource in datasources:
#print datasource['name']
# print datasource['name']
save_datasource(datasource['name'], datasource)
datasources = get_all_datasources_and_save()
......
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