From 2be44d8b24a09498d542b70041b1c792700a1288 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 11 May 2026 23:45:20 -0400 Subject: [PATCH] Fix ticket_id never stored when fail_thresh>1; guard sessionStorage JSON.parse monitor.py: _ticket_interface/_ticket_unifi/_ticket_unreachable all used `if tid and is_new` to guard db.set_ticket_id(). Since is_new is True only on the first upsert (consec=1) but tickets are created at consec>=fail_thresh (default 2), is_new is always False when the ticket is created, so the ticket link never appeared in the UI. Changed to `if tid:`. links.html: JSON.parse(sessionStorage.getItem(...)) in togglePanel and restoreCollapseState had no try-catch. Corrupt/stale session storage would throw an uncaught SyntaxError. Also wrapped all sessionStorage.setItem calls in try-catch to defend against storage-full / private-browsing errors. Co-Authored-By: Claude Sonnet 4.6 --- monitor.py | 6 +++--- templates/links.html | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/monitor.py b/monitor.py index e8b77c2..c44373d 100644 --- a/monitor.py +++ b/monitor.py @@ -789,7 +789,7 @@ class NetworkMonitor: f'Please inspect the cable/SFP/switch port for {host}/{iface}.' ) tid = self.tickets.create(title, desc, priority='2') - if tid and is_new: + if tid: db.set_ticket_id(event_id, tid) # ------------------------------------------------------------------ @@ -831,7 +831,7 @@ class NetworkMonitor: f'Please check power and cable connectivity.' ) tid = self.tickets.create(title, desc, priority='2') - if tid and is_new: + if tid: db.set_ticket_id(event_id, tid) # ------------------------------------------------------------------ @@ -873,7 +873,7 @@ class NetworkMonitor: f'Please check the host power, management interface, and network connectivity.' ) tid = self.tickets.create(title, desc, priority='2') - if tid and is_new: + if tid: db.set_ticket_id(event_id, tid) # ------------------------------------------------------------------ diff --git a/templates/links.html b/templates/links.html index 9d3a978..3ce5229 100644 --- a/templates/links.html +++ b/templates/links.html @@ -372,14 +372,16 @@ function togglePanel(panel) { if (title) title.setAttribute('aria-expanded', isCollapsed ? 'false' : 'true'); const id = panel.id; if (id) { - const collapsed = JSON.parse(sessionStorage.getItem('linksCollapsed') || '{}'); + let collapsed = {}; + try { collapsed = JSON.parse(sessionStorage.getItem('linksCollapsed') || '{}'); } catch(_) {} collapsed[id] = panel.classList.contains('collapsed'); - sessionStorage.setItem('linksCollapsed', JSON.stringify(collapsed)); + try { sessionStorage.setItem('linksCollapsed', JSON.stringify(collapsed)); } catch(_) {} } } function restoreCollapseState() { - const collapsed = JSON.parse(sessionStorage.getItem('linksCollapsed') || '{}'); + let collapsed = {}; + try { collapsed = JSON.parse(sessionStorage.getItem('linksCollapsed') || '{}'); } catch(_) {} for (const [id, isCollapsed] of Object.entries(collapsed)) { const panel = document.getElementById(id); if (!panel) continue; @@ -507,9 +509,11 @@ function collapseAll() { if (btn) btn.textContent = '[+]'; if (title) title.setAttribute('aria-expanded', 'false'); }); - sessionStorage.setItem('linksCollapsed', JSON.stringify( - Object.fromEntries([...document.querySelectorAll('.link-host-panel')].map(p => [p.id, true])) - )); + try { + sessionStorage.setItem('linksCollapsed', JSON.stringify( + Object.fromEntries([...document.querySelectorAll('.link-host-panel')].map(p => [p.id, true])) + )); + } catch(_) {} } function expandAll() { @@ -520,7 +524,7 @@ function expandAll() { if (btn) btn.textContent = '[–]'; if (title) title.setAttribute('aria-expanded', 'true'); }); - sessionStorage.setItem('linksCollapsed', '{}'); + try { sessionStorage.setItem('linksCollapsed', '{}'); } catch(_) {} } // ── Stale data warning ────────────────────────────────────────────