From 7c1afbac9e62083c4ca447ec75e020ab6c57b605 Mon Sep 17 00:00:00 2001 From: louisevelayo Date: Thu, 29 Aug 2024 10:58:34 +0700 Subject: [PATCH] refactor: remove repetitive text and make status message more concise --- node_monitor/node_monitor_helpers/messages.py | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/node_monitor/node_monitor_helpers/messages.py b/node_monitor/node_monitor_helpers/messages.py index c1120a6f..8b1b727a 100644 --- a/node_monitor/node_monitor_helpers/messages.py +++ b/node_monitor/node_monitor_helpers/messages.py @@ -70,19 +70,17 @@ def nodes_compromised_message(nodes: List[ic_api.Node], def _make_subject() -> str: datacenters = {node.dc_id.upper() for node in nodes_compromised} match len(nodes_compromised): - case 0: return "All Systems Healthy" - case _: return "Action Required @ " + ', '.join(sorted(datacenters)) + case 0: return "🟢 All Systems Healthy" + case _: return "🟡 Action Required @ " + ', '.join(sorted(datacenters)) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - formatted_nodes_compromised = detailnodes(nodes, labels) subject = _make_subject() message = ( - f"🛑 Node(s) Compromised:\n" + f"Node(s) Compromised:\n" f"\n" f"{formatted_nodes_compromised}\n" f"\n" - f"Node Monitor by Aviate Labs\n" - f"Report Generated: {datetime_iso8601()} UTC\n" - f"Help us serve you better! Provide your feedback here: {c.FEEDBACK_FORM_URL}") + f"Report Generated: {datetime_iso8601()} UTC\n") return (subject, message) @@ -102,14 +100,14 @@ def nodes_status_message(nodes: List[ic_api.Node], def _make_diagnostic_message() -> str: match len(nodes_down): case 0: return "" - case _: return (f"🛑 Node(s) Compromised:\n" + case _: return (f"Node(s) Compromised:\n" f"\n" f"{detailnodes(nodes_down, labels)}\n\n") def _make_subject() -> str: datacenters = {node.dc_id.upper() for node in nodes_down} match len(nodes_down): - case 0: return "All Systems Healthy" - case _: return "Action Required @ " + ', '.join(sorted(datacenters)) + case 0: return "🟢 All Systems Healthy" + case _: return "🟡 Action Required @ " + ', '.join(sorted(datacenters)) def _render_frac(numerator: int, denominator: int) -> str: match numerator: case 0: return "None" @@ -117,19 +115,12 @@ def _render_frac(numerator: int, denominator: int) -> str: # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - subject = _make_subject() message = ( + f"\nNode Provider: {nodes[0].node_provider_name}\n" + f"Nodes Total: {total_nodes}\n" + f"Node Health: {len(nodes_degraded) + len(nodes_down)} Unhealthy, {len(nodes_unassigned) + len(nodes_up)} Healthy\n" + f"Node Assignment: {len(nodes_unassigned)} Unassigned, {len(nodes_up)} Assigned\n" + f"\n\n" f"{_make_diagnostic_message()}" - f"🔎 Node Status Breakdown:\n" - f"Nodes Up: { _render_frac(len(nodes_up ), total_nodes) }\n" - f"Nodes Down: { _render_frac(len(nodes_down), total_nodes) }\n" - f"Nodes Unassigned: { _render_frac(len(nodes_unassigned), total_nodes) }\n" - f"Nodes Disabled: { _render_frac(len(nodes_disabled), total_nodes) }\n" - f"Nodes Degraded: { _render_frac(len(nodes_degraded), total_nodes) }\n" - f"\n" - f"Total Nodes: {total_nodes}\n" - f"Node Provider: {nodes[0].node_provider_name}\n" - f"\n" - f"Thanks for reviewing today's report. We'll be back tomorrow!\n" - f"Node Monitor by Aviate Labs.\n" f"Report generated: {datetime_iso8601()} UTC\n" - f"Help us serve you better! Provide your feedback here: {c.FEEDBACK_FORM_URL}") + ) return (subject, message)