Dashboard: flag stale alerts and tickets left open
Lint / JS (eslint) (push) Successful in 19s
Lint / Python (flake8) (push) Successful in 1m7s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 52s
Test / Python Tests (pytest) (push) Successful in 44s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Python (flake8) (pull_request) Successful in 50s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 52s
Test / Python Tests (pytest) (pull_request) Successful in 1m35s
Lint / JS (eslint) (push) Successful in 19s
Lint / Python (flake8) (push) Successful in 1m7s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 52s
Test / Python Tests (pytest) (push) Successful in 44s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Python (flake8) (pull_request) Successful in 50s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 52s
Test / Python Tests (pytest) (pull_request) Successful in 1m35s
Gandalf only comments on tickets, so a ticket can stay open long after its alert cleared (pbs's ticket sat open for a month), and an alert can stay active for days once nobody is looking. - The monitor reads Tinker's open ticket list (tickets_api.php, read scope) every 15 minutes and saves it. A failed read keeps the previous list. - Active alerts get a stale badge after monitor.stale_alert_days (3), and a "ticket closed" badge when their ticket was closed while still active. - A Needs Follow-up panel lists open tickets whose every alert cleared at least monitor.stale_ticket_hours (24) ago. - A "TO FOLLOW UP" status chip counts both. If the open ticket list is over 2 hours old, the ticket flags are left off rather than guessed. - Replaced an — in the alert count notice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -247,6 +247,49 @@ def get_active_events(limit: int = 200, offset: int = 0) -> list:
|
||||
return rows
|
||||
|
||||
|
||||
def get_cleared_tickets(open_ids: List[str], older_than_hours: int = 24) -> list:
|
||||
"""Of the given open tickets, those whose every alert cleared at least `older_than_hours` ago.
|
||||
|
||||
One row per ticket, describing its most recent alert, newest clearance first:
|
||||
{ticket_id, event_type, target_name, target_detail, severity, first_seen, cleared_at, events}
|
||||
"""
|
||||
ids = sorted({str(i) for i in open_ids if i})
|
||||
if not ids:
|
||||
return []
|
||||
placeholders = ','.join(['%s'] * len(ids))
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
f"""SELECT ticket_id, event_type, target_name, target_detail, severity,
|
||||
first_seen, resolved_at
|
||||
FROM network_events WHERE ticket_id IN ({placeholders})
|
||||
ORDER BY first_seen""", # nosec B608: placeholders are only %s markers
|
||||
ids,
|
||||
)
|
||||
rows = cur.fetchall()
|
||||
cur.execute('SELECT NOW() AS now')
|
||||
now = cur.fetchone()['now']
|
||||
by_ticket: dict = {}
|
||||
for r in rows:
|
||||
by_ticket.setdefault(str(r['ticket_id']), []).append(r)
|
||||
out = []
|
||||
for tid, events in by_ticket.items():
|
||||
if any(e['resolved_at'] is None for e in events):
|
||||
continue
|
||||
cleared = max(e['resolved_at'] for e in events)
|
||||
if (now - cleared).total_seconds() < older_than_hours * 3600:
|
||||
continue
|
||||
last = events[-1]
|
||||
out.append({
|
||||
'ticket_id': tid, 'event_type': last['event_type'], 'target_name': last['target_name'],
|
||||
'target_detail': last['target_detail'], 'severity': last['severity'],
|
||||
'first_seen': events[0]['first_seen'].isoformat() + 'Z',
|
||||
'cleared_at': cleared.isoformat() + 'Z', 'events': len(events),
|
||||
})
|
||||
out.sort(key=lambda r: r['cleared_at'], reverse=True)
|
||||
return out
|
||||
|
||||
|
||||
def count_active_events() -> int:
|
||||
"""Return count of all unresolved events (for pagination)."""
|
||||
with get_conn() as conn:
|
||||
|
||||
Reference in New Issue
Block a user