def get_source_dashboard()

in sitewise_monitor_dashboard_replicator/sitewise_dashboard_replicator.py [0:0]


def get_source_dashboard(dashboard_id):
    dashboards_dict = {'source_dashboard':{}, 'update':{}}
    dash_details = client.describe_dashboard(dashboardId=dashboard_id)
    definition = json.loads(dash_details['dashboardDefinition'])
    name = dash_details['dashboardName']
    arn = dash_details['dashboardArn']
    if source_tag in name:
        print('Found Source Dashboard:')
        print('- Name:'+name)
        print('- ID: '+dashboard_id)
        source_asset_id = source_asset_id_check(definition)
        source_asset_details = client.describe_asset(assetId=source_asset_id)
        source_asset_model_id = source_asset_details['assetModelId']
        source_asset_siblings = list_assets(assetModelId=source_asset_model_id)
        if 'dashboardDescription' in dash_details:
            description = dash_details['dashboardDescription']
        else:
            description = name
        dash = {
            'definition':definition, 
            'name':name, 
            'description':description, 
            'arn':arn,
            'project_id':dash_details['projectId'], 
            'source_asset_id':source_asset_id,
            'source_asset_model_id':source_asset_model_id,
            'source_asset_siblings':source_asset_siblings
            }
        dashboards_dict['source_dashboard'].update(dash)
    else:
        raise ValueError('Dashboard not tagged as '+source_tag)
    
    #build a list of dashboards to update rather than create
    check_update = list_dashboards(dash_details['projectId'])
    for dashboard in check_update:
        dash_details = client.describe_dashboard(dashboardId=dashboard['id'])
        tags_response = client.list_tags_for_resource(
            resourceArn=dash_details['dashboardArn']
        )
        if 'assetId' in tags_response['tags']:
            dashboards_dict['update'].update({tags_response['tags']['assetId']:dash_details['dashboardId']})
    return dashboards_dict