Skip to content

alerts: email alert transitions over SMTP#54

Merged
thejefflarson merged 1 commit into
mainfrom
alert-email
Jun 21, 2026
Merged

alerts: email alert transitions over SMTP#54
thejefflarson merged 1 commit into
mainfrom
alert-email

Conversation

@thejefflarson

Copy link
Copy Markdown
Owner

Adds an optional SMTP email sink to the alert evaluator, alongside the existing webhook.

What

When WATCHER_ALERT_SMTP_HOST is set, each alert fire/resolve transition is emailed (STARTTLS, authenticated) in addition to — or instead of — the webhook. The two sinks are now independent: previously notify early-returned when no webhook was set, so email had to not be gated on that. A failure in one sink never skips the other (both best-effort, logged on failure).

How

  • New EmailConfig (from WATCHER_ALERT_SMTP_{HOST,PORT,USERNAME,PASSWORD,FROM,TO}), and a Mailer built once in run() on a rustls STARTTLS transport — no OpenSSL, keeps the arm64 image clean.
  • Invalid SMTP config (bad address/relay) is logged-and-disabled, not fatal — the alert loop keeps running.
  • Pure email_subject / email_body formatters with unit tests.

Tests

cargo test --lib alerts7/7 pass (3 new: subject for fire/resolve, body includes the condition + observed value, body handles no-data / no-service).

Deploy

Consumed by the homelab's charts/watcher (separate repo), which will set the WATCHER_ALERT_SMTP_* env from a SOPS secret and point watcher's alerts at email once this image ships.

🤖 Generated with Claude Code

Adds an optional SMTP sink to the alert evaluator alongside the existing
webhook. When WATCHER_ALERT_SMTP_HOST is set, each fire/resolve transition is
emailed (STARTTLS, authenticated) in addition to (or instead of) the webhook —
the two sinks are independent, so a failure in one never skips the other.

- New EmailConfig (from WATCHER_ALERT_SMTP_* env) + a Mailer built once in run()
  on a rustls STARTTLS transport (no OpenSSL, keeps the arm64 image clean).
- Invalid SMTP config is logged-and-disabled, not fatal; sends are best-effort
  like the webhook.
- Pure email_subject/email_body formatters with unit tests.

lettre 0.11 (rustls, no default native-tls). Docs updated with the new env vars.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013cYVqzH7Xfwea7fAozdQK7
@thejefflarson thejefflarson merged commit 9c9a1e5 into main Jun 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant