Skip to content

Commit

Permalink
FIXME - this commit helps me deploy dashboards to another folder to c…
Browse files Browse the repository at this point in the history
…ompare
  • Loading branch information
consideRatio committed Apr 7, 2024
1 parent dfbbff6 commit af4f2c0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions deploy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import argparse
import hashlib
import json
import os
import re
Expand Down Expand Up @@ -70,13 +71,19 @@ def build_dashboard(dashboard_path, api, global_dash=False):

def deploy_dashboard(dashboard_path, folder_uid, api, global_dash=False):
db = build_dashboard(dashboard_path, api, global_dash)
# without this modification, deploying to a second folder deletes deployed
# dashboards in another folder, likely due to generated dashboard UID is the
# same as an already existing dashboard UID. They are probably generated
# based on some hash that didn't get new input when deployed to the second
# folder compared to initially deployed to the first folder.
db['uid'] = hashlib.sha256((dashboard_path + folder_uid).encode()).hexdigest()[:16]

if not db:
return

db = populate_template_variables(api, db)

data = {'dashboard': db, 'folderId': folder_uid, 'overwrite': True}
data = {'dashboard': db, 'folderUid': folder_uid, 'overwrite': True}
api('/dashboards/db', data)


Expand Down Expand Up @@ -191,7 +198,7 @@ def main():
folder = ensure_folder(args.folder_name, args.folder_uid, api)

for dashboard in glob(f'{args.dashboards_dir}/*.jsonnet'):
deploy_dashboard(dashboard, folder['id'], api)
deploy_dashboard(dashboard, args.folder_uid, api)
print(f'Deployed {dashboard}')


Expand Down

0 comments on commit af4f2c0

Please sign in to comment.