Add AT&T modem monitoring and device pages; replace Link Debug
Lint / Python (flake8) (pull_request) Successful in 2m6s
Lint / JS (eslint) (pull_request) Successful in 18s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m11s
Test / Python Tests (pytest) (pull_request) Successful in 2m20s
Lint / JS (eslint) (push) Successful in 10s
Lint / Python (flake8) (push) Successful in 1m58s
Lint / Notify on failure (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m58s
Lint / Deploy (push) Successful in 4s
Test / Python Tests (pytest) (push) Successful in 58s
Lint / Python (flake8) (pull_request) Successful in 2m6s
Lint / JS (eslint) (pull_request) Successful in 18s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m11s
Test / Python Tests (pytest) (pull_request) Successful in 2m20s
Lint / JS (eslint) (push) Successful in 10s
Lint / Python (flake8) (push) Successful in 1m58s
Lint / Notify on failure (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m58s
Lint / Deploy (push) Successful in 4s
Test / Python Tests (pytest) (push) Successful in 58s
Modem and WAN: - Poll the BGW320 status pages read-only for light levels, PON and WAN state, with a WAN / Fiber panel, 7-day Rx trend, and alerts on WAN down, optical limits, and Rx drift - Read WAN outages and Smart Power restarts from the UniFi system log, since outages can be over between 5 minute polls Device pages: - Add device search to the dashboard and a page per host, switch, router, AP, PDU, or modem - Move all Link Debug data into expandable rows there; /links redirects - Collect UDM ports and UniFi device details (firmware, load, WAN, outlets) - Reorder the dashboard Monitoring fixes: - Alert when a configured host stops reporting: its series disappear rather than reporting down, so a dead host never raised an alert - Alert on Prometheus outages instead of blanking the dashboard - Treat a failed Pulse ping as unknown rather than host unreachable - Stop new switch ports reporting lifetime bytes as one interval's rate - Run database sessions in UTC: other server time zones shifted displayed ages and timed suppression expiries Also log every avatar 404 reason, add a favicon, and correct the WAN link labels (1G on Port 9, not 10G SFP+). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #4.
This commit is contained in:
1 parent
e1716d5228
commit
e32499b7f6
25 files changed
+3120
-821
No files matched your search
+261
-1
@@ -1,4 +1,6 @@
|
||||
'use strict';
|
||||
/* exported initDeviceSearch */
|
||||
/* global DEVICE_NAME */
|
||||
|
||||
// ── Auto-redirect on auth timeout ─────────────────────────────────────
|
||||
// Wraps fetch so a 401 (Authelia session expired) forces a full reload.
|
||||
@@ -40,6 +42,7 @@ async function refreshAll() {
|
||||
const [netResult, statusResult] = await Promise.allSettled([
|
||||
lt.api.get('/api/network'),
|
||||
lt.api.get('/api/status'),
|
||||
refreshModem(),
|
||||
]);
|
||||
if (netResult.status === 'fulfilled') {
|
||||
const net = netResult.value;
|
||||
@@ -170,6 +173,263 @@ function updateTopology(hosts) {
|
||||
});
|
||||
}
|
||||
|
||||
// ── Device search ─────────────────────────────────────────────────────
|
||||
function deviceUrl(name) {
|
||||
return `/device/${encodeURIComponent(name)}`;
|
||||
}
|
||||
|
||||
// All words must match somewhere; the device's name matching ranks first.
|
||||
function rankDevices(devices, query) {
|
||||
const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
||||
if (!words.length) return [];
|
||||
const scored = [];
|
||||
for (const d of devices) {
|
||||
if (!words.every(w => d.search.includes(w))) continue;
|
||||
const name = d.name.toLowerCase();
|
||||
let score = 3;
|
||||
if (name === words[0]) score = 0;
|
||||
else if (name.startsWith(words[0])) score = 1;
|
||||
else if (name.includes(words[0]) || (d.ip || '').startsWith(words[0])) score = 2;
|
||||
scored.push({ d, score });
|
||||
}
|
||||
return scored
|
||||
.sort((a, b) => a.score - b.score || a.d.name.localeCompare(b.d.name))
|
||||
.slice(0, 12)
|
||||
.map(s => s.d);
|
||||
}
|
||||
|
||||
function initDeviceSearch() {
|
||||
const input = document.getElementById('device-search-input');
|
||||
const results = document.getElementById('device-search-results');
|
||||
if (!input || !results) return;
|
||||
let devices = [];
|
||||
let matches = [];
|
||||
let active = 0;
|
||||
|
||||
async function loadDevices() {
|
||||
try {
|
||||
devices = (await lt.api.get('/api/devices')).devices || [];
|
||||
} catch (err) {
|
||||
console.warn('Device list unavailable', err);
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
results.hidden = true;
|
||||
input.setAttribute('aria-expanded', 'false');
|
||||
input.removeAttribute('aria-activedescendant');
|
||||
}
|
||||
|
||||
function render() {
|
||||
matches = rankDevices(devices, input.value);
|
||||
if (!input.value.trim()) { close(); return; }
|
||||
active = Math.min(active, Math.max(matches.length - 1, 0));
|
||||
results.hidden = false;
|
||||
input.setAttribute('aria-expanded', 'true');
|
||||
if (!matches.length) {
|
||||
results.innerHTML = '<div class="device-search-empty">No devices match.</div>';
|
||||
input.removeAttribute('aria-activedescendant');
|
||||
return;
|
||||
}
|
||||
results.innerHTML = matches.map((d, i) => `
|
||||
<a class="device-search-row${i === active ? ' is-active' : ''}" id="device-opt-${i}" role="option"
|
||||
aria-selected="${i === active}" href="${lt.escHtml(deviceUrl(d.name))}">
|
||||
<span class="dot-${lt.escHtml(d.status)}"></span>
|
||||
<span class="device-search-name">${lt.escHtml(d.name)}</span>
|
||||
<span class="device-search-kind">${lt.escHtml(d.kind)}</span>
|
||||
<span class="device-search-meta">${lt.escHtml(d.ip || '')}</span>
|
||||
<span class="device-search-meta">${lt.escHtml(d.model || '')}</span>
|
||||
</a>`).join('');
|
||||
input.setAttribute('aria-activedescendant', `device-opt-${active}`);
|
||||
}
|
||||
|
||||
input.addEventListener('input', () => { active = 0; render(); });
|
||||
input.addEventListener('focus', () => { loadDevices().then(render); });
|
||||
input.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape') { close(); return; }
|
||||
if (!matches.length) return;
|
||||
if (e.key === 'ArrowDown') { e.preventDefault(); active = (active + 1) % matches.length; render(); }
|
||||
if (e.key === 'ArrowUp') { e.preventDefault(); active = (active - 1 + matches.length) % matches.length; render(); }
|
||||
if (e.key === 'Enter') { e.preventDefault(); window.location.href = deviceUrl(matches[active].name); }
|
||||
});
|
||||
document.addEventListener('click', e => {
|
||||
if (!e.target.closest('#device-search')) close();
|
||||
});
|
||||
document.addEventListener('keydown', e => {
|
||||
const typing = e.target.closest('input, textarea, select, [contenteditable]');
|
||||
if (e.key === '/' && !typing && !e.ctrlKey && !e.metaKey) {
|
||||
e.preventDefault();
|
||||
input.focus();
|
||||
}
|
||||
});
|
||||
loadDevices();
|
||||
}
|
||||
|
||||
// ── WAN modem / fiber panel ───────────────────────────────────────────
|
||||
async function refreshModem() {
|
||||
try {
|
||||
updateModem(await lt.api.get('/api/modem'));
|
||||
} catch (err) {
|
||||
console.warn('Modem data unavailable', err);
|
||||
}
|
||||
}
|
||||
|
||||
function _modemUptime(seconds) {
|
||||
if (seconds === null || seconds === undefined) return '–';
|
||||
const d = Math.floor(seconds / 86400);
|
||||
const h = Math.floor((seconds % 86400) / 3600);
|
||||
const m = Math.floor((seconds % 3600) / 60);
|
||||
return d ? `${d}d ${h}h` : `${h}h ${m}m`;
|
||||
}
|
||||
|
||||
function _modemRate(bytesPerSec) {
|
||||
if (bytesPerSec === null || bytesPerSec === undefined) return '–';
|
||||
const mbps = bytesPerSec * 8 / 1e6;
|
||||
return mbps >= 1000 ? `${(mbps / 1000).toFixed(2)} Gbps` : `${mbps.toFixed(1)} Mbps`;
|
||||
}
|
||||
|
||||
function _modemStat(label, value, cls, note) {
|
||||
return `
|
||||
<div class="modem-stat">
|
||||
<span class="modem-stat-label">${lt.escHtml(label)}</span>
|
||||
<span class="modem-stat-value ${cls || ''}">${lt.escHtml(String(value))}</span>
|
||||
${note ? `<span class="modem-stat-note">${lt.escHtml(note)}</span>` : ''}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function _modemOptic(label, metric, status, unit) {
|
||||
if (!metric || metric.value === null || metric.value === undefined) return _modemStat(label, '–');
|
||||
const cls = { alarm: 'lt-text-red', warning: 'lt-text-amber', ok: 'lt-text-green' }[status] || '';
|
||||
return _modemStat(label, `${metric.value} ${unit}`, cls, `warn ${metric.warn_low} to ${metric.warn_high}`);
|
||||
}
|
||||
|
||||
function _modemChart(history) {
|
||||
const points = (history || []).filter(p => p.rx_avg !== null && p.rx_avg !== undefined);
|
||||
if (points.length < 2) {
|
||||
return '<div class="modem-chart-empty">Rx power trend appears after a few polls.</div>';
|
||||
}
|
||||
const W = 600, H = 70, PAD = 4;
|
||||
const values = points.map(p => p.rx_avg);
|
||||
const low = Math.min(...values) - 0.5, high = Math.max(...values) + 0.5;
|
||||
const t0 = points[0].ts, tSpan = (points[points.length - 1].ts - t0) || 1;
|
||||
const coord = p => `${((p.ts - t0) / tSpan * W).toFixed(1)},` +
|
||||
`${(PAD + (high - p.rx_avg) / (high - low) * (H - 2 * PAD)).toFixed(1)}`;
|
||||
|
||||
// Break the line where samples are missing rather than drawing across an outage
|
||||
const gaps = points.slice(1).map((p, i) => p.ts - points[i].ts).sort((a, b) => a - b);
|
||||
const maxGap = gaps[Math.floor(gaps.length / 2)] * 3;
|
||||
const segments = [[]];
|
||||
points.forEach((p, i) => {
|
||||
if (i && p.ts - points[i - 1].ts > maxGap) segments.push([]);
|
||||
segments[segments.length - 1].push(coord(p));
|
||||
});
|
||||
const lines = segments
|
||||
.map(s => `<polyline points="${s.join(' ')}" fill="none" vector-effect="non-scaling-stroke"/>`)
|
||||
.join('');
|
||||
const summary = `range ${Math.min(...values)} to ${Math.max(...values)} dBm`;
|
||||
return `
|
||||
<div class="modem-chart">
|
||||
<div class="modem-chart-title">Rx power, last 7 days <span>${lt.escHtml(summary)}</span></div>
|
||||
<svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" role="img"
|
||||
aria-label="Rx power trend, ${lt.escHtml(summary)}">${lines}</svg>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function _modemWhen(epochSeconds) {
|
||||
return new Date(epochSeconds * 1000).toLocaleString([], { dateStyle: 'short', timeStyle: 'short' });
|
||||
}
|
||||
|
||||
function _modemLastRestart(history) {
|
||||
const restarts = (history && history.restarts) || [];
|
||||
if (!restarts.length) return '';
|
||||
const last = restarts[restarts.length - 1];
|
||||
return `restarted ${_modemWhen(last.at)}${last.by ? ` by ${last.by}` : ''}`;
|
||||
}
|
||||
|
||||
function _modemDuration(seconds) {
|
||||
if (seconds < 60) return `${Math.round(seconds)}s`;
|
||||
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${Math.round(seconds % 60)}s`;
|
||||
return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`;
|
||||
}
|
||||
|
||||
function _modemOutages(history) {
|
||||
const outages = ((history && history.outages) || []).slice(-5).reverse();
|
||||
if (!outages.length) return '';
|
||||
const rows = outages.map(o => {
|
||||
const length = o.restored_at === null || o.restored_at === undefined
|
||||
? '<span class="lt-text-red">ongoing</span>'
|
||||
: lt.escHtml(_modemDuration(o.restored_at - o.failed_at));
|
||||
return `<li><span>${lt.escHtml(_modemWhen(o.failed_at))}</span><span>${length}</span></li>`;
|
||||
}).join('');
|
||||
return `
|
||||
<div class="modem-outages">
|
||||
<div class="modem-chart-title">Recent WAN outages</div>
|
||||
<ul>${rows}</ul>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function updateModem(data) {
|
||||
const section = document.getElementById('modem-section');
|
||||
const body = document.getElementById('modem-body');
|
||||
if (!section || !body) return;
|
||||
section.hidden = !data.configured;
|
||||
if (!data.configured) return;
|
||||
|
||||
// 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) {
|
||||
detailsLink.href = deviceUrl(data.name);
|
||||
detailsLink.hidden = false;
|
||||
}
|
||||
|
||||
const rxLabel = document.getElementById('topo-modem-rx');
|
||||
const topo = document.getElementById('topo-modem');
|
||||
const title = document.getElementById('modem-title');
|
||||
|
||||
if (!data.reachable) {
|
||||
if (rxLabel) rxLabel.textContent = 'unreachable';
|
||||
if (topo) topo.classList.add('topo-v2-status-down');
|
||||
body.innerHTML = `
|
||||
<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>
|
||||
${_modemChart(data.history)}`;
|
||||
return;
|
||||
}
|
||||
|
||||
const problems = data.wan_problems || [];
|
||||
const optics = data.optics || {};
|
||||
const status = data.optics_status || {};
|
||||
const counters = data.counters || {};
|
||||
const rates = data.rates || {};
|
||||
const rx = optics.rx_power ? optics.rx_power.value : null;
|
||||
|
||||
if (topo) topo.classList.toggle('topo-v2-status-down', problems.length > 0);
|
||||
if (rxLabel) rxLabel.textContent = (rx === null || rx === undefined) ? 'Rx –' : `Rx ${rx} dBm`;
|
||||
if (title) {
|
||||
title.textContent = [data.model || 'AT&T Gateway', data.firmware && `fw ${data.firmware}`]
|
||||
.filter(Boolean).join(' · ');
|
||||
}
|
||||
|
||||
const errs = (counters.rx_errors || 0) + (counters.tx_errors || 0);
|
||||
const drops = (counters.rx_drops || 0) + (counters.tx_drops || 0);
|
||||
body.innerHTML = `
|
||||
${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',
|
||||
data.wan_ip || '')}
|
||||
${_modemStat('PON', data.pon_state || '–', '', data.wavelength || '')}
|
||||
${_modemOptic('Rx power', optics.rx_power, status.rx_power, 'dBm')}
|
||||
${_modemOptic('Tx power', optics.tx_power, status.tx_power, 'dBm')}
|
||||
${_modemOptic('Optics temp', optics.temperature, status.temperature, '°C')}
|
||||
${_modemStat('Throughput', `↓ ${_modemRate(rates.rx_bytes)}`, '', `↑ ${_modemRate(rates.tx_bytes)}`)}
|
||||
${_modemStat('Errors / drops', `${errs} / ${drops}`, errs ? 'lt-text-amber' : '', 'since modem reboot')}
|
||||
${_modemStat('Uptime', _modemUptime(data.uptime_s), '', _modemLastRestart(data.wan_history))}
|
||||
</div>
|
||||
${_modemChart(data.history)}
|
||||
${_modemOutages(data.wan_history)}
|
||||
<div class="modem-stat-note modem-updated">Updated ${lt.escHtml(data.updated || '–')}</div>`;
|
||||
}
|
||||
|
||||
function updateUnifiTable(devices) {
|
||||
const tbody = document.querySelector('#unifi-table tbody');
|
||||
if (!tbody || !devices.length) return;
|
||||
@@ -188,7 +448,7 @@ function updateUnifiTable(devices) {
|
||||
return `
|
||||
<tr class="${statusClass}">
|
||||
<td><span class="${dotClass}"></span> ${statusText}</td>
|
||||
<td><strong>${lt.escHtml(d.name)}</strong></td>
|
||||
<td><a class="device-link" href="${lt.escHtml(deviceUrl(d.name))}"><strong>${lt.escHtml(d.name)}</strong></a></td>
|
||||
<td>${lt.escHtml(d.type)}</td>
|
||||
<td>${lt.escHtml(d.model)}</td>
|
||||
<td>${lt.escHtml(d.ip)}</td>
|
||||
|
||||
Reference in new issue
Block a user