in sitewise_monitor_dashboard_replicator/sitewise_dashboard_replicator.py [0:0]
def dashboard_sync(dashboard):
for asset_sibling in dashboard['source_dashboard']['source_asset_siblings']:
name_merge = dashboard['source_dashboard']['name']
name_merge = name_merge.replace(source_tag, asset_sibling['name'])
dash_new = {
'definition':update_definition(dashboard['source_dashboard']['definition'], asset_sibling['id'], asset_sibling['name']),
'name':asset_sibling['name'],
'description':dashboard['source_dashboard']['description'],
'asset_id':asset_sibling['id']
}
#Check if the asset_id is in the dashboard update list.
#If it is update the dashboard rather than create a new one.
if dash_new['asset_id'] in dashboard['update']:
response = client.update_dashboard(
dashboardId=dashboard['update'][dash_new['asset_id']],
dashboardName=name_merge,
dashboardDescription=dash_new['description'],
dashboardDefinition=json.dumps(dash_new['definition'])
)
print('Dashboard update success:')
print('- Name: '+name_merge)
#Create a new dashboard for the asset_id if it isn't in the update list.
else:
create_dashboard_response = client.create_dashboard(
projectId=dashboard['source_dashboard']['project_id'],
dashboardName=name_merge,
dashboardDescription=dash_new['description'],
dashboardDefinition=json.dumps(dash_new['definition']),
tags={
'assetId': dash_new['asset_id']
}
)
print('Dashboard create success:')
print('- Name: '+name_merge)