The internet degrades a day or two after each modem reboot. Restarting it safely means silencing Gandalf and Uptime Kuma first and remembering to switch them back on. This puts all three steps behind one admin button.
What
Restart modem button (admins only, WAN / Fiber panel, shown when modem.access_code is set). After a confirmation it does three things in order:
Uptime Kuma maintenance on. The new kuma.py logs in over Kuma 2's Socket.IO API and resumes one pre-made manual maintenance window (uptime_kuma.maintenance_id). It changes nothing else in Kuma. If Kuma fails, the button stops and asks whether to go on without it.
Gandalf maintenance on: a global suppression for 20 minutes at most, shown in the usual banner.
Restart: ModemAdmin.restart() posts the gateway's Restart Device form. If that fails, steps 1 and 2 are undone.
Monitor (_finish_modem_restart): waits until the modem answers with its WAN up and an uptime showing it really restarted (at least 3 minutes after the request). It then switches the Kuma window off, ends the suppression, and records how long it took in monitor_state.modem_restart. If the Kuma call fails, it retries the next cycle. After 30 minutes it ends both regardless.
Panel: shows "Restart requested by ..." while the restart is in progress, then "back after 4m 10s" for an hour. Only one restart can run at a time (409).
Docs and dependencies: README (config keys, the button) and a new dependency, python-socketio[client], which the deploy script installs from requirements.txt. The uptime-kuma-api library doesn't work with Kuma 2 (it waits for a version field that Kuma 2 no longer sends before login), so this uses python-socketio directly.
## Why
The internet degrades a day or two after each modem reboot. Restarting it safely means silencing Gandalf and Uptime Kuma first and remembering to switch them back on. This puts all three steps behind one admin button.
## What
- **Restart modem button** (admins only, WAN / Fiber panel, shown when `modem.access_code` is set). After a confirmation it does three things in order:
1. **Uptime Kuma maintenance on.** The new `kuma.py` logs in over Kuma 2's Socket.IO API and resumes one pre-made *manual* maintenance window (`uptime_kuma.maintenance_id`). It changes nothing else in Kuma. If Kuma fails, the button stops and asks whether to go on without it.
2. **Gandalf maintenance on**: a global suppression for 20 minutes at most, shown in the usual banner.
3. **Restart**: `ModemAdmin.restart()` posts the gateway's Restart Device form. If that fails, steps 1 and 2 are undone.
- **Monitor** (`_finish_modem_restart`): waits until the modem answers with its WAN up and an uptime showing it really restarted (at least 3 minutes after the request). It then switches the Kuma window off, ends the suppression, and records how long it took in `monitor_state.modem_restart`. If the Kuma call fails, it retries the next cycle. After 30 minutes it ends both regardless.
- **Panel**: shows "Restart requested by ..." while the restart is in progress, then "back after 4m 10s" for an hour. Only one restart can run at a time (409).
- **Docs and dependencies**: README (config keys, the button) and a new dependency, `python-socketio[client]`, which the deploy script installs from requirements.txt. The `uptime-kuma-api` library doesn't work with Kuma 2 (it waits for a version field that Kuma 2 no longer sends before login), so this uses `python-socketio` directly.
## Setup already done
- Kuma maintenance window **#7 "Gandalf: modem restart"**: manual strategy, all 49 monitors, paused.
- Still needed: a Kuma account in prod `config.json` under `uptime_kuma`, which the admin adds by hand.
## Checks
- 599 tests pass. New ones cover:
- Kuma: login, two-factor, refusals, unreachable.
- Modem restart: the form post, a dropped connection, a refusal.
- The route: admin only, confirm, needs the code, the order of steps, the Kuma failure path, rollback, one at a time.
- The monitor's finish logic: back, still down, too soon, not rebooted, give up, Kuma retry.
- flake8 and bandit are clean; eslint is at the 21-warning baseline.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Admins get a Restart modem button on the WAN / Fiber panel (needs
modem.access_code). After a confirmation it:
1. switches an Uptime Kuma maintenance window on (new kuma.py: logs in
over Kuma 2's Socket.IO API and resumes/pauses one pre-made manual
window, uptime_kuma.maintenance_id); if Kuma fails it stops and asks
whether to go on without it,
2. starts Gandalf maintenance (global suppression, 20 minutes at most),
3. posts the gateway's Restart Device form (ModemAdmin.restart), undoing
1 and 2 if that fails.
The monitor waits for the modem to answer with its WAN up and an uptime
showing it restarted, then switches Kuma off, ends the suppression and
records how long it took; after 30 minutes it ends both regardless. The
panel shows the restart in progress and the result for an hour.
New dependency: python-socketio[client].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tried on the real BGW320 (firmware 6.40.4): posting the Restart form only
answers 302 to /cgi-bin/restarting.ha, and the modem keeps running (its
uptime carried on). Loading that page, as a browser does, starts the
restart ("restarting ... approximately 155 seconds"). restart() now
follows the redirect and only reports 'accepted' when that page says it
is restarting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found while restarting the real modem (approved), and fixed in 3afd856:
On firmware 6.40.4, posting the Restart form only answers 302 -> /cgi-bin/restarting.ha. The modem kept running: its uptime carried on at 3 days 7 hours. Loading restarting.ha, as a browser does, is what starts the restart ("restarting ... approximately 155 seconds"). restart() now follows that redirect and reports accepted only when the page says it is restarting. A redirect without the restart now raises an error, so the button undoes the silence instead of reporting success.
Result of the restart (at about 00:37 UTC):
1.1.1.1: 1,154 ms average before, 17 ms after, with 0% loss.
Found while restarting the real modem (approved), and fixed in 3afd856:
On firmware 6.40.4, posting the Restart form only answers `302 -> /cgi-bin/restarting.ha`. The modem kept running: its uptime carried on at 3 days 7 hours. Loading `restarting.ha`, as a browser does, is what starts the restart ("restarting ... approximately 155 seconds"). `restart()` now follows that redirect and reports `accepted` only when the page says it is restarting. A redirect without the restart now raises an error, so the button undoes the silence instead of reporting success.
Result of the restart (at about 00:37 UTC):
- 1.1.1.1: 1,154 ms average before, 17 ms after, with 0% loss.
- Modem: 2.7 ms.
600 tests pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared
scheduled this pull request to auto merge when all checks succeed 2026-11-19 20:39:02 -05:00
jared
merged commit dd9ba41479 into main2026-11-19 20:39:04 -05:00
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.
Why
The internet degrades a day or two after each modem reboot. Restarting it safely means silencing Gandalf and Uptime Kuma first and remembering to switch them back on. This puts all three steps behind one admin button.
What
modem.access_codeis set). After a confirmation it does three things in order:kuma.pylogs in over Kuma 2's Socket.IO API and resumes one pre-made manual maintenance window (uptime_kuma.maintenance_id). It changes nothing else in Kuma. If Kuma fails, the button stops and asks whether to go on without it.ModemAdmin.restart()posts the gateway's Restart Device form. If that fails, steps 1 and 2 are undone._finish_modem_restart): waits until the modem answers with its WAN up and an uptime showing it really restarted (at least 3 minutes after the request). It then switches the Kuma window off, ends the suppression, and records how long it took inmonitor_state.modem_restart. If the Kuma call fails, it retries the next cycle. After 30 minutes it ends both regardless.python-socketio[client], which the deploy script installs from requirements.txt. Theuptime-kuma-apilibrary doesn't work with Kuma 2 (it waits for a version field that Kuma 2 no longer sends before login), so this usespython-socketiodirectly.Setup already done
config.jsonunderuptime_kuma, which the admin adds by hand.Checks
🤖 Generated with Claude Code
Tried on the real BGW320 (firmware 6.40.4): posting the Restart form only answers 302 to /cgi-bin/restarting.ha, and the modem keeps running (its uptime carried on). Loading that page, as a browser does, starts the restart ("restarting ... approximately 155 seconds"). restart() now follows the redirect and only reports 'accepted' when that page says it is restarting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>Found while restarting the real modem (approved), and fixed in
3afd856:On firmware 6.40.4, posting the Restart form only answers
302 -> /cgi-bin/restarting.ha. The modem kept running: its uptime carried on at 3 days 7 hours. Loadingrestarting.ha, as a browser does, is what starts the restart ("restarting ... approximately 155 seconds").restart()now follows that redirect and reportsacceptedonly when the page says it is restarting. A redirect without the restart now raises an error, so the button undoes the silence instead of reporting success.Result of the restart (at about 00:37 UTC):
600 tests pass.
🤖 Generated with Claude Code