diff --git a/handler.py b/handler.py index 2be0414..24f8d4a 100644 --- a/handler.py +++ b/handler.py @@ -226,7 +226,7 @@ def send_org_alert( except URLError as e: print("Server connection failed: ", e.reason) pass - if "office.com/webhook" in teams_url: + if "logic.azure.com:443/workflows" in teams_url: try: print("Sending the alert to Teams") send_to_teams( diff --git a/messagegenerator.py b/messagegenerator.py index 12c619b..7e4d01b 100644 --- a/messagegenerator.py +++ b/messagegenerator.py @@ -423,55 +423,416 @@ def get_org_message_for_teams(event_details, event_type, affected_org_accounts, 'service'].upper() + " service in the " + event_details['successfulSet'][0]['event'][ 'region'].upper() + " region." message = { - "@type": "MessageCard", - "@context": "http://schema.org/extensions", - "themeColor": "FF0000", - "summary": "AWS Health Aware Alert", - "sections": [ + "type": "AdaptiveCard", + "msteams": { "width": "full" }, + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "version": "1.5", + "body": [ { - "activityTitle": title, - "markdown": False, + "type": "TextBlock", + "size": "Medium", + "weight": "Bolder", + "text": "AHA Health Alert" + }, + { + "type": "TextBlock", + "weight": "Bolder", + "text": "🚨 [NEW] AWS Health reported an issue with the " + event_details['successfulSet'][0]['event'][ + 'service'].upper() + " service in the " + event_details['successfulSet'][0]['event'][ + 'region'].upper() + " region.", + "wrap": "true" + }, + { + "type": "TextBlock", + "spacing": "None", + "text": "Created DATE", + "isSubtle": "true", + "wrap": "true", + "isVisible": "false" + }, + { + "type": "FactSet", "facts": [ - {"name": "Account(s)", "value": affected_org_accounts}, - {"name": "Resource(s)", "value": affected_org_entities}, - {"name": "Service", "value": event_details['successfulSet'][0]['event']['service']}, - {"name": "Region", "value": event_details['successfulSet'][0]['event']['region']}, - {"name": "Start Time (UTC)", "value": cleanup_time(event_details['successfulSet'][0]['event']['startTime'])}, - {"name": "Status", "value": event_details['successfulSet'][0]['event']['statusCode']}, - {"name": "Event ARN", "value": event_details['successfulSet'][0]['event']['arn']}, - {"name": "Updates", "value": event_details['successfulSet'][0]['eventDescription']['latestDescription']} + { + "title": "Account(s)", + "value": affected_org_accounts + }, + { + "title": "Resource(s)", + "value": affected_org_entities + }, + { + "title": "Service", + "value": event_details['successfulSet'][0]['event']['service'] + }, + { + "title": "Region", + "value": event_details['successfulSet'][0]['event']['region'] + }, + { + "title": "Start Time (UTC)", + "value": cleanup_time(event_details['successfulSet'][0]['event']['startTime']) + }, + { + "title": "End Time (UTC)", + "value": cleanup_time(event_details['successfulSet'][0]['event']['endTime']) + }, + { + "title": "Status", + "value": event_details['successfulSet'][0]['event']['statusCode'] + } ], + "$data": "${facts}" + }, + { + "type": "Container", + "items": [{ + "type": "ColumnSet", + "columns": [{ + "type": "Column", + "items": [{ + "type": "TextBlock", + "text": "Event ARN", + "wrap": "true", + "size": "Medium", + "weight": "Bolder" + }], + "width": "stretch" + }, + { + "type": "Column", + "id": "chevronDown1", + "spacing": "Small", + "verticalContentAlignment": "Center", + "items": [{ + "type": "Image", + "url": "https://adaptivecards.io/content/down.png", + "width": "20px", + "altText": "collapsed" + }], + "width": "auto", + "isVisible": "false" + }, + { + "type": "Column", + "id": "chevronUp1", + "spacing": "Small", + "verticalContentAlignment": "Center", + "items": [{ + "type": "Image", + "url": "https://adaptivecards.io/content/up.png", + "width": "20px", + "altText": "expanded" + }], + "width": "auto" + } + ], + "selectAction": { + "type": "Action.ToggleVisibility", + "targetElements": [ + "cardContent1", + "chevronUp1", + "chevronDown1" + ] + } + }, + { + "type": "Container", + "id": "cardContent1", + "isVisible" : "false", + "items": [{ + "type": "Container", + "items": [{ + "type": "TextBlock", + "text": event_details['successfulSet'][0]['event']['arn'], + "isSubtle": "true", + "wrap": "true" } + ], + } ] - } - + } + ] + }, + { + "type": "Container", + "items": [{ + "type": "ColumnSet", + "columns": [{ + "type": "Column", + "items": [{ + "type": "TextBlock", + "text": "Description", + "wrap": "true", + "size": "Medium", + "weight": "Bolder" + }], + "width": "stretch" + }, + { + "type": "Column", + "id": "chevronDown2", + "spacing": "Small", + "verticalContentAlignment": "Center", + "items": [{ + "type": "Image", + "url": "https://adaptivecards.io/content/down.png", + "width": "20px", + "altText": "collapsed" + }], + "width": "auto", + "isVisible": "false" + }, + { + "type": "Column", + "id": "chevronUp2", + "spacing": "Small", + "verticalContentAlignment": "Center", + "items": [{ + "type": "Image", + "url": "https://adaptivecards.io/content/up.png", + "width": "20px", + "altText": "expanded" + }], + "width": "auto" + } + ], + "selectAction": { + "type": "Action.ToggleVisibility", + "targetElements": [ + "cardContent2", + "chevronUp2", + "chevronDown2" + ] + } + }, + { + "type": "Container", + "id": "cardContent2", + "isVisible" : "false", + "items": [{ + "type": "Container", + "items": [{ + "type": "TextBlock", + "text": get_last_aws_update(event_details), + "isSubtle": "true", + "wrap": "true" + } + ], + } + ] + } + ] + }, + ] + } + elif event_type == "resolve": title = "✅ [RESOLVED] The AWS Health issue with the " + event_details['successfulSet'][0]['event'][ 'service'].upper() + " service in the " + event_details['successfulSet'][0]['event'][ 'region'].upper() + " region is now resolved." message = { - "@type": "MessageCard", - "@context": "http://schema.org/extensions", - "themeColor": "00ff00", - "summary": "AWS Health Aware Alert", - "sections": [ + "type": "AdaptiveCard", + "msteams": { "width": "full" }, + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "version": "1.5", + "body": [ { - "activityTitle": title, - "markdown": False, + "type": "TextBlock", + "size": "Medium", + "weight": "Bolder", + "text": "AHA Health Alert" + }, + { + "type": "TextBlock", + "weight": "Bolder", + "text": "✅ [RESOLVED] The AWS Health issue with the " + event_details['successfulSet'][0]['event'][ 'service'].upper() + " service in the " + event_details['successfulSet'][0]['event']['region'].upper() + " region is now resolved.", + "wrap": "true" + }, + { + "type": "TextBlock", + "spacing": "None", + "text": "Created DATE", + "isSubtle": "true", + "wrap": "true", + "isVisible": "false" + }, + { + "type": "FactSet", "facts": [ - {"name": "Account(s)", "value": affected_org_accounts}, - {"name": "Resource(s)", "value": affected_org_entities}, - {"name": "Service", "value": event_details['successfulSet'][0]['event']['service']}, - {"name": "Region", "value": event_details['successfulSet'][0]['event']['region']}, - {"name": "Start Time (UTC)", "value": cleanup_time(event_details['successfulSet'][0]['event']['startTime'])}, - {"name": "End Time (UTC)", "value": cleanup_time(event_details['successfulSet'][0]['event']['endTime'])}, - {"name": "Status", "value": event_details['successfulSet'][0]['event']['statusCode']}, - {"name": "Event ARN", "value": event_details['successfulSet'][0]['event']['arn']}, - {"name": "Updates", "value": event_details['successfulSet'][0]['eventDescription']['latestDescription']} + { + "title": "Account(s)", + "value": affected_org_accounts + }, + { + "title": "Resource(s)", + "value": affected_org_entities + }, + { + "title": "Service", + "value": event_details['successfulSet'][0]['event']['service'] + }, + { + "title": "Region", + "value": event_details['successfulSet'][0]['event']['region'] + }, + { + "title": "Start Time (UTC)", + "value": cleanup_time(event_details['successfulSet'][0]['event']['startTime']) + }, + { + "title": "End Time (UTC)", + "value": cleanup_time(event_details['successfulSet'][0]['event']['endTime']) + }, + { + "title": "Status", + "value": event_details['successfulSet'][0]['event']['statusCode'] + } ], + "$data": "${facts}" + }, + { + "type": "Container", + "items": [{ + "type": "ColumnSet", + "columns": [{ + "type": "Column", + "items": [{ + "type": "TextBlock", + "text": "Event ARN", + "wrap": "true", + "size": "Medium", + "weight": "Bolder" + }], + "width": "stretch" + }, + { + "type": "Column", + "id": "chevronDown1", + "spacing": "Small", + "verticalContentAlignment": "Center", + "items": [{ + "type": "Image", + "url": "https://adaptivecards.io/content/down.png", + "width": "20px", + "altText": "collapsed" + }], + "width": "auto", + "isVisible": "false" + }, + { + "type": "Column", + "id": "chevronUp1", + "spacing": "Small", + "verticalContentAlignment": "Center", + "items": [{ + "type": "Image", + "url": "https://adaptivecards.io/content/up.png", + "width": "20px", + "altText": "expanded" + }], + "width": "auto" + } + ], + "selectAction": { + "type": "Action.ToggleVisibility", + "targetElements": [ + "cardContent1", + "chevronUp1", + "chevronDown1" + ] + } + }, + { + "type": "Container", + "id": "cardContent1", + "isVisible" : "false", + "items": [{ + "type": "Container", + "items": [{ + "type": "TextBlock", + "text": event_details['successfulSet'][0]['event']['arn'], + "isSubtle": "true", + "wrap": "true" } + ], + } ] - } + } + ] + }, + { + "type": "Container", + "items": [{ + "type": "ColumnSet", + "columns": [{ + "type": "Column", + "items": [{ + "type": "TextBlock", + "text": "Description", + "wrap": "true", + "size": "Medium", + "weight": "Bolder" + }], + "width": "stretch" + }, + { + "type": "Column", + "id": "chevronDown2", + "spacing": "Small", + "verticalContentAlignment": "Center", + "items": [{ + "type": "Image", + "url": "https://adaptivecards.io/content/down.png", + "width": "20px", + "altText": "collapsed" + }], + "width": "auto", + "isVisible": "false" + }, + { + "type": "Column", + "id": "chevronUp2", + "spacing": "Small", + "verticalContentAlignment": "Center", + "items": [{ + "type": "Image", + "url": "https://adaptivecards.io/content/up.png", + "width": "20px", + "altText": "expanded" + }], + "width": "auto" + } + ], + "selectAction": { + "type": "Action.ToggleVisibility", + "targetElements": [ + "cardContent2", + "chevronUp2", + "chevronDown2" + ] + } + }, + { + "type": "Container", + "id": "cardContent2", + "isVisible" : "false", + "items": [{ + "type": "Container", + "items": [{ + "type": "TextBlock", + "text": get_last_aws_update(event_details), + "isSubtle": "true", + "wrap": "true" + } + ], + } + ] + } + ] + }, + ] + } return message print("Message sent to Teams: ", message)