diff --git a/ops_bot/aws.py b/ops_bot/aws.py index 363aa66..c3a9170 100644 --- a/ops_bot/aws.py +++ b/ops_bot/aws.py @@ -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"{subject}\n

{message}

" + f"{subject}\n

{message}

" ) 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"{subject}\n

{description}

" ) diff --git a/ops_bot/common.py b/ops_bot/common.py index b33be83..787c361 100644 --- a/ops_bot/common.py +++ b/ops_bot/common.py @@ -1,6 +1,4 @@ -def urgency_color(urgency: str) -> str: - if urgency == "high": - return "#dc3545" # red - else: - return "#ffc107" # orange - # return "#17a2b8" # blue +COLOR_OK = "#33cc33" # green +COLOR_ALARM = "#dc3545" # red +COLOR_UNKNOWN = "#ffc107" # orange +COLOR_INFO = "#17a2b8" # blue diff --git a/ops_bot/pagerduty.py b/ops_bot/pagerduty.py index abd8c55..183a291 100644 --- a/ops_bot/pagerduty.py +++ b/ops_bot/pagerduty.py @@ -1,7 +1,14 @@ import json from typing import Any, Tuple -from ops_bot.common import urgency_color +from ops_bot.common import COLOR_ALARM, COLOR_UNKNOWN + + +def urgency_color(urgency: str) -> str: + if urgency == "high": + return COLOR_ALARM + else: + return COLOR_UNKNOWN def parse_pagerduty_event(payload: Any) -> Tuple[str, str]: