Restart modem button: silence Gandalf and Uptime Kuma, restart, end both
Lint / Python (flake8) (push) Failing after 15s
Lint / JS (eslint) (push) Successful in 1m43s
Lint / Deploy (push) Skipped
Test / Python Tests (pytest) (push) Failing after 21s
Security / Python Security (bandit) (push) Successful in 2m3s
Lint / Python (flake8) (pull_request) Failing after 15s
Lint / JS (eslint) (pull_request) Failing after 15s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m17s
Lint / Notify on failure (push) Successful in 3s
Test / Python Tests (pytest) (pull_request) Successful in 2m58s

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>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-19 19:27:25 -05:00
1 parent f097e4882c
commit c2ff072eb2
13 files changed
+488 -10

No files matched your search

+55 -2
View File
@@ -470,6 +470,47 @@ function _modemQuality(q) {
</div>`;
}
// A restart from the Restart modem button: in progress, or finished in the last hour
function _modemRestartNote(r) {
if (!r || !r.at) return '';
const who = r.by ? ` by ${r.by}` : '';
if (!r.finished_at) {
return `<div class="modem-restart-note">Restart requested${lt.escHtml(who)} ${lt.escHtml(_modemWhen(r.at))}. ` +
`Alerts are silenced${r.kuma ? ' here and in Uptime Kuma' : ''} until the modem is back.</div>`;
}
if (Date.now() / 1000 - r.finished_at > 3600) return '';
const how = r.back ? `back after ${_modemDuration(r.back_after_s)}` : 'did not come back within 30 minutes';
return `<div class="modem-restart-note">Restarted${lt.escHtml(who)} ${lt.escHtml(_modemWhen(r.at))}: ` +
`${lt.escHtml(how)}. Alerts are on again.</div>`;
}
async function restartModem(btn) {
const msg = 'Restart the AT&T modem?\n\nThe internet will be down for about 3 to 5 minutes. ' +
'Gandalf alerts and the Uptime Kuma maintenance window are switched on first, and switched off ' +
'again when the modem is back.';
if (!window.confirm(msg)) return;
btn.disabled = true;
try {
let res;
try {
res = await lt.api.post('/api/modem/restart', { confirm: true });
} catch (err) {
if (!String(err.message).startsWith('Uptime Kuma:')) throw err;
if (!window.confirm(`${err.message}\n\nRestart anyway? Uptime Kuma will report the outage.`)) {
btn.disabled = false;
return;
}
res = await lt.api.post('/api/modem/restart', { confirm: true, without_kuma: true });
}
showToast(res.result === 'accepted' ? 'Modem restarting' : 'Restart sent; the modem dropped the connection',
'success');
window.location.reload();
} catch (err) {
btn.disabled = false;
showToast(err.message || 'Could not restart the modem', 'error');
}
}
function updateModem(data) {
const section = document.getElementById('modem-section');
const body = document.getElementById('modem-body');
@@ -477,6 +518,18 @@ function updateModem(data) {
section.hidden = !data.configured;
if (!data.configured) return;
const restartBtn = document.getElementById('modem-restart-btn');
if (restartBtn) {
const pending = data.modem_restart && !data.modem_restart.finished_at;
restartBtn.hidden = !data.can_restart;
restartBtn.disabled = Boolean(pending);
if (!restartBtn.dataset.bound) {
restartBtn.dataset.bound = '1';
restartBtn.addEventListener('click', () => restartModem(restartBtn));
}
}
const restartNote = _modemRestartNote(data.modem_restart);
// On the dashboard, link to the modem's page. On that page, it would link to itself.
const detailsLink = document.getElementById('modem-device-link');
if (detailsLink && typeof DEVICE_NAME === 'undefined' && data.name) {
@@ -487,7 +540,7 @@ function updateModem(data) {
const title = document.getElementById('modem-title');
if (!data.reachable) {
body.innerHTML = `
body.innerHTML = `${restartNote}
<div class="modem-error">Modem status unavailable: ${lt.escHtml(data.error || 'unknown error')}
<span class="modem-stat-note">Last attempt ${lt.escHtml(data.updated || '-')}</span></div>
${_modemQuality(data.wan_quality)}
@@ -508,7 +561,7 @@ function updateModem(data) {
const errs = (counters.rx_errors || 0) + (counters.tx_errors || 0);
const drops = (counters.rx_drops || 0) + (counters.tx_drops || 0);
body.innerHTML = `
body.innerHTML = `${restartNote}
${problems.length ? `<div class="modem-error">WAN down: ${lt.escHtml(problems.join('; '))}</div>` : ''}
<div class="modem-stats">
${_modemStat('WAN', problems.length ? 'DOWN' : 'UP', problems.length ? 'lt-text-red' : 'lt-text-green',