diff --git a/deploy.py b/deploy.py index f896026..2954171 100755 --- a/deploy.py +++ b/deploy.py @@ -66,7 +66,7 @@ def build_dashboard(dashboard_path, api): datasources = api("/datasources") datasources_names = [ds["name"] for ds in datasources] - return json.loads( + dashboard = json.loads( subprocess.check_output( [ "jsonnet", @@ -78,6 +78,9 @@ def build_dashboard(dashboard_path, api): ] ).decode() ) + if not dashboard: + raise ValueError(f"jsonnet render of {dashboard_path} led to an empty object") + return dashboard def deploy_dashboard(dashboard_path, folder_uid, api): @@ -85,6 +88,7 @@ def deploy_dashboard(dashboard_path, folder_uid, api): Creates a new dashboard or updates an existing dashboard. """ db = build_dashboard(dashboard_path, api) + # 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 @@ -92,9 +96,6 @@ def deploy_dashboard(dashboard_path, folder_uid, api): # 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) # api ref: https://grafana.com/docs/grafana/latest/developers/http_api/dashboard/#create--update-dashboard