Handle SNS cloudwatch alarm states with colors

This commit is contained in:
Abel Luck 2022-11-30 16:05:39 +00:00
parent 5ecb68f2e7
commit 08f5b49b16
3 changed files with 21 additions and 11 deletions

View file

@ -2,7 +2,7 @@ import json
import logging
from typing import Any, Tuple
from ops_bot.common import urgency_color
from ops_bot.common import COLOR_ALARM, COLOR_OK, COLOR_UNKNOWN
def handle_subscribe_confirm(payload: Any) -> Tuple[str, str]:
@ -17,9 +17,8 @@ def handle_notification(payload: Any) -> Tuple[str, str]:
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>"
f"<strong><font color={COLOR_ALARM}>{subject}</font></strong>\n<p>{message}</p>"
)
return plain, formatted
@ -33,9 +32,15 @@ def handle_json_notification(payload: Any, body: Any) -> Tuple[str, str]:
description = body.get("AlarmDescription")
subject = payload.get("Subject")
state_value = payload.get("NewStateValue", "unknown")
plain = f"{subject}\n{description}"
color = urgency_color("high")
if state_value == "ALARM":
color = COLOR_ALARM
elif state_value == "OK":
color = COLOR_OK
else:
color = COLOR_UNKNOWN
formatted = (
f"<strong><font color={color}>{subject}</font></strong>\n<p>{description}</p>"
)