Fix ticket_id never stored when fail_thresh>1; guard sessionStorage JSON.parse
Lint / Python (flake8) (push) Successful in 45s
Lint / JS (eslint) (push) Successful in 8s
Security / Python Security (bandit) (push) Successful in 43s
Test / Python Tests (pytest) (push) Successful in 51s
Lint / Notify on failure (push) Has been skipped
Lint / Deploy (push) Successful in 3s
Lint / Python (flake8) (push) Successful in 45s
Lint / JS (eslint) (push) Successful in 8s
Security / Python Security (bandit) (push) Successful in 43s
Test / Python Tests (pytest) (push) Successful in 51s
Lint / Notify on failure (push) Has been skipped
Lint / Deploy (push) Successful in 3s
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 <noreply@anthropic.com>
This commit is contained in:
+3
-3
@@ -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)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
+11
-7
@@ -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 ────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user