Skip to content

Commit

Permalink
failures are now reported to OpsCenter when setting should_forward_fa…
Browse files Browse the repository at this point in the history
…ilures_to_opscenter: true in the config
  • Loading branch information
eamonnfaherty committed Sep 19, 2019
1 parent 82ce457 commit 1ea81c4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
37 changes: 37 additions & 0 deletions servicecatalog_puppet/cli_command_helpers.py
Expand Up @@ -662,6 +662,13 @@ def deploy_launches_task_builder_for_account_launch_region(

def run_tasks(tasks_to_run):
should_use_eventbridge = get_should_use_eventbridge(os.environ.get("AWS_DEFAULT_REGION"))
should_forward_failures_to_opscenter = get_should_forward_failures_to_opscenter(os.environ.get("AWS_DEFAULT_REGION"))

ssm_client = None
if should_forward_failures_to_opscenter:
with betterboto_client.ClientContextManager('ssm') as ssm:
ssm_client = ssm

entries = []

for type in ["failure", "success", "timeout", "process_failure", "processing_time", "broken_task", ]:
Expand Down Expand Up @@ -694,6 +701,7 @@ def run_tasks(tasks_to_run):
'Detail': result_contents,
'EventBusName': constants.EVENT_BUS_NAME
})

table_data.append([
result.get('task_type'),
params.get('launch_name'),
Expand All @@ -707,6 +715,35 @@ def run_tasks(tasks_to_run):
click.echo(table.table)
for filename in glob('results/failure/*.json'):
result = json.loads(open(filename, 'r').read())
params = result.get('params_for_results')
if should_forward_failures_to_opscenter:
title = f"{result.get('task_type')} failed: {params.get('launch_name')} - {params.get('account_id')} - {params.get('region')}"
logging.info(f"Sending failure to opscenter: {title}")
ssm_client.create_ops_item(
Title=title,
Description="\n".join(result.get('exception_stack_trace')),
OperationalData={
'launch_name': {
'Value': params.get('launch_name'),
'Type': 'SearchableString'
},
'account_id': {
'Value': params.get('account_id'),
'Type': 'SearchableString'
},
'region': {
'Value': params.get('region'),
'Type': 'SearchableString'
},
'task_type': {
'Value': result.get('task_type'),
'Type': 'SearchableString'
},
},
Priority=1,
Source=constants.SERVICE_CATALOG_PUPPET_OPS_CENTER_SOURCE,
)

click.echo(colorclass.Color("{red}" + result.get('task_type') + " failed{/red}"))
click.echo(f"{yaml.safe_dump({'parameters':result.get('task_params')})}")
click.echo("\n".join(result.get('exception_stack_trace')))
Expand Down
3 changes: 2 additions & 1 deletion servicecatalog_puppet/constants.py
Expand Up @@ -32,4 +32,5 @@
CHANGE = 'CHANGE'

EVENT_BUS_NAME = "servicecatalog-puppet-event-bus"
SERVICE_CATALOG_PUPPET_EVENT_SOURCE = "servicecatalog-puppet"
SERVICE_CATALOG_PUPPET_EVENT_SOURCE = "servicecatalog-puppet"
SERVICE_CATALOG_PUPPET_OPS_CENTER_SOURCE = "servicecatalog-puppet"
1 change: 1 addition & 0 deletions servicecatalog_puppet/example-config-small.yaml
Expand Up @@ -5,3 +5,4 @@ regions: [
]
should_collect_cloudformation_events: true
should_forward_events_to_eventbridge: true
should_forward_failures_to_opscenter: true
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name="aws-service-catalog-puppet",
version="0.34.0",
version="0.35.0",
author="Eamonn Faherty",
author_email="aws-service-catalog-tools@amazon.com",
description="Making it easier to deploy ServiceCatalog products",
Expand Down

0 comments on commit 1ea81c4

Please sign in to comment.