feat(notifications): send reports to Pushover, ntfy, and email #32

Manually merged
jfro merged 3 commits from feat/5-notifications into main 2026-11-01 19:19:11 +00:00
Owner

Closes #5

Settings → Notifications sends reports to Pushover, ntfy, and email (through the merged Mailgun mailer).

  • Notifies when a report opens, when its severity gets worse, and when it resolves (per-channel toggle). Retiring a source doesn't notify.
  • Each channel has a minimum severity, serious by default, so warnings (pending updates etc.) stay quiet unless asked.
  • Pushover: critical = priority 1, serious = 0, warnings/recoveries = -1; link back to the dashboard. ntfy: JSON publish to the server root (any title text), priority 5/4/3/2, tags, click link, optional bearer token, self-hosted servers. Email: comma-separated recipients; channel is off with a note when no mailer is configured.
  • Send a test checks unsaved settings without touching the saved status. A failed delivery is logged (channel, event, report id, duration, the service's error) and shown on the page as the last error.
  • Env vars win over saved fields: 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.
  • Delivery runs under a Task.Supervisor so a slow service never holds up a poll; errors can't break the poll.
  • Secrets are stored encrypted (EncryptedMap), same as source credentials.
  • Settings tabs: a 4th tab overflowed at 390px (404px), so tab icons hide below sm and 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-desktop

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

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

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

Closes #5 **Settings → Notifications** sends reports to **Pushover**, **ntfy**, and **email** (through the merged Mailgun mailer). - Notifies when a report **opens**, when its **severity gets worse**, and when it **resolves** (per-channel toggle). Retiring a source doesn't notify. - Each channel has a minimum severity, **serious by default**, so warnings (pending updates etc.) stay quiet unless asked. - Pushover: critical = priority 1, serious = 0, warnings/recoveries = -1; link back to the dashboard. ntfy: JSON publish to the server root (any title text), priority 5/4/3/2, tags, click link, optional bearer token, self-hosted servers. Email: comma-separated recipients; channel is off with a note when no mailer is configured. - **Send a test** checks unsaved settings without touching the saved status. A failed delivery is logged (channel, event, report id, duration, the service's error) and shown on the page as the last error. - **Env vars** win over saved fields: `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. - Delivery runs under a Task.Supervisor so a slow service never holds up a poll; errors can't break the poll. - Secrets are stored encrypted (EncryptedMap), same as source credentials. - Settings tabs: a 4th tab overflowed at 390px (404px), so tab icons hide below `sm` and 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-desktop](https://git.knope.dev/attachments/e3501561-1f63-4ca7-bb67-164ae2d04048) **notifications-pushover-390** (example data: Pushover on with saved secrets; ntfy on, critical only, with a failed last delivery) ![notifications-pushover-390](https://git.knope.dev/attachments/949758b2-2a82-4f3b-8780-9081c290402d) **notifications-ntfy-desktop** (example data: Pushover on with saved secrets; ntfy on, critical only, with a failed last delivery) ![notifications-ntfy-desktop](https://git.knope.dev/attachments/6b29e12d-5427-4606-a3e2-4198603cee01) **notifications-ntfy-390** (example data: Pushover on with saved secrets; ntfy on, critical only, with a failed last delivery) ![notifications-ntfy-390](https://git.knope.dev/attachments/71954dc6-8684-4460-a417-c0d07b4e3689)
feat(notifications): send reports to Pushover, ntfy, and email
All checks were successful
CI / test (pull_request) Successful in 26s
6885856d71
Settings → Notifications sets up Pushover, ntfy, and email (through the
Mailgun mailer). Reports notify when they open, when their severity gets
worse, and when they resolve, filtered by each channel's minimum severity
(serious by default) and recovery setting. Send a test checks unsaved
settings; failed deliveries are logged and shown on the settings page.

Environment variables (PUSHOVER_*, NTFY_*, NOTIFY_EMAIL_TO) can set a
channel's fields and win over saved settings. Delivery runs in a task so
polls never wait on it. Settings tabs no longer overflow at 390px.

Closes #5
jfro force-pushed feat/5-notifications from 6885856d71
All checks were successful
CI / test (pull_request) Successful in 26s
to bfa87ec1c8
All checks were successful
CI / test (pull_request) Successful in 25s
2026-11-01 18:40:40 +00:00
Compare
Author
Owner

Review: #32 Notifications (Closes #5) at 6885856 — Nye

Read 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_url and a blank access_token sends Authorization: Bearer tk_… to the new host. This is the retarget rule from #11/#26 (checklist D1). Fix: in change_config/2, when server_url changes from the stored value, drop the stored token from stored so a blank token isn't filled in (require it again if the topic needs one; an open topic is fine with none), and apply_values/2 shouldn'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: serious channel gets no "Resolved", because wants?(: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 in report_attrs/refresh_report since they replace context), escalate only when the new severity beats that peak, and decide :resolved by 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_error shows 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).

## Review: #32 Notifications (Closes #5) at 6885856 — Nye Read 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_url` and a blank `access_token` sends `Authorization: Bearer tk_…` to the new host. This is the retarget rule from #11/#26 (checklist D1). Fix: in `change_config/2`, when `server_url` changes from the stored value, drop the stored token from `stored` so a blank token isn't filled in (require it again if the topic needs one; an open topic is fine with none), and `apply_values/2` shouldn'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: serious` channel gets no "Resolved", because `wants?(: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 in `report_attrs`/`refresh_report` since they replace `context`), escalate only when the new severity beats that peak, and decide `:resolved` by 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_error` shows 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).
Author
Owner

Fixed at bfa87ec (rebased on main 7e178dd, precommit 728 green):

  • F8: a changed server URL (any non-env :url field) requires stored secrets again ("enter it again, since the server URL changed") and drops them on save, mirroring Sources.retarget. Applies to Send a test too.
  • F9/F10: reports keep context["peak_severity"]. Escalation compares with the peak (flapping pages once); recoveries go to channels the peak reached.
  • Nye's review tests added under test/review/; all pass.
    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).
Fixed at bfa87ec (rebased on main 7e178dd, precommit 728 green): - F8: a changed server URL (any non-env :url field) requires stored secrets again ("enter it again, since the server URL changed") and drops them on save, mirroring Sources.retarget. Applies to Send a test too. - F9/F10: reports keep `context["peak_severity"]`. Escalation compares with the peak (flapping pages once); recoveries go to channels the peak reached. - Nye's review tests added under test/review/; all pass. 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).
fix(notifications): keep env secrets on the server the env names
All checks were successful
CI / test (pull_request) Successful in 25s
3a61faf836
A token from NTFY_TOKEN is no longer sent to a server URL typed into
settings; set NTFY_URL with it for a self-hosted server. The settings
page and README say so, and delivery logs a warning when it's held back.
Author
Owner

Re-review of #32 at bfa87ec

F8, F9, F10 are fixed: my review tests pass, and mix precommit passes with 728 tests. CI is green and the PR merges cleanly. I read the fix: peak_severity is 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/2 skips secrets set by the environment. So with NTFY_TOKEN in the env and no NTFY_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) unless NTFY_URL is set, or refuse to deliver the env token to any URL other than NTFY_URL or 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 env NTFY_TOKEN is only sent to NTFY_URL or 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.

## Re-review of #32 at bfa87ec F8, F9, F10 are fixed: my review tests pass, and `mix precommit` passes with 728 tests. CI is green and the PR merges cleanly. I read the fix: `peak_severity` is 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/2` skips secrets set by the environment. So with `NTFY_TOKEN` in the env and no `NTFY_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`) unless `NTFY_URL` is set, or refuse to deliver the env token to any URL other than `NTFY_URL` or 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 env `NTFY_TOKEN` is only sent to `NTFY_URL` or 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.
jfro manually merged commit 8587c27253 into main 2026-11-01 19:19:11 +00:00
Sign in to join this conversation.
No description provided.