Add SNS format
This commit is contained in:
parent
e4308923b4
commit
b9e8747808
7 changed files with 1029 additions and 195 deletions
33
ops_bot/aws.py
Normal file
33
ops_bot/aws.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import json
|
||||
from typing import Any, Tuple
|
||||
|
||||
from ops_bot.common import urgency_color
|
||||
|
||||
|
||||
def handle_subscribe_confirm(payload: Any) -> Tuple[str, str]:
|
||||
message = payload.get("Message")
|
||||
url = payload.get("SubscribeURL")
|
||||
plain = f"{message}\n\n{url}"
|
||||
return plain, plain
|
||||
|
||||
|
||||
def handle_notification(payload: Any) -> Tuple[str, str]:
|
||||
message = payload.get("Message")
|
||||
subject = payload.get("Subject")
|
||||
|
||||
plain = f"{subject}\n{message}"
|
||||
color = urgency_color("high")
|
||||
formatted = (
|
||||
f"<strong><font color={color}>{subject}</font></strong>\n<p>{message}</p>"
|
||||
)
|
||||
return plain, formatted
|
||||
|
||||
|
||||
def parse_sns_event(payload: Any) -> Tuple[str, str]:
|
||||
if payload.get("Type") == "SubscriptionConfirmation":
|
||||
return handle_subscribe_confirm(payload)
|
||||
elif payload.get("Type") == "UnsubscribeConfirmation":
|
||||
return handle_subscribe_confirm(payload)
|
||||
elif payload.get("Type") == "Notification":
|
||||
return handle_notification(payload)
|
||||
raise Exception("Unnown SNS payload type")
|
||||
Loading…
Add table
Add a link
Reference in a new issue