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:
1 parent
7b80633088
commit
0921e82c54
10 files changed
+462
-4
No files matched your search
@@ -1,5 +1,7 @@
|
||||
"""Tests for app.py routes: database and LDAP are mocked."""
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import os
|
||||
import sys
|
||||
from unittest.mock import patch
|
||||
@@ -648,3 +650,56 @@ class TestMaintenance:
|
||||
def test_a_db_error_means_no_banner(self, client):
|
||||
gandalf.db.get_active_suppressions.side_effect = RuntimeError('db down')
|
||||
assert gandalf.inject_maintenance() == {'maintenance': None}
|
||||
|
||||
|
||||
class TestFollowUp:
|
||||
def _state(self, tickets, age_s=60):
|
||||
state = dict(STATE, open_tickets=json.dumps({'checked_at': time.time() - age_s, 'tickets': tickets}))
|
||||
gandalf.db.get_state.side_effect = lambda key, default=None: state.get(key, default)
|
||||
|
||||
def _event(self, days_old, ticket_id=None):
|
||||
first = (datetime.now(timezone.utc) - timedelta(days=days_old)).strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
return {'id': 1, 'event_type': 'interface_down', 'severity': 'critical', 'target_name': 'micro1',
|
||||
'target_detail': 'enp3s0', 'description': 'down', 'first_seen': first, 'last_seen': first,
|
||||
'consecutive_failures': 3, 'ticket_id': ticket_id}
|
||||
|
||||
def test_old_alert_is_stale_and_closed_ticket_is_flagged(self, client):
|
||||
self._state({'9': 'Open'})
|
||||
gandalf.db.get_active_events.return_value = [self._event(5, '8'), self._event(1, '9')]
|
||||
gandalf.db.get_cleared_tickets.return_value = []
|
||||
events = client.get('/api/status', headers=AUTH).get_json()['events']
|
||||
assert events[0]['stale_days'] == 5 and events[0]['ticket_closed'] is True
|
||||
assert events[1]['stale_days'] is None and events[1]['ticket_closed'] is False
|
||||
|
||||
def test_threshold_comes_from_config(self, client):
|
||||
self._state({})
|
||||
gandalf.db.get_active_events.return_value = [self._event(1.5)]
|
||||
gandalf.db.get_cleared_tickets.return_value = []
|
||||
cfg = dict(CONFIG, monitor={'stale_alert_days': 1})
|
||||
with patch.object(gandalf, '_cfg', cfg):
|
||||
events = client.get('/api/status', headers=AUTH).get_json()['events']
|
||||
assert events[0]['stale_days'] == 1
|
||||
|
||||
def test_tickets_left_open_are_listed(self, client):
|
||||
self._state({'281331508': 'Open'})
|
||||
left = [{'ticket_id': '281331508', 'event_type': 'host_unreachable', 'target_name': 'pbs',
|
||||
'target_detail': '', 'severity': 'critical', 'first_seen': '2026-10-14T12:02:05Z',
|
||||
'cleared_at': '2026-11-04T22:12:36Z', 'events': 3}]
|
||||
gandalf.db.get_cleared_tickets.return_value = left
|
||||
assert client.get('/api/status', headers=AUTH).get_json()['stale_tickets'] == left
|
||||
gandalf.db.get_cleared_tickets.assert_called_with(['281331508'], older_than_hours=24)
|
||||
html = client.get('/', headers=AUTH).get_data(as_text=True)
|
||||
assert '#281331508' in html and 'TO FOLLOW UP' in html
|
||||
assert '<section class="g-section" id="followup">' in html
|
||||
|
||||
def test_out_of_date_list_flags_nothing(self, client):
|
||||
self._state({}, age_s=3 * 3600)
|
||||
gandalf.db.get_active_events.return_value = [self._event(1, '8')]
|
||||
body = client.get('/api/status', headers=AUTH).get_json()
|
||||
assert body['stale_tickets'] == [] and body['events'][0]['ticket_closed'] is False
|
||||
gandalf.db.get_cleared_tickets.assert_not_called()
|
||||
|
||||
def test_no_list_yet_hides_the_panel(self, client):
|
||||
html = client.get('/', headers=AUTH).get_data(as_text=True)
|
||||
assert '<section class="g-section" id="followup" hidden>' in html
|
||||
assert 'TO FOLLOW UP' not in html
|
||||
Reference in new issue
Block a user