Skip to content

Commit

Permalink
Various fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
crshanks committed Feb 10, 2023
1 parent 8582e56 commit ba3c7ab
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
9 changes: 6 additions & 3 deletions fetchentities.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def configure_parser():
help='Pass --workloads to list matching Workload entities')
parser.add_argument('--tagName', nargs=1, required=False, help='(Optional) Tag name to use when filtering results. Required if --tagValue is passed.')
parser.add_argument('--tagValue', nargs=1, required=False, help='(Optional) Tag value to use when filtering results. Required if --tagName is passed.')
parser.add_argument('--assessment', dest='assessment', required=False, action='store_true', help='Pass --assessment to prefix entities, with account id')
return parser


Expand Down Expand Up @@ -76,12 +77,14 @@ def fetch_entities(src_account_id, src_api_key, entity_types, output_file, *,
for entity_type in entity_types:
entities = ec.gql_get_entities_by_type(src_api_key, entity_type, src_account_id, tag_name, tag_value, src_region)
for entity in entities['entities']:
entity_names.append(entity['name'])
entity_names.append(store.sanitize(entity['name']))
entity_names_file = store.create_output_file(output_file)
with entity_names_file.open('a') as entity_names_out:
for entity_name in entity_names:
name = store.sanitize(entity_name)
entity_names_out.write(name + "\n")
if assessment:
entity_names_out.write(src_account_id + "," + entity_name + "\n")
else:
entity_names_out.write(entity_name + "\n")
entity_names_out.close()
logger.info("Wrote %s entities to file %s",len(entity_names), output_file)

Expand Down
18 changes: 12 additions & 6 deletions fetchnotifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@ def configure_parser():

def fetch_destinations(user_api_key, account_id, region, accounts_file=None):
destinations_by_id = get_config(nc.destinations, user_api_key, account_id, region, accounts_file)
store.save_notification_destinations(account_id, destinations_by_id)
return destinations_by_id


def fetch_channels(user_api_key, account_id, region, accounts_file=None):
channels_by_id = get_config(nc.channels, user_api_key, account_id, region, accounts_file)
store.save_notification_channels(account_id, channels_by_id)
return channels_by_id


def get_config(func, user_api_key, account_id, region, from_file):
def get_config(func, user_api_key, account_id, region, accounts_file):
acct_ids = []
if account_id:
acct_ids = [account_id]
else:
acct_ids = store.load_names(from_file)
acct_ids = store.load_names(accounts_file)
configs_by_id = {}
# Strip the class name
field = func.__name__
Expand All @@ -65,9 +63,15 @@ def get_config(func, user_api_key, account_id, region, from_file):
except:
logger.error(f'Error querying {field} for account {acct_id}')
else:
account_configs_by_id = {}
for element in config:
element['accountId'] = acct_id
configs_by_id.setdefault(element['id'], element)
account_configs_by_id.setdefault(element['id'], element)
if field == 'destinations':
store.save_notification_destinations(acct_id, account_configs_by_id)
if field == 'channels':
store.save_notification_channels(acct_id, account_configs_by_id)
logger.info(configs_by_id)
store.save_config_csv(field, configs_by_id)
return configs_by_id
Expand All @@ -80,10 +84,12 @@ def main():
if not user_api_key:
utils.error_and_exit('userApiKey', 'ENV_USER_API_KEY')
region = utils.ensure_region(args)
account_id = args.account[0] if args.account else None
accounts_file = args.accounts[0] if args.accounts else None
if args.destinations:
fetch_destinations(user_api_key, args.account[0], region, args.accounts[0] if args.accounts else None)
fetch_destinations(user_api_key, account_id, region, accounts_file)
elif args.channels:
fetch_channels(user_api_key, args.account[0], region, args.accounts[0] if args.accounts else None)
fetch_channels(user_api_key, account_id, region, accounts_file)
else:
logger.info("pass [--destinations | --channels] to fetch configuration")

Expand Down
8 changes: 6 additions & 2 deletions fetchworkflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def configure_parser():

def fetch_workflows(user_api_key, account_id, region, accounts_file=None):
workflow_by_source_id = get_config(wc.workflows, user_api_key, account_id, region, accounts_file)
store.save_workflows(account_id, workflow_by_source_id)
return workflow_by_source_id


Expand Down Expand Up @@ -53,9 +52,12 @@ def get_config(func, user_api_key, account_id, region, from_file):
except:
logger.error(f'Error querying {field} for account {acct_id}')
else:
account_configs_by_id = {}
for element in config:
element['accountId'] = acct_id
configs_by_id.setdefault(element['id'], element)
account_configs_by_id.setdefault(element['id'], element)
store.save_workflows(acct_id, account_configs_by_id)
logger.info(configs_by_id)
store.save_config_csv(field, configs_by_id)
return configs_by_id
Expand All @@ -68,7 +70,9 @@ def main():
if not user_api_key:
utils.error_and_exit('userApiKey', 'ENV_USER_API_KEY')
region = utils.ensure_region(args)
fetch_workflows(user_api_key, args.account[0], args.accounts[0], region)
account_id = args.account[0] if args.account else None
accounts_file = args.accounts[0] if args.accounts else None
fetch_workflows(user_api_key, account_id, region, accounts_file)


if __name__ == '__main__':
Expand Down
5 changes: 5 additions & 0 deletions library/clients/entityclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,15 @@ def get_nrql_condition_payload(account_id, condition_id):
policyId
runbookUrl
signal {
aggregationDelay
aggregationMethod
aggregationTimer
aggregationWindow
evaluationDelay
evaluationOffset
fillOption
fillValue
slideBy
}
terms {
operator
Expand Down
2 changes: 0 additions & 2 deletions library/clients/notificationsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
SUPPORTED_DESTINATIONS = [
DESTINATION_TYPE_EMAIL,
DESTINATION_TYPE_MOBILE_PUSH,
DESTINATION_TYPE_SLACK,
DESTINATION_TYPE_SLACK_LEGACY,
DESTINATION_TYPE_WEBHOOK
]
Expand Down Expand Up @@ -49,7 +48,6 @@
SUPPORTED_CHANNELS = [
CHANNEL_TYPE_EMAIL,
CHANNEL_TYPE_MOBILE_PUSH,
CHANNEL_TYPE_SLACK,
CHANNEL_TYPE_SLACK_LEGACY,
CHANNEL_TYPE_WEBHOOK
]
Expand Down
3 changes: 2 additions & 1 deletion library/localstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ def create_output_file(file_name):


def sanitize(name):
illegal_characters = ['/', '?', '<', '>', '\\', ':', '*', '|']
# illegal_characters = ['/', '?', '<', '>', '\\', ':', '*', '|']
illegal_characters = ['/', '?', '<', '>', '\\', '*', '|']
characters = list(name)
for index, character in enumerate(characters):
if characters[index] in illegal_characters:
Expand Down
6 changes: 3 additions & 3 deletions migrate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def migrate_step1():
mm.migrate_monitors('output/' + SRC_MON_LIST_FILE, SRC_ACCT, SRC_REGION, SRC_API_KEY, src_mon_time_stamp, TGT_ACCT, TGT_REGION, TGT_API_KEY, MINION_MAPPING_FILE)
# Migrate Synthetic monitor entity tags
mt.migrate_tags('output/' + SRC_MON_LIST_FILE, SRC_ACCT, SRC_REGION, SRC_API_KEY, TGT_ACCT, TGT_REGION, TGT_API_KEY, [ec.SYNTH_MONITOR])


def migrate_step2():
# Migrate alert policies
policies_by_source_id = mp.migrate(POLICY_NAME_FILE, ENTITY_NAME_FILE, SRC_ACCT, SRC_REGION, TGT_ACCT, TGT_REGION, SRC_API_KEY, TGT_API_KEY, USE_LOCAL)
# Migrate alert conditions
Expand All @@ -104,9 +107,6 @@ def migrate_step1():
channels_by_source_id = mn.migrate_channels(SRC_ACCT, SRC_API_KEY, SRC_REGION, TGT_ACCT, TGT_API_KEY, TGT_REGION, destinations_by_source_id)
# Migrate workflows
workflows_by_source_id = mw.migrate_workflows(SRC_ACCT, SRC_API_KEY, SRC_REGION, TGT_ACCT, TGT_API_KEY, TGT_REGION, channels_by_source_id, policies_by_source_id)


def migrate_step2():
# Migrate APM app_apdex_threshold, end_user_apdex_threshold, and enable_real_user_monitoring settings
mapm.migrate_apps(APP_FILE, SRC_ACCT, SRC_API_KEY, SRC_REGION, TGT_ACCT, TGT_API_KEY, TGT_REGION)
# Migrate dashboards
Expand Down
2 changes: 1 addition & 1 deletion migrate_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def migrate_dashboards(from_file, src_acct, src_api_key, src_region, tgt_acct, t
update_nrql_account_ids(src_acct, tgt_acct, tgt_dashboard, account_mappings)
result = ec.post_dashboard(tgt_api_key, tgt_dashboard, tgt_acct, tgt_region)
all_db_status[db_name][ds.STATUS] = result['status']
if result['entityCreated']:
if 'entityCreated' in result:
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']['guid']
Expand Down

0 comments on commit ba3c7ab

Please sign in to comment.