feat(alerts): alert by webhook and email #13
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/alerting"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
feat/health-maintenance).Changes
alert_channels, at most 20 per organization): kind, name, destination, events, on/off, and the outcome of the last delivery. Managed by admins signed in as users on/orgs/:org/alerts. Not in the API, deliberately: a leaked API key must not be able to redirect an organization's alerts. Members cannot read them (a webhook URL is often a secret). Admin changes are audited naming a webhook's host, never its URL, and no email address.secret_key_base(signing needs the secret itself, so it cannot be a hash; changingsecret_key_basemakes stored secrets unreadable, New secret replaces one). Requests carryx-traefik-control-timestampandx-traefik-control-signature: v1=<hex>, the HMAC-SHA256 of"<timestamp>.<body>".Alerts.Network): a destination is refused when any address it resolves to is private, loopback, link-local, CGNAT, documentation, multicast and so on (IPv4 and IPv6, including IPv4-mapped, NAT64 and 6to4 forms), at save time and again at every delivery. The request then goes to the address that was checked, with the host name kept forHostand TLS, so a name cannot change its answer in between. No redirects, 5 s limit, answers never read or kept.TRAEFIK_CONTROL_WEBHOOK_ALLOW_PRIVATE=truelifts it for operators who trust the network. Names are only looked up when saving, never while the form validates (see below), and every lookup is time-bounded.Delivery.deliver/2never raises. Best effort, no persistent queue: an attempt in flight is lost on restart (documented). A burst alerts the first 20 events; a flapping target alerts on every change.Nodes.Monitor): every 30 s compareslast_seen_atwithTRAEFIK_CONTROL_NODE_OFFLINE_AFTER(default 180, min 90, 0 = off). Presence changes are claimed with conditional updates, so with several instances exactly one alerts (tested with four concurrent checks). Nodes whose state was unknown settle silently.Health.ingest/3(down, back up, or first seen down).gen_smtp1.3.0 (approved; BSD-2, current, pulls inranch) for Swoosh's SMTP adapter.TRAEFIK_CONTROL_SMTP_*/TRAEFIK_CONTROL_MAIL_FROM; the server certificate is always verified unless TLS isnone. Without an SMTP host, email channels cannot be added. Plain text only.alert_channelsandnodes.presence, portable (the array column round-trips on both backends).Bugs found by running it for real
username: nilin the SMTP config makes Swoosh raise even withauth: :never; credentials are now passed only when given._buildmade beforegen_smtpwas added fails every send withBadMapErroruntilmix deps.compile swoosh --force(documented in the README; a clean build is fine). An exception in the mail adapter used to crash the LiveView and the background task before the failure was recorded; deliveries now never raise.Verification
mix format --check-formatted,mix compile --warnings-as-errors,mix credo --strict(no issues),mix dialyzer(0 errors).mix test: 1060 passed on SQLite and on PostgreSQL. The webhook tests run against a real local HTTP server (signatures verified, retries, redirects refused, timeouts, private destinations refused at send time, the Host header kept); the node monitor tests include the concurrent claim.openssl. Then real incidents: stoppingwhoamialertedtarget.downon both channels, restarting ittarget.up(a healthy first sighting alerted nothing); stopping the node's Traefik alertednode.offlineabout 2.5 minutes after its last poll, restarting itnode.online. Each event arrived once per channel. The audit log named the host and no URL, token or address. The dev database was restored afterwards.Not covered
hostnameoption) is not exercised against a real TLS server, and SMTP with STARTTLS orsslagainst a real certificate was not run (Mailpit ran with TLSnone).xto feat(alerts): alert by webhook and email