alerts: email alert transitions over SMTP#54
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional SMTP email sink to the alert evaluator, alongside the existing webhook.
What
When
WATCHER_ALERT_SMTP_HOSTis set, each alert fire/resolve transition is emailed (STARTTLS, authenticated) in addition to — or instead of — the webhook. The two sinks are now independent: previouslynotifyearly-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
EmailConfig(fromWATCHER_ALERT_SMTP_{HOST,PORT,USERNAME,PASSWORD,FROM,TO}), and aMailerbuilt once inrun()on a rustls STARTTLS transport — no OpenSSL, keeps the arm64 image clean.email_subject/email_bodyformatters with unit tests.Tests
cargo test --lib alerts→ 7/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 theWATCHER_ALERT_SMTP_*env from a SOPS secret and point watcher's alerts at email once this image ships.🤖 Generated with Claude Code