diff --git a/ns8_backup_monitor/notifier.py b/ns8_backup_monitor/notifier.py index ed3fa0a..8c4a8b0 100644 --- a/ns8_backup_monitor/notifier.py +++ b/ns8_backup_monitor/notifier.py @@ -6,6 +6,11 @@ Formats a human-readable HTML + text email based on: - correlation outcome (SUCCESS / PARTIAL / REPO_FAILURE) - per-module statuses - repository check results (if run) + +SMTP configuration is resolved via smtp_config.resolve_smtp_config(): + 1. NS8 cluster Redis (cluster/mail_settings) - same relay used by NS8 itself + 2. config.yml [smtp] section + 3. localhost:25 fallback """ import logging @@ -15,9 +20,11 @@ from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from typing import Optional +from .smtp_config import resolve_smtp_config + log = logging.getLogger(__name__) -OUTCOME_EMOJI = { +OUTCOME_LABEL = { "SUCCESS": "OK", "PARTIAL": "WARNING", "REPO_FAILURE": "CRITICAL", @@ -33,7 +40,7 @@ OUTCOME_COLOR = { def _build_text(correlation: dict, repo_status: Optional[dict]) -> str: outcome = correlation["outcome"] lines = [ - f"NS8 Backup Monitor - {OUTCOME_EMOJI[outcome]}: {outcome}", + f"NS8 Backup Monitor - {OUTCOME_LABEL[outcome]}: {outcome}", f"Time: {datetime.now(timezone.utc).isoformat()}", f"Plans checked: {', '.join(correlation.get('backup_ids', []))}", f"Modules: {correlation['succeeded']} OK / {correlation['failed']} FAILED / {correlation['total']} total", @@ -60,10 +67,10 @@ def _build_text(correlation: dict, repo_status: Optional[dict]) -> str: return "\n".join(lines) -def _build_html(correlation: dict, repo_status: Optional[dict]) -> str: +def _build_html(correlation: dict, repo_status: Optional[dict], smtp_source: str) -> str: outcome = correlation["outcome"] color = OUTCOME_COLOR[outcome] - label = OUTCOME_EMOJI[outcome] + label = OUTCOME_LABEL[outcome] ts = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC") plan_ids = ", ".join(correlation.get("backup_ids", [])) or "N/A" @@ -131,6 +138,7 @@ def _build_html(correlation: dict, repo_status: Optional[dict]) -> str:
{rows} {repo_section} +Sent via {smtp_source}