feat(notifications): send reports to Pushover, ntfy, and email #32
No reviewers
Labels
No labels
bug
docs
duplicate
enhancement
help wanted
invalid
nice-to-have
pre-1.0
question
security
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jfro/lamplighter!32
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/5-notifications"
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?
Closes #5
Settings → Notifications sends reports to Pushover, ntfy, and email (through the merged Mailgun mailer).
PUSHOVER_APP_TOKEN,PUSHOVER_USER_KEY,PUSHOVER_DEVICE,NTFY_URL,NTFY_TOPIC,NTFY_TOKEN,NOTIFY_EMAIL_TO. A channel whose required fields all come from env is on without saving; the form shows those fields as "Set by VAR". Env values are never written to the DB.smand the nav can scroll; now 390px wide at 390.Tests: 30 new (channels via Req.Test, email via Swoosh, env overrides, triggers open/escalate/resolve, LiveView).
mix precommit: 670 pass.Screenshots
notifications-pushover-desktop (example data: Pushover on with saved secrets; ntfy on, critical only, with a failed last delivery)

notifications-pushover-390 (example data: Pushover on with saved secrets; ntfy on, critical only, with a failed last delivery)

notifications-ntfy-desktop (example data: Pushover on with saved secrets; ntfy on, critical only, with a failed last delivery)

notifications-ntfy-390 (example data: Pushover on with saved secrets; ntfy on, critical only, with a failed last delivery)

6885856d71bfa87ec1c8Review: #32 Notifications (Closes #5) at
6885856— NyeRead against the #5 acceptance checklist. Solid PR: JSON publish for ntfy, no retries on 4xx, async via Task.Supervisor with a rescue so polls never break, EncryptedMap +
@derive Inspect except: [:secrets], env-set values used but never saved, settings page shows env var names only. Precommit passes (670 tests), and I checked that Pushover/ntfy tokens stay out of logs on a 400 and a timeout (C25).Three findings, each with a failing test in
test/review/notifications_review_test.exs(attached):F8 (medium, security): ntfy server URL change keeps the stored token. Saving or "Send a test" with a new
server_urland a blankaccess_tokensendsAuthorization: Bearer tk_…to the new host. This is the retarget rule from #11/#26 (checklist D1). Fix: inchange_config/2, whenserver_urlchanges from the stored value, drop the stored token fromstoredso a blank token isn't filled in (require it again if the topic needs one; an open topic is fine with none), andapply_values/2shouldn't carry the old secret over. Test:mix test test/review/notifications_review_test.exs --only describe:"F8 secret retarget (D1, same rule as #11/#26)".F9 (medium): recovery lost after a severity drop. Critical opens (paged), eases to warning, recovers: a
min_severity: seriouschannel gets no "Resolved", becausewants?(:resolved, …)checks the severity at resolve time. Test::71.F10 (low): flapping re-pages. serious→critical→serious→critical… sends "Now critical" every flap (3 in the test), since escalation compares with the previous poll only. Test:
:81.One fix covers F9 and F10: keep the highest severity seen on the report (e.g.
context["peak_severity"], carried over inreport_attrs/refresh_reportsince they replacecontext), escalate only when the new severity beats that peak, and decide:resolvedby the peak (sent if the channel would have wanted the worst point).Minor, not blocking: Pushover 5xx/timeout isn't retried (fine for 1.0,
last_errorshows it); ntfy body isn't byte-truncated to 4096 (summaries are short); a channel turned on by env vars can't be switched off in the UI (the page says so).Fixed at
bfa87ec(rebased on main7e178dd, precommit 728 green):context["peak_severity"]. Escalation compares with the peak (flapping pages once); recoveries go to channels the peak reached.Known, not changed: a token set via NTFY_TOKEN is still used if the URL is edited in the UI (env is the operator's choice).
Re-review of #32 at
bfa87ecF8, F9, F10 are fixed: my review tests pass, and
mix precommitpasses with 728 tests. CI is green and the PR merges cleanly. I read the fix:peak_severityis kept on every refresh, escalations compare with the peak, and recoveries go by the peak. A report opened before this ships has no peak and falls back to its severity, which is fine.One more, F11 (low, security): the retarget check in
retargeted?/2/require_stored_secrets/2skips secrets set by the environment. So withNTFY_TOKENin the env and noNTFY_URL, changing the server URL in settings and pressing Send a test (or waiting for the next alert) sends the env token to the new host. The env token is the one the UI is meant to never reveal.Proof:
test/nye/ntfy_env_token_retarget_test.exs(attached). It fails now.Suggested fix: when a channel's secret comes from the env, its URL field has to come from the env too. Either lock the URL field to the default (
https://ntfy.sh) unlessNTFY_URLis set, or refuse to deliver the env token to any URL other thanNTFY_URLor the default. Note it in the README Notifications env table ("set NTFY_URL along with NTFY_TOKEN for a self-hosted server").Everything else looks good to ship once F11 is fixed.
F11 fixed at
3a61faf: an envNTFY_TOKENis only sent toNTFY_URLor the default https://ntfy.sh. With a server URL from settings the env token is held back, delivery logs a warning, and the settings page shows "Only sent to https://ntfy.sh; set NTFY_URL for another server." README updated. Nye's proof is in test/nye/, plus 3 env tests and a LiveView test.mix precommit: 733 pass.