Skip to content
Snippets Groups Projects
Commit 1eee871f authored by arthur.yueh's avatar arthur.yueh
Browse files

make program more verbose

parent 84c46e51
No related branches found
No related tags found
No related merge requests found
...@@ -24,9 +24,9 @@ if [ ! -d "$folders_backup_path" ]; then ...@@ -24,9 +24,9 @@ if [ ! -d "$folders_backup_path" ]; then
mkdir -p "$folders_backup_path" mkdir -p "$folders_backup_path"
fi fi
python "${current_path}/saveDashboards.py" $dashboard_backup_path python "${current_path}/saveDashboards.py" $dashboard_backup_path || exit 0
python "${current_path}/saveDatasources.py" $datasource_backup_path python "${current_path}/saveDatasources.py" $datasource_backup_path || exit 0
python "${current_path}/saveFolders.py" $folders_backup_path python "${current_path}/saveFolders.py" $folders_backup_path || exit 0
tar -zcvf "/tmp/$compressed_dashboards_name" $dashboard_backup_path tar -zcvf "/tmp/$compressed_dashboards_name" $dashboard_backup_path
tar -zcvf "/tmp/$compressed_datasources_name" $datasource_backup_path tar -zcvf "/tmp/$compressed_datasources_name" $datasource_backup_path
......
...@@ -5,7 +5,7 @@ from commons import * ...@@ -5,7 +5,7 @@ from commons import *
def search_dashboard(): def search_dashboard():
print("search dashboard in grafana:") print("search dashboard in grafana:")
r = send_grafana_get(grafana_url + '/api/search/?type=dash-db') r = send_grafana_get(grafana_url + '/api/search/?type=dash-db')
return r.content.decode('utf8') return (r.status_code, r.content.decode('utf8'))
def get_dashboard(board_uri): def get_dashboard(board_uri):
r = send_grafana_get(grafana_url + "/api/dashboards/{0}".format(board_uri)) r = send_grafana_get(grafana_url + "/api/dashboards/{0}".format(board_uri))
...@@ -34,7 +34,7 @@ def create_datasource(payload): ...@@ -34,7 +34,7 @@ def create_datasource(payload):
def search_folders(): def search_folders():
print("search folder in grafana:") print("search folder in grafana:")
r = send_grafana_get(grafana_url + '/api/search/?type=dash-folder') r = send_grafana_get(grafana_url + '/api/search/?type=dash-folder')
return r.content.decode('utf8') return (r.status_code, r.content.decode('utf8'))
def get_folder(uid): def get_folder(uid):
r = send_grafana_get(grafana_url + "/api/folders/{0}".format(uid)) r = send_grafana_get(grafana_url + "/api/folders/{0}".format(uid))
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
current_path=`pwd` current_path=`pwd`
dashboard_folder="$1" dashboard_folder="$1"
if [ $# -ne 1 ]; then
echo "Please input the backup folder path. e.g. /tmp/dashboards/2018-01-01"
exit 1
fi
find "$dashboard_folder" -name "*.dashboard" -mindepth 1 | while read f ; do find "$dashboard_folder" -name "*.dashboard" -mindepth 1 | while read f ; do
echo "$f" echo "$f"
python $current_path/createDashboard.py "$f" python $current_path/createDashboard.py "$f"
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
current_path=`pwd` current_path=`pwd`
datasource_folder="$1" datasource_folder="$1"
if [ $# -ne 1 ]; then
echo "Please input the backup folder path. e.g. /tmp/datasources/2018-01-01"
exit 1
fi
find "$datasource_folder" -name "*.datasource" -mindepth 1 | while read f ; do find "$datasource_folder" -name "*.datasource" -mindepth 1 | while read f ; do
echo "$f" echo "$f"
python $current_path/createDatasource.py "$f" python $current_path/createDatasource.py "$f"
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
current_path=`pwd` current_path=`pwd`
folders_path="$1" folders_path="$1"
if [ $# -ne 1 ]; then
echo "Please input the backup folder path. e.g. /tmp/folders/2018-01-01"
exit 1
fi
find "$folders_path" -name "*.folder" -mindepth 1 | while read f ; do find "$folders_path" -name "*.folder" -mindepth 1 | while read f ; do
echo "$f" echo "$f"
python $current_path/createFolder.py "$f" python $current_path/createFolder.py "$f"
......
...@@ -12,12 +12,18 @@ folder_path = args.path ...@@ -12,12 +12,18 @@ folder_path = args.path
log_file = 'dashboards_{0}.txt'.format(datetime.today().strftime('%Y%m%d%H%M')) log_file = 'dashboards_{0}.txt'.format(datetime.today().strftime('%Y%m%d%H%M'))
def get_all_dashboards_in_grafana(): def get_all_dashboards_in_grafana():
content_of_all_dashboards = search_dashboard() status_and_content_of_all_dashboards = search_dashboard()
dashboards = json.loads(content_of_all_dashboards) status = status_and_content_of_all_dashboards[0]
print("There are {0} dashboards:".format(len(dashboards))) content = status_and_content_of_all_dashboards[1]
for board in dashboards: if status == 200:
print('name: {}'.format(board['title'])) dashboards = json.loads(content)
return dashboards print("There are {0} dashboards:".format(len(dashboards)))
for board in dashboards:
print('name: {}'.format(board['title']))
return dashboards
else:
print("get dashboards failed, status: {0}, msg: {1}".format(status, content))
return []
def save_dashboard_setting(dashboard_name, file_name, dashboard_settings): def save_dashboard_setting(dashboard_name, file_name, dashboard_settings):
......
...@@ -11,12 +11,18 @@ folder_path = args.path ...@@ -11,12 +11,18 @@ folder_path = args.path
log_file = 'folders_{0}.txt'.format(datetime.today().strftime('%Y%m%d%H%M')) log_file = 'folders_{0}.txt'.format(datetime.today().strftime('%Y%m%d%H%M'))
def get_all_folders_in_grafana(): def get_all_folders_in_grafana():
content_of_all_folders = search_folders() status_and_content_of_all_folders = search_folders()
folders = json.loads(content_of_all_folders) status = status_and_content_of_all_folders[0]
print("There are {0} folders:".format(len(folders))) content = status_and_content_of_all_folders[1]
for folder in folders: if status == 200:
print(folder['title']) folders = json.loads(content)
return folders print("There are {0} folders:".format(len(content)))
for folder in folders:
print("name: {0}".format(folder['title']))
return folders
else:
print("get folders failed, status: {0}, msg: {1}".format(status, content))
return []
def save_folder_setting(folder_name, file_name, folder_settings): def save_folder_setting(folder_name, file_name, folder_settings):
......
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