Desktop notifications when a container dies or turns unhealthy #19

Closed
opened 2026-11-30 14:39:43 +00:00 by jfro · 1 comment
Owner

What

  • Listen to engine events (die with a non-zero exit, health_status: unhealthy, oom) and send a desktop notification (freedesktop Notifications over D-Bus) with the container/project name.
  • Clicking the notification opens Krane on that container's logs.
  • Ignore stops Krane itself started; a setting to turn notifications off.
**What** - Listen to engine events (`die` with a non-zero exit, `health_status: unhealthy`, `oom`) and send a desktop notification (freedesktop Notifications over D-Bus) with the container/project name. - Clicking the notification opens Krane on that container's logs. - Ignore stops Krane itself started; a setting to turn notifications off.
jfro added this to the v1.0 milestone 2026-11-30 14:47:14 +00:00
Author
Owner

Notes for the build, from Nye's tests against real Docker 26 and Podman 5.4 events (posted by Haystack for Nye):

#19 notifications: what engine events really look like (Nye, Nov 30)

Tested live: Docker 26 and rootless Podman 5.4.2 (compat API), via docker events.

Docker 26

  • docker stop (CLI or Krane): kill, (kill), stop, then die exitCode=137 (or 0 if the app traps TERM). Non-zero.
  • docker kill: kill then die 137 (no stop event). docker rm -f: kill then die 137.
  • Crash: just die exitCode=3.
  • OOM: oom then die 137 -> two events for one failure.
  • Restart policy on-failure: one die exitCode=1 per restart -> repeated alerts.
  • Unhealthy: Action string is exactly health_status: unhealthy (sent once on transition).

Podman 5.4 (compat API)

  • podman stop: only die 137, NO kill/stop events first -> "was it stopped on purpose" can't be read from events.
  • Health: Action is plain health_status, NO status attribute, and it fires on every check (each second here).

Must-dos for the build

  1. Don't alert on die after an intentional stop: remember ids Krane stopped/killed/removed/restarted (Krane-side set, ~10 s),
    and on Docker also skip a die preceded by kill/stop for the same id within ~10 s (covers CLI stops). On Podman only
    Krane's own set works; accept that CLI podman stop alerts (or match on 137/143 only when not Krane's: call it out).
  2. Coalesce oom + die for the same id into one notification ("ran out of memory").
  3. Rate-limit per container (e.g. one per 60 s) so restart loops don't spam; replace_id the previous notification.
  4. Health: match action prefix health_status; if no : <status> suffix (Podman), inspect the container and only
    notify on a transition to unhealthy (keep last-known health per id).
  5. D-Bus: zbus 5.13 is already in Cargo.lock via ksni, no new dep needed. Send actions ["default","Show logs"],
    listen for ActionInvoked + NotificationClosed on the same connection, map notification id -> container id.
    Xfce notifyd 0.9.7 here advertises actions and body-markup; check GetCapabilities and drop actions if missing.
  6. Escape container names in the body if using markup (body-markup servers parse <>&).
  7. With #16, the listener must restart on engine switch (generation counter) and use the shared client.
Notes for the build, from Nye's tests against real Docker 26 and Podman 5.4 events (posted by Haystack for Nye): # #19 notifications: what engine events really look like (Nye, Nov 30) Tested live: Docker 26 and rootless Podman 5.4.2 (compat API), via `docker events`. ## Docker 26 - `docker stop` (CLI or Krane): kill, (kill), stop, then **die exitCode=137** (or 0 if the app traps TERM). Non-zero. - `docker kill`: kill then die 137 (no stop event). `docker rm -f`: kill then die 137. - Crash: just `die exitCode=3`. - OOM: `oom` then `die 137` -> two events for one failure. - Restart policy on-failure: one `die exitCode=1` per restart -> repeated alerts. - Unhealthy: Action string is exactly `health_status: unhealthy` (sent once on transition). ## Podman 5.4 (compat API) - `podman stop`: only `die 137`, NO kill/stop events first -> "was it stopped on purpose" can't be read from events. - Health: Action is plain `health_status`, NO status attribute, and it fires on every check (each second here). ## Must-dos for the build 1. Don't alert on die after an intentional stop: remember ids Krane stopped/killed/removed/restarted (Krane-side set, ~10 s), and on Docker also skip a die preceded by kill/stop for the same id within ~10 s (covers CLI stops). On Podman only Krane's own set works; accept that CLI `podman stop` alerts (or match on 137/143 only when not Krane's: call it out). 2. Coalesce oom + die for the same id into one notification ("ran out of memory"). 3. Rate-limit per container (e.g. one per 60 s) so restart loops don't spam; replace_id the previous notification. 4. Health: match action prefix `health_status`; if no `: <status>` suffix (Podman), inspect the container and only notify on a transition to unhealthy (keep last-known health per id). 5. D-Bus: zbus 5.13 is already in Cargo.lock via ksni, no new dep needed. Send actions ["default","Show logs"], listen for ActionInvoked + NotificationClosed on the same connection, map notification id -> container id. Xfce notifyd 0.9.7 here advertises `actions` and `body-markup`; check GetCapabilities and drop actions if missing. 6. Escape container names in the body if using markup (body-markup servers parse <>&). 7. With #16, the listener must restart on engine switch (generation counter) and use the shared client.
jfro closed this issue 2026-11-30 19:30:54 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/krane#19
No description provided.