Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49869fd9f7 | |||
| c68e797f31 |
@@ -291,7 +291,7 @@ def api_links():
|
||||
return jsonify(json.loads(raw))
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to parse link_stats JSON: {e}')
|
||||
return jsonify({'hosts': {}, 'updated': None})
|
||||
return jsonify({'hosts': {}, 'unifi_switches': {}, 'updated': None})
|
||||
|
||||
|
||||
@app.route('/api/events')
|
||||
|
||||
@@ -221,8 +221,6 @@ class DiagnosticsRunner:
|
||||
data['auto_neg'] = (val.lower() == 'on')
|
||||
elif key == 'Link detected':
|
||||
data['link_detected'] = (val.lower() == 'yes')
|
||||
elif 'Supported link modes' in key:
|
||||
data.setdefault('supported_modes', []).append(val)
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -217,6 +217,7 @@
|
||||
.sev-pills { display: flex; gap: 4px; }
|
||||
.g-page-sub { font-size: .78em; color: var(--text-muted); margin-top: 4px; }
|
||||
.g-page-sub-aside { font-size: .78em; color: var(--text-muted); margin-left: 8px; }
|
||||
.g-stale-warn { color: var(--orange); font-weight: 600; }
|
||||
|
||||
/* ── Badge severity color variants (used with lt-badge) ───────────── */
|
||||
.badge-critical { color: var(--red); border-color: var(--red); text-shadow: var(--glow-red); }
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
<div id="events-table-wrap">
|
||||
{% if events %}
|
||||
{% if total_active is defined and total_active > events|length %}
|
||||
<div class="pagination-notice">Showing {{ events|length }} of {{ total_active }} active alerts — <a href="/api/events?limit=1000">view all via API</a></div>
|
||||
<div class="pagination-notice">Showing {{ events|length }} of {{ total_active }} active alerts — use the search box to filter, or <a href="/api/events?limit=1000" target="_blank" rel="noopener">export all as JSON</a></div>
|
||||
{% endif %}
|
||||
<div class="lt-table-wrap">
|
||||
<table class="lt-table" id="events-table">
|
||||
|
||||
@@ -428,7 +428,14 @@ function renderInspector(data) {
|
||||
|
||||
const updEl = document.getElementById('inspector-updated');
|
||||
if (updEl && data.updated) {
|
||||
updEl.textContent = 'Updated: ' + new Date(data.updated + (data.updated.includes('Z') ? '' : 'Z')).toLocaleTimeString();
|
||||
const updMs = new Date(data.updated + (data.updated.includes('Z') ? '' : 'Z'));
|
||||
const ageMin = (Date.now() - updMs) / 60000;
|
||||
const timeStr = updMs.toLocaleTimeString();
|
||||
if (ageMin > 15) {
|
||||
updEl.innerHTML = `<span class="g-stale-warn" title="Data is ${Math.floor(ageMin)} minutes old — monitor may be down">⚠ Stale: ${timeStr}</span>`;
|
||||
} else {
|
||||
updEl.textContent = 'Updated: ' + timeStr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Object.keys(switches).length) {
|
||||
@@ -487,7 +494,13 @@ document.addEventListener('click', e => {
|
||||
if (diagBtn) { runDiagnostic(diagBtn.dataset.sw, parseInt(diagBtn.dataset.idx, 10)); return; }
|
||||
|
||||
const toggleDiag = e.target.closest('[data-action="toggle-diag"]');
|
||||
if (toggleDiag) { toggleDiag.parentElement.classList.toggle('diag-open'); return; }
|
||||
if (toggleDiag) {
|
||||
const section = toggleDiag.parentElement;
|
||||
const nowOpen = section.classList.toggle('diag-open');
|
||||
const hint = toggleDiag.querySelector('.diag-toggle-hint');
|
||||
if (hint) hint.textContent = nowOpen ? '[collapse]' : '[expand]';
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// ── Link Diagnostics ─────────────────────────────────────────────────
|
||||
@@ -510,7 +523,10 @@ function runDiagnostic(swName, portIdx) {
|
||||
pollDiagnostic(resp.job_id, statusEl, resultsEl);
|
||||
})
|
||||
.catch(e => {
|
||||
statusEl.textContent = 'Error: ' + (e.message || 'Request failed');
|
||||
const msg = (e && e.status === 429)
|
||||
? 'Rate limit reached — max 5 diagnostics per minute. Please wait.'
|
||||
: 'Error: ' + (e && e.message || 'Request failed');
|
||||
statusEl.textContent = msg;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -520,7 +536,13 @@ function pollDiagnostic(jobId, statusEl, resultsEl) {
|
||||
attempts++;
|
||||
if (attempts > 120) { // 2min timeout
|
||||
clearInterval(_diagPollTimer);
|
||||
statusEl.textContent = 'Timed out waiting for results.';
|
||||
_diagPollTimer = null;
|
||||
statusEl.innerHTML = 'Timed out waiting for results. '
|
||||
+ '<button class="lt-btn lt-btn-ghost lt-btn-sm" id="diag-retry-btn">Retry</button>';
|
||||
document.getElementById('diag-retry-btn')?.addEventListener('click', () => {
|
||||
const sel = document.querySelector('.switch-port-block.selected');
|
||||
if (sel) runDiagnostic(sel.dataset.switch, parseInt(sel.dataset.portIdx));
|
||||
});
|
||||
return;
|
||||
}
|
||||
lt.api.get(`/api/diagnose/${jobId}`)
|
||||
@@ -535,7 +557,12 @@ function pollDiagnostic(jobId, statusEl, resultsEl) {
|
||||
.catch(() => {
|
||||
clearInterval(_diagPollTimer);
|
||||
_diagPollTimer = null;
|
||||
statusEl.textContent = 'Error: lost connection while collecting diagnostics.';
|
||||
statusEl.innerHTML = 'Error: lost connection while collecting diagnostics. '
|
||||
+ '<button class="lt-btn lt-btn-ghost lt-btn-sm" id="diag-retry-btn">Retry</button>';
|
||||
document.getElementById('diag-retry-btn')?.addEventListener('click', () => {
|
||||
const sel = document.querySelector('.switch-port-block.selected');
|
||||
if (sel) runDiagnostic(sel.dataset.switch, parseInt(sel.dataset.portIdx));
|
||||
});
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user