Skip to content
Snippets Groups Projects
Unverified Commit 3d4d21cb authored by Felix's avatar Felix Committed by GitHub
Browse files

more robust way to retrieve the folder id (#167)

* add option to change all editors to viewers and back. essentially making it read-only

* restore file that got lost

* update versions

* Revert "update versions"

This reverts commit 37e2589cae06d3ea71f373cb38bd6fe5a21f9e1f.

* update versions

* two fixes for folder names with dashes and alerts-channels

* fix a bug with the folder uid and id logic

* fix naming
parent 86862446
No related branches found
No related tags found
No related merge requests found
import json
from grafana_backup.dashboardApi import get_folder_id_from_old_folder_url, create_dashboard
from grafana_backup.commons import to_python2_and_3_compatible_string
from grafana_backup.dashboardApi import get_folder_id, create_dashboard
def main(args, settings, file_path):
......@@ -18,7 +18,7 @@ def main(args, settings, file_path):
payload = {
'dashboard': content['dashboard'],
'folderId': get_folder_id_from_old_folder_url(content['meta']['folderUrl'], grafana_url, http_post_headers, verify_ssl, client_cert, debug),
'folderId': get_folder_id(content, grafana_url, http_post_headers, verify_ssl, client_cert, debug),
'overwrite': True
}
......
......@@ -254,19 +254,28 @@ def update_folder_permissions(payload, grafana_url, http_post_headers, verify_ss
debug)
def get_folder_id_from_old_folder_url(folder_url, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
if folder_url != "":
# Get folder uid
matches = re.search('dashboards\/[A-Za-z0-9]{1}\/(.*)\/.*', folder_url)
uid = matches.group(1)
response = get_folder(uid, grafana_url, http_post_headers, verify_ssl, client_cert, debug)
def get_folder_id(dashboard, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
folder_uid = ""
try:
folder_uid = dashboard['meta']['folderUid']
except (KeyError):
matches = re.search('dashboards\/f\/(.*)\/.*', dashboard['meta']['folderUrl'])
folder_uid = matches.group(1)
if (folder_uid != ""):
print("debug: quering with uid {}".format(folder_uid))
response = get_folder(folder_uid, grafana_url, http_post_headers, verify_ssl, client_cert, debug)
if isinstance(response[1], dict):
folder_data = response[1]
else:
folder_data = json.loads(response[1])
return folder_data['id']
return 0
try:
return folder_data['id']
except (KeyError):
return 0
else:
return 0
def create_folder(payload, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
......
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