Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 156ef97667 | |||
| 2f74266bd9 | |||
| 222bdb08ab | |||
| 8dd744b039 | |||
| 9e2be150b5 | |||
| ed5ba5c59e |
@@ -174,17 +174,26 @@ _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."""
|
||||
"""Annotate each event dict in-place with an is_suppressed bool.
|
||||
|
||||
Mirrors the suppression check order in monitor.py exactly:
|
||||
interface_down → interface OR host
|
||||
unifi_device_* → unifi_device
|
||||
everything else → host
|
||||
"""
|
||||
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 '',
|
||||
)
|
||||
etype = ev.get('event_type', '')
|
||||
name = ev.get('target_name', '')
|
||||
detail = ev.get('target_detail', '') or ''
|
||||
if etype == 'interface_down':
|
||||
ev['is_suppressed'] = (
|
||||
db.check_suppressed(suppressions, 'interface', name, detail) or
|
||||
db.check_suppressed(suppressions, 'host', name)
|
||||
)
|
||||
elif etype == 'unifi_device_offline':
|
||||
ev['is_suppressed'] = db.check_suppressed(suppressions, 'unifi_device', name, detail)
|
||||
else:
|
||||
ev['is_suppressed'] = db.check_suppressed(suppressions, 'host', name, detail)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ class DiagnosticsRunner:
|
||||
f' echo "=== ip_route ===";'
|
||||
f' ip route show dev {q} 2>/dev/null;'
|
||||
f' echo "=== dmesg ===";'
|
||||
f' dmesg 2>/dev/null | grep {q} | tail -50;'
|
||||
f' dmesg 2>/dev/null | grep -F -- {q} | tail -50;'
|
||||
f' echo "=== lldpctl ===";'
|
||||
f' lldpctl 2>/dev/null || echo "lldpd not running";'
|
||||
f' echo "=== end ==="'
|
||||
|
||||
+7
-6
@@ -734,7 +734,7 @@ class NetworkMonitor:
|
||||
f'Interface {iface} on {host} went link-down ({_now_utc()})',
|
||||
)
|
||||
if not sup and consec >= self.fail_thresh:
|
||||
self._ticket_interface(event_id, is_new, host, iface, consec)
|
||||
self._ticket_interface(event_id, host, iface, consec)
|
||||
|
||||
if host_has_regression:
|
||||
hosts_with_regression.append(host)
|
||||
@@ -771,7 +771,7 @@ class NetworkMonitor:
|
||||
db.resolve_event('cluster_network_issue', self.cluster_name, '')
|
||||
|
||||
def _ticket_interface(
|
||||
self, event_id: int, is_new: bool, host: str, iface: str, consec: int
|
||||
self, event_id: int, host: str, iface: str, consec: int
|
||||
) -> None:
|
||||
title = (
|
||||
f'[{host}][auto][production][issue][network][single-node] '
|
||||
@@ -810,11 +810,11 @@ class NetworkMonitor:
|
||||
f'UniFi {name} ({d.get("ip","")}) offline ({_now_utc()})',
|
||||
)
|
||||
if not sup and consec >= self.fail_thresh:
|
||||
self._ticket_unifi(event_id, is_new, d)
|
||||
self._ticket_unifi(event_id, d)
|
||||
else:
|
||||
db.resolve_event('unifi_device_offline', name, d.get('type', ''))
|
||||
|
||||
def _ticket_unifi(self, event_id: int, is_new: bool, device: dict) -> None:
|
||||
def _ticket_unifi(self, event_id: int, device: dict) -> None:
|
||||
name = device['name']
|
||||
title = (
|
||||
f'[{name}][auto][production][issue][network][single-node] '
|
||||
@@ -850,12 +850,12 @@ class NetworkMonitor:
|
||||
f'Host {name} ({ip}) unreachable via ping ({_now_utc()})',
|
||||
)
|
||||
if not sup and consec >= self.fail_thresh:
|
||||
self._ticket_unreachable(event_id, is_new, name, ip, consec)
|
||||
self._ticket_unreachable(event_id, name, ip, consec)
|
||||
else:
|
||||
db.resolve_event('host_unreachable', name, ip)
|
||||
|
||||
def _ticket_unreachable(
|
||||
self, event_id: int, is_new: bool, name: str, ip: str, consec: int
|
||||
self, event_id: int, name: str, ip: str, consec: int
|
||||
) -> None:
|
||||
title = (
|
||||
f'[{name}][auto][production][issue][network][single-node] '
|
||||
@@ -970,6 +970,7 @@ class NetworkMonitor:
|
||||
except Exception as e:
|
||||
logger.error(f'Monitor loop error: {e}', exc_info=True)
|
||||
time.sleep(30)
|
||||
continue
|
||||
|
||||
time.sleep(self.poll_interval)
|
||||
|
||||
|
||||
@@ -324,6 +324,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="host-grid" id="host-grid">
|
||||
{%- set has_global_sup = suppressions | selectattr('target_type', 'equalto', 'all') | list | length > 0 -%}
|
||||
{% for name, host in snapshot.hosts.items() %}
|
||||
{% set suppressed = suppressions | selectattr('target_name', 'equalto', name) | list %}
|
||||
<div class="host-card host-card-{{ host.status }}" data-host="{{ name }}">
|
||||
@@ -331,7 +332,7 @@
|
||||
<div class="host-name-row">
|
||||
<span class="host-status-dot dot-{{ host.status }}"></span>
|
||||
<span class="host-name">{{ name }}</span>
|
||||
{% if suppressed %}
|
||||
{% if suppressed or has_global_sup %}
|
||||
<span class="badge-suppressed" title="Suppressed">🔕</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -468,7 +469,7 @@
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// Start auto-refresh using saved settings interval (default 30 s)
|
||||
const _savedInterval = (window.gandalfSettings && window.gandalfSettings.refreshInterval) || 30;
|
||||
const _savedInterval = window.gandalfSettings?.refreshInterval ?? 30;
|
||||
if (_savedInterval > 0) lt.autoRefresh.start(refreshAll, _savedInterval * 1000);
|
||||
|
||||
// When settings change, restart auto-refresh with new interval
|
||||
|
||||
@@ -571,7 +571,7 @@ async function loadLinks() {
|
||||
}
|
||||
|
||||
loadLinks();
|
||||
const _linksInterval = (window.gandalfSettings && window.gandalfSettings.refreshInterval) || 60;
|
||||
const _linksInterval = window.gandalfSettings?.refreshInterval ?? 60;
|
||||
if (_linksInterval > 0) lt.autoRefresh.start(loadLinks, Math.max(_linksInterval, 15) * 1000);
|
||||
|
||||
window.onGandalfSettingsChanged = function(s) {
|
||||
|
||||
@@ -36,6 +36,12 @@ class TestBuildSshCommand:
|
||||
cmd = DiagnosticsRunner.build_ssh_command('10.0.0.1', 'eth0')
|
||||
assert 'ethtool' in cmd
|
||||
|
||||
def test_dmesg_uses_fixed_string_grep(self):
|
||||
# grep -F prevents iface names with dots (e.g. eth0.1) being treated as
|
||||
# regex wildcards; -- prevents leading - from being parsed as a flag
|
||||
cmd = DiagnosticsRunner.build_ssh_command('10.0.0.1', 'eth0')
|
||||
assert 'grep -F --' in cmd
|
||||
|
||||
|
||||
# ── parse_output ─────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user