def migrate_dashboards(from_file, src_acct, src_api_key, tgt_acct, tgt_api_key): log.info('Dashboard migration started.') db_names = store.load_names(from_file) all_db_status = {} for db_name in db_names: all_db_status[db_name] = {} tgt_dashboard = get_dashboard(tgt_api_key, db_name, all_db_status) if tgt_dashboard is not None: log.warning('Dashboard already exists in target skipping : ' + db_name) all_db_status[db_name][ds.TARGET_EXISTED] = True continue all_db_status[db_name][ds.TARGET_EXISTED] = False src_dashboard = get_dashboard(src_api_key, db_name, all_db_status) if src_dashboard is None: continue log.info('Found source dashboard ' + db_name) if 'metadata' not in src_dashboard: src_dashboard['metadata'] = {'version': 1} tgt_dashboard = {"dashboard": src_dashboard} result = ec.post_dashboard(tgt_api_key, tgt_dashboard) all_db_status[db_name][ds.STATUS] = result['status'] if result['entityCreated']: log.info('Created target dashboard ' + db_name) all_db_status[db_name][ds.DASHBOARD_CREATED] = True all_db_status[db_name][ds.TARGET_DASHBOARD] = result['entity']['dashboard']['ui_url'] db_status_file = str(src_acct) + '_' + utils.file_name_from(from_file) + '_dashboards_' + str(tgt_acct) + '.csv' store.save_status_csv(db_status_file, all_db_status, ds) log.info('Dashboard migration complete.')
def migrate_monitors(from_file, src_acct, src_api_key, time_stamp, tgt_acct_id, target_api_key, per_api_key): monitor_names = store.load_names(from_file) logger.debug(monitor_names) all_monitors_json = store.load_monitors(src_acct, time_stamp, monitor_names) monitor_status = migrate(all_monitors_json, src_acct, src_api_key, tgt_acct_id, target_api_key, per_api_key) logger.debug(monitor_status) file_name = utils.file_name_from(from_file) status_csv = src_acct + "_" + file_name + "_" + tgt_acct_id + ".csv" store.save_status_csv(status_csv, monitor_status, mskeys)
def migrate_apps(from_file, src_acct, src_api_key, per_api_key, tgt_acct, tgt_api_key, migrate_list=DEFAULT_MIGRATE_LIST): all_apps_status = {} if MIGRATE_LABELS in migrate_list: migrate_labels(from_file, src_acct, src_api_key, per_api_key, tgt_acct, all_apps_status) if MIGRATE_SETTINGS in migrate_list: migrate_settings(from_file, src_api_key, tgt_api_key, all_apps_status) file_name = utils.file_name_from(from_file) status_csv = src_acct + "_" + file_name + "_migrate_apm_" + tgt_acct + ".csv" store.save_status_csv(status_csv, all_apps_status, appkeys)
def migrate_alert_policies(from_file, src_account, src_api_key, tgt_account, tgt_api_key): logger.info('Alert migration started.') all_alert_status = {} policy_names = store.load_names(from_file) if fetch_channels: logger.info( 'Fetching latest channel info and policy assignment. This may take a while.....' ) loaded_src_channels = fetchchannels.get_channels_by_id_policy( src_api_key) else: logger.info( 'Loading pre-fetched channel and policy assignment information') loaded_src_channels = store.load_alert_channels(src_account) tgt_channels_by_type_name = get_channels_by_type_name(tgt_api_key) for policy_name in policy_names: all_alert_status[policy_name] = {} result = ac.get_policy(src_api_key, policy_name) if not result['policyFound']: logger.error("Skipping as policy not found in source account " + policy_name) all_alert_status[policy_name][ askeys.ERROR] = "Policy Not found in source account" continue src_policy = result['policy'] result = ac.get_policy(tgt_api_key, policy_name) if result['status'] in [200, 304] and result['policyFound']: logger.info('Policy exists : ' + policy_name) all_alert_status[policy_name] = {askeys.POLICY_EXISTED: True} tgt_policy = result['policy'] else: logger.info('Creating : ' + policy_name) all_alert_status[policy_name] = {askeys.POLICY_EXISTED: False} result = ac.create_alert_policy(tgt_api_key, src_policy) update_create_status(all_alert_status, policy_name, result) tgt_policy = result['policy'] update_notification_channels(tgt_api_key, src_policy, tgt_policy, loaded_src_channels, tgt_channels_by_type_name, all_alert_status) alert_status_file = str(src_account) + '_' + utils.file_name_from( from_file) + '_' + str(tgt_account) + '.csv' store.save_status_csv(alert_status_file, all_alert_status, askeys) logger.info('Alert migration complete.')
def migrate_conditions(from_file, per_api_key, src_account_id, src_api_key, tgt_account_id, tgt_api_key, cond_types): all_alert_status = {} policy_names = store.load_names(from_file) for policy_name in policy_names: logger.info('Migrating conditions for policy ' + policy_name) all_alert_status[policy_name] = {} src_result = ac.get_policy(src_api_key, policy_name) if not src_result['policyFound']: logger.error("Skipping as policy not found in source account " + policy_name) all_alert_status[policy_name][ cs.ERROR] = 'Policy not found in source account' continue src_policy = src_result['policy'] tgt_result = ac.get_policy(tgt_api_key, policy_name) if not tgt_result['policyFound']: logger.error("Skipping as policy not found in target account " + policy_name) all_alert_status[policy_name][ cs.ERROR] = 'Policy not found in target account' continue tgt_policy = tgt_result['policy'] if SYNTHETICS in cond_types: sc_migrator.migrate(all_alert_status, per_api_key, policy_name, src_api_key, src_policy, tgt_account_id, tgt_api_key, tgt_policy) lfc_migrator.migrate(all_alert_status, per_api_key, policy_name, src_api_key, src_policy, tgt_account_id, tgt_api_key, tgt_policy) if APP_CONDITIONS in cond_types: ac_migrator.migrate(all_alert_status, per_api_key, policy_name, src_api_key, src_policy, tgt_account_id, tgt_api_key, tgt_policy) if NRQL_CONDITIONS in cond_types: nrql_migrator.migrate(all_alert_status, per_api_key, policy_name, src_api_key, src_policy, tgt_account_id, tgt_api_key, tgt_policy) if EXT_SVC_CONDITIONS in cond_types: extsvc_migrator.migrate(all_alert_status, per_api_key, policy_name, src_api_key, src_policy, tgt_account_id, tgt_api_key, tgt_policy) status_file = src_account_id + '_' + utils.file_name_from( from_file) + '_' + tgt_account_id + '_conditions.csv' store.save_status_csv(status_file, all_alert_status, cs)