Refs #47. This PR covers Gandalf's part. The "unexpected reboot" alert, for crashes that recover inside the window, is host health, so it goes to thor (see the comment on #47).
What changes
When a configured host stops reporting to Prometheus, Gandalf asks Loki whether the host's systemd-logind logged a shutdown request just before it went quiet. The request looks like The system will reboot now! or power off now!.
Shutdown requested:
Dashboard: the host shows as "rebooting (planned)" in Needs attention, as an info-level host_rebooting event rather than an outage.
Cluster check: the host doesn't count toward it. Last night's two requested power-offs would no longer add up toward a cluster alert.
Ticket: only if the host hasn't come back within planned_reboot_grace of the shutdown line. The default is 20 minutes, and planned_reboot_grace_hosts sets per-host overrides. The ticket is P2 and titled "Planned reboot did not come back", with checks aimed at a host stuck in POST or boot, or left powered off.
No shutdown line: alerted exactly as before, on host_failure_threshold.
Loki not configured, unreachable, or erroring: alerted exactly as before. A failed log query never delays or silences an alert.
How it's built
reboots.py: a Loki client plus find_shutdown and grace_for. It doesn't touch Gandalf's database or tickets, so thor can take it over unchanged.
Loki queries: one per check per missing host, and only while the host could still be in an ordinary reboot (host_failure_threshold checks). The answer is cached until the host returns.
Restarts: a monitor restart in the middle of a reboot still finds the shutdown line, because the lookback covers the whole window.
Verification
Real data: ran find_shutdown from prod against Loki for last month's reboots. All six came out right:
Reboot
Result
micro1 planned, 11-06
planned (23:17:49)
monitor-02 planned, 11-06
planned (23:25:26)
compute-storage-02 planned, 11-18
planned (20:02:19)
compute-storage-02 crash, 11-21
not planned, alerted as usual
compute-storage-01 power off, 11-25
planned (03:21:38)
storage-01 unclean stop, 11-25
not planned, alerted as usual
Tests: 678 pass, 23 of them new. They cover planned with no ticket, cluster exclusion, caching, grace expiry, per-host grace, a crash, Loki down, no Loki configured, a monitor restart mid-reboot, and the query window cutoff. The Needs attention entry is tested too.
flake8 and bandit are clean. No em or en dashes.
Rollout
Prod's config.json needs "loki": {"url": "http://10.10.10.69:3100"}. Until it has that, nothing changes. I checked that the Gandalf LXC can query Loki at that address. After the merge I'll back up the config, add the key, and restart gandalf-monitor.
Refs #47. This PR covers Gandalf's part. The "unexpected reboot" alert, for crashes that recover inside the window, is host health, so it goes to thor (see the comment on #47).
## What changes
When a configured host stops reporting to Prometheus, Gandalf asks Loki whether the host's `systemd-logind` logged a shutdown request just before it went quiet. The request looks like `The system will reboot now!` or `power off now!`.
**Shutdown requested:**
- Dashboard: the host shows as **"rebooting (planned)"** in Needs attention, as an info-level `host_rebooting` event rather than an outage.
- Cluster check: the host doesn't count toward it. Last night's two requested power-offs would no longer add up toward a cluster alert.
- Ticket: only if the host hasn't come back within `planned_reboot_grace` of the shutdown line. The default is 20 minutes, and `planned_reboot_grace_hosts` sets per-host overrides. The ticket is P2 and titled "Planned reboot did not come back", with checks aimed at a host stuck in POST or boot, or left powered off.
**No shutdown line:** alerted exactly as before, on `host_failure_threshold`.
**Loki not configured, unreachable, or erroring:** alerted exactly as before. A failed log query never delays or silences an alert.
## How it's built
- **`reboots.py`:** a Loki client plus `find_shutdown` and `grace_for`. It doesn't touch Gandalf's database or tickets, so thor can take it over unchanged.
- **Loki queries:** one per check per missing host, and only while the host could still be in an ordinary reboot (`host_failure_threshold` checks). The answer is cached until the host returns.
- **Restarts:** a monitor restart in the middle of a reboot still finds the shutdown line, because the lookback covers the whole window.
## Verification
- **Real data:** ran `find_shutdown` from prod against Loki for last month's reboots. All six came out right:
| Reboot | Result |
|---|---|
| micro1 planned, 11-06 | planned (23:17:49) |
| monitor-02 planned, 11-06 | planned (23:25:26) |
| compute-storage-02 planned, 11-18 | planned (20:02:19) |
| compute-storage-02 crash, 11-21 | not planned, alerted as usual |
| compute-storage-01 power off, 11-25 | planned (03:21:38) |
| storage-01 unclean stop, 11-25 | not planned, alerted as usual |
- **Tests:** 678 pass, 23 of them new. They cover planned with no ticket, cluster exclusion, caching, grace expiry, per-host grace, a crash, Loki down, no Loki configured, a monitor restart mid-reboot, and the query window cutoff. The Needs attention entry is tested too.
- flake8 and bandit are clean. No em or en dashes.
## Rollout
Prod's `config.json` needs `"loki": {"url": "http://10.10.10.69:3100"}`. Until it has that, nothing changes. I checked that the Gandalf LXC can query Loki at that address. After the merge I'll back up the config, add the key, and restart gandalf-monitor.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
When a host stops reporting, ask Loki whether its systemd-logind logged a
shutdown request just before. If so, show it as "rebooting (planned)"
instead of an outage, keep it out of the cluster check, and ticket only if
it has not come back within planned_reboot_grace (default 20 min, per host
overrides) as "Planned reboot did not come back". No line, no Loki config,
or a Loki error: alert exactly as before.
Refs #47 (the "unexpected reboot" alert for crashes that recover goes to thor)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Refs #47. This PR covers Gandalf's part. The "unexpected reboot" alert, for crashes that recover inside the window, is host health, so it goes to thor (see the comment on #47).
What changes
When a configured host stops reporting to Prometheus, Gandalf asks Loki whether the host's
systemd-logindlogged a shutdown request just before it went quiet. The request looks likeThe system will reboot now!orpower off now!.Shutdown requested:
host_rebootingevent rather than an outage.planned_reboot_graceof the shutdown line. The default is 20 minutes, andplanned_reboot_grace_hostssets per-host overrides. The ticket is P2 and titled "Planned reboot did not come back", with checks aimed at a host stuck in POST or boot, or left powered off.No shutdown line: alerted exactly as before, on
host_failure_threshold.Loki not configured, unreachable, or erroring: alerted exactly as before. A failed log query never delays or silences an alert.
How it's built
reboots.py: a Loki client plusfind_shutdownandgrace_for. It doesn't touch Gandalf's database or tickets, so thor can take it over unchanged.host_failure_thresholdchecks). The answer is cached until the host returns.Verification
find_shutdownfrom prod against Loki for last month's reboots. All six came out right:Rollout
Prod's
config.jsonneeds"loki": {"url": "http://10.10.10.69:3100"}. Until it has that, nothing changes. I checked that the Gandalf LXC can query Loki at that address. After the merge I'll back up the config, add the key, and restart gandalf-monitor.🤖 Generated with Claude Code