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:
@@ -913,3 +913,60 @@ class TestTicketClientCreate:
|
||||
with self._post({'success': True, 'ticket_id': '8', 'action': 'none'}):
|
||||
assert c.create('t', 'd') == '8'
|
||||
assert 't' not in c._closed_matches
|
||||
|
||||
|
||||
class TestTicketClientOpenTickets:
|
||||
def _client(self):
|
||||
return monitor.TicketClient({'url': 'http://t.test/create_ticket_api.php', 'api_key': 'k'})
|
||||
|
||||
def _page(self, tickets, pages):
|
||||
resp = MagicMock(status_code=200)
|
||||
resp.json.return_value = {'success': True, 'tickets': tickets, 'page': 1, 'pages': pages}
|
||||
return resp
|
||||
|
||||
def test_read_endpoint_sits_beside_create(self):
|
||||
assert self._client().read_url == 'http://t.test/api/tickets_api.php'
|
||||
|
||||
def test_reads_every_page_of_open_statuses(self):
|
||||
pages = [self._page([{'ticket_id': '1', 'status': 'Open'}], 2),
|
||||
self._page([{'ticket_id': 2, 'status': 'Pending'}], 2)]
|
||||
with patch.object(monitor.requests, 'get', side_effect=pages) as get:
|
||||
assert self._client().open_tickets() == {'1': 'Open', '2': 'Pending'}
|
||||
assert get.call_count == 2
|
||||
params = get.call_args.kwargs['params']
|
||||
assert params['status'] == 'Open,Pending,In Progress' and params['page'] == 2
|
||||
assert get.call_args.kwargs['headers'] == {'Authorization': 'Bearer k'}
|
||||
|
||||
def test_failure_means_unknown_not_empty(self):
|
||||
with patch.object(monitor.requests, 'get', side_effect=OSError('down')):
|
||||
assert self._client().open_tickets() is None
|
||||
bad = MagicMock(status_code=200)
|
||||
bad.json.return_value = {'success': False, 'error': 'nope'}
|
||||
with patch.object(monitor.requests, 'get', return_value=bad):
|
||||
assert self._client().open_tickets() is None
|
||||
|
||||
def test_unconfigured(self):
|
||||
assert monitor.TicketClient({}).open_tickets() is None
|
||||
|
||||
|
||||
class TestSyncOpenTickets:
|
||||
def test_saves_the_list_then_waits(self, mon, db):
|
||||
mon.tickets.open_tickets.return_value = {'7': 'Open'}
|
||||
mon._sync_open_tickets()
|
||||
mon._sync_open_tickets()
|
||||
assert mon.tickets.open_tickets.call_count == 1
|
||||
key, value = db.set_state.call_args.args
|
||||
assert key == monitor.OPEN_TICKETS_STATE and value['tickets'] == {'7': 'Open'}
|
||||
assert value['checked_at'] > 0
|
||||
|
||||
def test_failed_read_keeps_the_previous_list(self, mon, db):
|
||||
mon.tickets.open_tickets.return_value = None
|
||||
mon._sync_open_tickets()
|
||||
db.set_state.assert_not_called()
|
||||
|
||||
def test_refreshes_after_the_interval(self, mon, db):
|
||||
mon.tickets.open_tickets.return_value = {}
|
||||
mon._sync_open_tickets()
|
||||
mon._open_tickets_synced -= monitor.OPEN_TICKETS_SYNC_S + 1
|
||||
mon._sync_open_tickets()
|
||||
assert mon.tickets.open_tickets.call_count == 2
|
||||
|
||||
Reference in New Issue
Block a user