Skip to content

Commit 623b860

Browse files
author
Gustavo Dacunda
committed
Add link to event
1 parent f9765d5 commit 623b860

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

functions/notify_slack.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class AwsService(Enum):
3131

3232
cloudwatch = "cloudwatch"
3333
guardduty = "guardduty"
34+
systems_manager = "systems-manager"
3435

3536

3637
def decrypt_url(encrypted_url: str) -> str:
@@ -283,6 +284,11 @@ def format_ssm_run_command(message: Dict[str, Any], region: str) -> Dict[str, An
283284
:returns: formatted Slack message payload
284285
"""
285286

287+
systems_manager_url = get_service_url(region=region, service="systems_manager")
288+
run_command_url = systems_manager_url.replace(
289+
"/home", f"/run-command/{message.get('commandId')}"
290+
)
291+
286292
return {
287293
"color": SSMRunCommandStatus[message.get("status")].value,
288294
"text": f"EC2 Run Command Notification {region}",
@@ -323,6 +329,11 @@ def format_ssm_run_command(message: Dict[str, Any], region: str) -> Dict[str, An
323329
"value": f"`{message.get('detailedStatus')}`",
324330
"short": True,
325331
},
332+
{
333+
"title": "Link to Event",
334+
"value": f"{run_command_url}",
335+
"short": False,
336+
},
326337
],
327338
}
328339

functions/snapshots/snap_notify_slack_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@
268268
},
269269
{"short": True, "title": "Status", "value": "`Failed`"},
270270
{"short": True, "title": "Detailed Status", "value": "`Failed`"},
271+
{
272+
"short": False,
273+
"title": "Link to Event",
274+
"value": "https://console.aws.amazon.com/systems-manager/run-command/6f69316a-e502-5a20-99bc-2408825b6dee?region=us-east-1",
275+
},
271276
],
272277
"text": "EC2 Run Command Notification us-east-1",
273278
}
@@ -314,6 +319,11 @@
314319
},
315320
{"short": True, "title": "Status", "value": "`Success`"},
316321
{"short": True, "title": "Detailed Status", "value": "`Success`"},
322+
{
323+
"short": False,
324+
"title": "Link to Event",
325+
"value": "https://console.aws.amazon.com/systems-manager/run-command/6f69316a-e502-5a20-99bc-2408825b6dee?region=us-east-1",
326+
},
317327
],
318328
"text": "EC2 Run Command Notification us-east-1",
319329
}
@@ -364,6 +374,11 @@
364374
"title": "Detailed Status",
365375
"value": "`DeliveryTimedOut`",
366376
},
377+
{
378+
"short": False,
379+
"title": "Link to Event",
380+
"value": "https://console.aws.amazon.com/systems-manager/run-command/6f69316a-e502-5a20-99bc-2408825b6dee?region=us-east-1",
381+
},
367382
],
368383
"text": "EC2 Run Command Notification us-east-1",
369384
}
@@ -585,6 +600,11 @@
585600
},
586601
{"short": True, "title": "Status", "value": "`Success`"},
587602
{"short": True, "title": "Detailed Status", "value": "`Success`"},
603+
{
604+
"short": False,
605+
"title": "Link to Event",
606+
"value": "https://console.aws.amazon.com/systems-manager/run-command/6f69316a-e502-5a20-99bc-2408825b6dee?region=us-east-1",
607+
},
588608
],
589609
"text": "EC2 Run Command Notification us-east-1",
590610
}

0 commit comments

Comments
 (0)