Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make messages more concise #137

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions node_monitor/node_monitor_helpers/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -102,34 +100,27 @@ 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"
case _: return f"{numerator}/{denominator}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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)
Loading