Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c0e59cfa9e | |||
| 7ab85cd055 |
@@ -73,8 +73,8 @@ def _purge_old_jobs_loop():
|
|||||||
for jid, j in list(_diag_jobs.items()):
|
for jid, j in list(_diag_jobs.items()):
|
||||||
if j['status'] == 'running' and j.get('created_at', 0) < stuck_cutoff:
|
if j['status'] == 'running' and j.get('created_at', 0) < stuck_cutoff:
|
||||||
j['status'] = 'done'
|
j['status'] = 'done'
|
||||||
j['result'] = {'status': 'error', 'error': 'Diagnostic timed out (thread crash)'}
|
j['result'] = {'status': 'error', 'error': 'Diagnostic abandoned — no activity for 5 minutes.'}
|
||||||
logger.error(f'Diagnostic job {jid} appeared stuck; marked as errored')
|
logger.error(f'Diagnostic job {jid} stuck (no activity for 5 min); marked done/error')
|
||||||
|
|
||||||
|
|
||||||
_purge_thread = threading.Thread(target=_purge_old_jobs_loop, daemon=True)
|
_purge_thread = threading.Thread(target=_purge_old_jobs_loop, daemon=True)
|
||||||
@@ -143,12 +143,31 @@ def require_auth(f):
|
|||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Page routes
|
# Helpers
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
_PAGE_LIMIT = 200 # max events returned per request
|
_PAGE_LIMIT = 200 # max events returned per request
|
||||||
|
|
||||||
|
|
||||||
|
def _annotate_suppressions(events: list, suppressions: list) -> None:
|
||||||
|
"""Annotate each event dict in-place with an is_suppressed bool."""
|
||||||
|
for ev in events:
|
||||||
|
sup_type = (
|
||||||
|
'unifi_device' if ev.get('event_type') == 'unifi_device_offline'
|
||||||
|
else 'interface' if ev.get('event_type') == 'interface_down'
|
||||||
|
else 'host'
|
||||||
|
)
|
||||||
|
ev['is_suppressed'] = db.check_suppressed(
|
||||||
|
suppressions, sup_type,
|
||||||
|
ev.get('target_name', ''), ev.get('target_detail', '') or '',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Page routes
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@require_auth
|
@require_auth
|
||||||
def index():
|
def index():
|
||||||
@@ -160,16 +179,7 @@ def index():
|
|||||||
last_check = db.get_state('last_check', 'Never')
|
last_check = db.get_state('last_check', 'Never')
|
||||||
snapshot = json.loads(snapshot_raw) if snapshot_raw else {}
|
snapshot = json.loads(snapshot_raw) if snapshot_raw else {}
|
||||||
suppressions = db.get_active_suppressions()
|
suppressions = db.get_active_suppressions()
|
||||||
for ev in events:
|
_annotate_suppressions(events, suppressions)
|
||||||
sup_type = (
|
|
||||||
'unifi_device' if ev.get('event_type') == 'unifi_device_offline'
|
|
||||||
else 'interface' if ev.get('event_type') == 'interface_down'
|
|
||||||
else 'host'
|
|
||||||
)
|
|
||||||
ev['is_suppressed'] = db.check_suppressed(
|
|
||||||
suppressions, sup_type,
|
|
||||||
ev.get('target_name', ''), ev.get('target_detail', '') or '',
|
|
||||||
)
|
|
||||||
recent_resolved = db.get_recent_resolved(hours=24, limit=10)
|
recent_resolved = db.get_recent_resolved(hours=24, limit=10)
|
||||||
return render_template(
|
return render_template(
|
||||||
'index.html',
|
'index.html',
|
||||||
@@ -225,16 +235,7 @@ def suppressions_page():
|
|||||||
def api_status():
|
def api_status():
|
||||||
active = db.get_active_events(limit=_PAGE_LIMIT)
|
active = db.get_active_events(limit=_PAGE_LIMIT)
|
||||||
suppressions = db.get_active_suppressions()
|
suppressions = db.get_active_suppressions()
|
||||||
for ev in active:
|
_annotate_suppressions(active, suppressions)
|
||||||
sup_type = (
|
|
||||||
'unifi_device' if ev.get('event_type') == 'unifi_device_offline'
|
|
||||||
else 'interface' if ev.get('event_type') == 'interface_down'
|
|
||||||
else 'host'
|
|
||||||
)
|
|
||||||
ev['is_suppressed'] = db.check_suppressed(
|
|
||||||
suppressions, sup_type,
|
|
||||||
ev.get('target_name', ''), ev.get('target_detail', '') or '',
|
|
||||||
)
|
|
||||||
last_check = db.get_state('last_check', 'Never')
|
last_check = db.get_state('last_check', 'Never')
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'summary': db.get_status_summary(),
|
'summary': db.get_status_summary(),
|
||||||
|
|||||||
@@ -214,8 +214,6 @@
|
|||||||
padding: 1px 7px;
|
padding: 1px 7px;
|
||||||
}
|
}
|
||||||
.g-section-actions { margin-left: auto; }
|
.g-section-actions { margin-left: auto; }
|
||||||
.events-filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
||||||
.events-filter-bar .lt-input-sm { width: 220px; }
|
|
||||||
.sev-pills { display: flex; gap: 4px; }
|
.sev-pills { display: flex; gap: 4px; }
|
||||||
.g-page-sub { font-size: .78em; color: var(--text-muted); margin-top: 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-page-sub-aside { font-size: .78em; color: var(--text-muted); margin-left: 8px; }
|
||||||
|
|||||||
+29
-29
@@ -324,7 +324,7 @@
|
|||||||
lt.init({ bootName: 'GANDALF' });
|
lt.init({ bootName: 'GANDALF' });
|
||||||
|
|
||||||
// Theme toggle
|
// Theme toggle
|
||||||
var themeBtn = document.getElementById('lt-theme-btn');
|
const themeBtn = document.getElementById('lt-theme-btn');
|
||||||
if (themeBtn) themeBtn.addEventListener('click', function() { lt.theme.toggle(); });
|
if (themeBtn) themeBtn.addEventListener('click', function() { lt.theme.toggle(); });
|
||||||
|
|
||||||
// Command palette
|
// Command palette
|
||||||
@@ -343,9 +343,9 @@
|
|||||||
|
|
||||||
// ── Global footer + key actions ───────────────────────────────────────
|
// ── Global footer + key actions ───────────────────────────────────────
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function(e) {
|
||||||
var btn = e.target.closest('[data-action]');
|
const btn = e.target.closest('[data-action]');
|
||||||
if (!btn) return;
|
if (!btn) return;
|
||||||
var action = btn.getAttribute('data-action');
|
const action = btn.getAttribute('data-action');
|
||||||
if (action === 'show-keyboard-help' && window.lt) lt.modal.open('lt-keys-help');
|
if (action === 'show-keyboard-help' && window.lt) lt.modal.open('lt-keys-help');
|
||||||
if (action === 'open-settings' && window.lt) lt.modal.open('lt-settings-modal');
|
if (action === 'open-settings' && window.lt) lt.modal.open('lt-settings-modal');
|
||||||
});
|
});
|
||||||
@@ -366,8 +366,8 @@
|
|||||||
|
|
||||||
// ── Settings modal ────────────────────────────────────────────────────
|
// ── Settings modal ────────────────────────────────────────────────────
|
||||||
(function() {
|
(function() {
|
||||||
var LS_KEY = 'gandalf_settings';
|
const LS_KEY = 'gandalf_settings';
|
||||||
var DEFAULT = { refreshInterval: 30 };
|
const DEFAULT = { refreshInterval: 30 };
|
||||||
|
|
||||||
function loadSettings() {
|
function loadSettings() {
|
||||||
try { return Object.assign({}, DEFAULT, JSON.parse(localStorage.getItem(LS_KEY) || '{}')); }
|
try { return Object.assign({}, DEFAULT, JSON.parse(localStorage.getItem(LS_KEY) || '{}')); }
|
||||||
@@ -381,11 +381,11 @@
|
|||||||
|
|
||||||
function applyRefreshPillUI(interval) {
|
function applyRefreshPillUI(interval) {
|
||||||
document.querySelectorAll('#settings-refresh-pills .pill').forEach(function(p) {
|
document.querySelectorAll('#settings-refresh-pills .pill').forEach(function(p) {
|
||||||
var isActive = parseInt(p.dataset.refreshInterval) === interval;
|
const isActive = parseInt(p.dataset.refreshInterval) === interval;
|
||||||
p.classList.toggle('active', isActive);
|
p.classList.toggle('active', isActive);
|
||||||
p.setAttribute('aria-pressed', isActive ? 'true' : 'false');
|
p.setAttribute('aria-pressed', isActive ? 'true' : 'false');
|
||||||
});
|
});
|
||||||
var hint = document.getElementById('settings-refresh-hint');
|
const hint = document.getElementById('settings-refresh-hint');
|
||||||
if (hint) {
|
if (hint) {
|
||||||
if (interval === 0) hint.textContent = 'Auto-refresh disabled.';
|
if (interval === 0) hint.textContent = 'Auto-refresh disabled.';
|
||||||
else if (interval < 60) hint.textContent = 'Refreshes every ' + interval + ' seconds.';
|
else if (interval < 60) hint.textContent = 'Refreshes every ' + interval + ' seconds.';
|
||||||
@@ -394,16 +394,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init pill UI from saved settings
|
// Init pill UI from saved settings
|
||||||
var _settings = loadSettings();
|
const _settings = loadSettings();
|
||||||
applyRefreshPillUI(_settings.refreshInterval);
|
applyRefreshPillUI(_settings.refreshInterval);
|
||||||
|
|
||||||
// Expose for pages that need to read it (e.g. index.html for autoRefresh)
|
// Expose for pages that need to read it (e.g. index.html for autoRefresh)
|
||||||
window.gandalfSettings = _settings;
|
window.gandalfSettings = _settings;
|
||||||
|
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function(e) {
|
||||||
var pill = e.target.closest('#settings-refresh-pills .pill[data-refresh-interval]');
|
const pill = e.target.closest('#settings-refresh-pills .pill[data-refresh-interval]');
|
||||||
if (!pill) return;
|
if (!pill) return;
|
||||||
var interval = parseInt(pill.dataset.refreshInterval);
|
const interval = parseInt(pill.dataset.refreshInterval);
|
||||||
_settings.refreshInterval = interval;
|
_settings.refreshInterval = interval;
|
||||||
saveSettings(_settings);
|
saveSettings(_settings);
|
||||||
applyRefreshPillUI(interval);
|
applyRefreshPillUI(interval);
|
||||||
@@ -412,16 +412,16 @@
|
|||||||
|
|
||||||
// ── Notification Bell — shows active monitoring alerts ────────────────
|
// ── Notification Bell — shows active monitoring alerts ────────────────
|
||||||
(function() {
|
(function() {
|
||||||
var bell = document.getElementById('lt-notif-bell');
|
const bell = document.getElementById('lt-notif-bell');
|
||||||
var panel = document.getElementById('lt-notif-panel');
|
const panel = document.getElementById('lt-notif-panel');
|
||||||
var list = document.getElementById('lt-notif-list');
|
const list = document.getElementById('lt-notif-list');
|
||||||
var clearBtn = document.getElementById('lt-notif-clear-btn');
|
const clearBtn = document.getElementById('lt-notif-clear-btn');
|
||||||
var wrapEl = document.getElementById('lt-notif-wrap');
|
const wrapEl = document.getElementById('lt-notif-wrap');
|
||||||
if (!bell || !panel) return;
|
if (!bell || !panel) return;
|
||||||
|
|
||||||
var _open = false;
|
let _open = false;
|
||||||
var _lastEvents = [];
|
let _lastEvents = [];
|
||||||
var LS_READ_KEY = 'gandalf_notif_read_before';
|
const LS_READ_KEY = 'gandalf_notif_read_before';
|
||||||
|
|
||||||
function getReadBefore() {
|
function getReadBefore() {
|
||||||
try { return parseInt(localStorage.getItem(LS_READ_KEY) || '0'); } catch(_) { return 0; }
|
try { return parseInt(localStorage.getItem(LS_READ_KEY) || '0'); } catch(_) { return 0; }
|
||||||
@@ -440,20 +440,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fmtAgo(dateStr) {
|
function fmtAgo(dateStr) {
|
||||||
var diff = Math.floor((Date.now() - toMs(dateStr)) / 1000);
|
const diff = Math.floor((Date.now() - toMs(dateStr)) / 1000);
|
||||||
if (diff < 60) return diff + 's ago';
|
if (diff < 60) return diff + 's ago';
|
||||||
if (diff < 3600) return Math.floor(diff/60) + 'm ago';
|
if (diff < 3600) return Math.floor(diff/60) + 'm ago';
|
||||||
if (diff < 86400) return Math.floor(diff/3600) + 'h ago';
|
if (diff < 86400) return Math.floor(diff/3600) + 'h ago';
|
||||||
return Math.floor(diff/86400) + 'd ago';
|
return Math.floor(diff/86400) + 'd ago';
|
||||||
}
|
}
|
||||||
|
|
||||||
var SEV_DOT = { critical: 'var(--red)', warning: 'var(--amber)' };
|
const SEV_DOT = { critical: 'var(--red)', warning: 'var(--amber)' };
|
||||||
|
|
||||||
function renderAlerts(events) {
|
function renderAlerts(events) {
|
||||||
_lastEvents = events || [];
|
_lastEvents = events || [];
|
||||||
var readBefore = getReadBefore();
|
const readBefore = getReadBefore();
|
||||||
var active = _lastEvents.filter(function(e) { return e.severity !== 'info'; });
|
const active = _lastEvents.filter(function(e) { return e.severity !== 'info'; });
|
||||||
var unreadCount = active.filter(function(e) { return toMs(e.last_seen) > readBefore; }).length;
|
const unreadCount = active.filter(function(e) { return toMs(e.last_seen) > readBefore; }).length;
|
||||||
lt.notif.set(bell, unreadCount);
|
lt.notif.set(bell, unreadCount);
|
||||||
|
|
||||||
if (!active.length) {
|
if (!active.length) {
|
||||||
@@ -461,8 +461,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list.innerHTML = active.slice(0, 25).map(function(e) {
|
list.innerHTML = active.slice(0, 25).map(function(e) {
|
||||||
var isUnread = toMs(e.last_seen) > readBefore;
|
const isUnread = toMs(e.last_seen) > readBefore;
|
||||||
var dotColor = SEV_DOT[e.severity] || 'var(--text-muted)';
|
const dotColor = SEV_DOT[e.severity] || 'var(--text-muted)';
|
||||||
return '<div class="lt-notif-item' + (isUnread ? ' lt-notif-item--unread' : '') + '">' +
|
return '<div class="lt-notif-item' + (isUnread ? ' lt-notif-item--unread' : '') + '">' +
|
||||||
'<div class="lt-notif-dot' + (isUnread ? '' : ' lt-notif-dot--read') + '" style="background:' + dotColor + '"></div>' +
|
'<div class="lt-notif-dot' + (isUnread ? '' : ' lt-notif-dot--read') + '" style="background:' + dotColor + '"></div>' +
|
||||||
'<div class="lt-notif-item-body">' +
|
'<div class="lt-notif-item-body">' +
|
||||||
@@ -476,14 +476,14 @@
|
|||||||
fetch('/api/status', { credentials: 'same-origin' })
|
fetch('/api/status', { credentials: 'same-origin' })
|
||||||
.then(function(r) { return r.json(); })
|
.then(function(r) { return r.json(); })
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
var events = data.events || [];
|
const events = data.events || [];
|
||||||
if (andRender) {
|
if (andRender) {
|
||||||
renderAlerts(events);
|
renderAlerts(events);
|
||||||
} else {
|
} else {
|
||||||
_lastEvents = events;
|
_lastEvents = events;
|
||||||
var readBefore = getReadBefore();
|
const readBefore = getReadBefore();
|
||||||
var active = events.filter(function(e) { return e.severity !== 'info'; });
|
const active = events.filter(function(e) { return e.severity !== 'info'; });
|
||||||
var unread = active.filter(function(e) { return toMs(e.last_seen) > readBefore; }).length;
|
const unread = active.filter(function(e) { return toMs(e.last_seen) > readBefore; }).length;
|
||||||
lt.notif.set(bell, unread);
|
lt.notif.set(bell, unread);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -466,7 +466,7 @@
|
|||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
// Start auto-refresh using saved settings interval (default 30 s)
|
// Start auto-refresh using saved settings interval (default 30 s)
|
||||||
var _savedInterval = (window.gandalfSettings && window.gandalfSettings.refreshInterval) || 30;
|
const _savedInterval = (window.gandalfSettings && window.gandalfSettings.refreshInterval) || 30;
|
||||||
if (_savedInterval > 0) lt.autoRefresh.start(refreshAll, _savedInterval * 1000);
|
if (_savedInterval > 0) lt.autoRefresh.start(refreshAll, _savedInterval * 1000);
|
||||||
|
|
||||||
// When settings change, restart auto-refresh with new interval
|
// When settings change, restart auto-refresh with new interval
|
||||||
@@ -477,9 +477,9 @@
|
|||||||
|
|
||||||
// ── Topology collapse toggle ───────────────────────────────────
|
// ── Topology collapse toggle ───────────────────────────────────
|
||||||
(function() {
|
(function() {
|
||||||
var LS_KEY = 'gandalf_topo_collapsed';
|
const LS_KEY = 'gandalf_topo_collapsed';
|
||||||
var btn = document.getElementById('topo-toggle-btn');
|
const btn = document.getElementById('topo-toggle-btn');
|
||||||
var wrap = document.getElementById('topo-collapsible-wrap');
|
const wrap = document.getElementById('topo-collapsible-wrap');
|
||||||
if (!btn || !wrap) return;
|
if (!btn || !wrap) return;
|
||||||
|
|
||||||
function setCollapsed(v) {
|
function setCollapsed(v) {
|
||||||
@@ -489,7 +489,7 @@
|
|||||||
try { localStorage.setItem(LS_KEY, v ? '1' : '0'); } catch(_) {}
|
try { localStorage.setItem(LS_KEY, v ? '1' : '0'); } catch(_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
var saved = false;
|
let saved = false;
|
||||||
try { saved = localStorage.getItem(LS_KEY) === '1'; } catch(_) {}
|
try { saved = localStorage.getItem(LS_KEY) === '1'; } catch(_) {}
|
||||||
setCollapsed(saved);
|
setCollapsed(saved);
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
const escHtml = s => lt.escHtml(s);
|
const escHtml = s => lt.escHtml(s);
|
||||||
|
const _toIso = s => s ? s.replace(' UTC', 'Z').replace(' ', 'T') : s;
|
||||||
|
|
||||||
// ── Formatting helpers ────────────────────────────────────────────
|
// ── Formatting helpers ────────────────────────────────────────────
|
||||||
function fmtRate(bytesPerSec) {
|
function fmtRate(bytesPerSec) {
|
||||||
@@ -326,7 +327,7 @@ function renderPortCard(portName, d) {
|
|||||||
function renderUnifiSwitches(unifiSwitches, dataUpdated) {
|
function renderUnifiSwitches(unifiSwitches, dataUpdated) {
|
||||||
if (!unifiSwitches || !Object.keys(unifiSwitches).length) return '';
|
if (!unifiSwitches || !Object.keys(unifiSwitches).length) return '';
|
||||||
const updStr = dataUpdated
|
const updStr = dataUpdated
|
||||||
? new Date(dataUpdated.replace(' UTC', 'Z').replace(' ', 'T')).toLocaleTimeString()
|
? new Date(_toIso(dataUpdated)).toLocaleTimeString()
|
||||||
: '';
|
: '';
|
||||||
const html = Object.entries(unifiSwitches).map(([swName, sw]) => {
|
const html = Object.entries(unifiSwitches).map(([swName, sw]) => {
|
||||||
const ports = sw.ports || {};
|
const ports = sw.ports || {};
|
||||||
@@ -558,7 +559,7 @@ async function loadLinks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadLinks();
|
loadLinks();
|
||||||
var _linksInterval = (window.gandalfSettings && window.gandalfSettings.refreshInterval) || 60;
|
const _linksInterval = (window.gandalfSettings && window.gandalfSettings.refreshInterval) || 60;
|
||||||
if (_linksInterval > 0) lt.autoRefresh.start(loadLinks, Math.max(_linksInterval, 15) * 1000);
|
if (_linksInterval > 0) lt.autoRefresh.start(loadLinks, Math.max(_linksInterval, 15) * 1000);
|
||||||
|
|
||||||
window.onGandalfSettingsChanged = function(s) {
|
window.onGandalfSettingsChanged = function(s) {
|
||||||
|
|||||||
Reference in New Issue
Block a user