Cutsheet trace mode and mismatch alerts
Lint / Python (flake8) (push) Successful in 1m8s
Security / Python Security (bandit) (push) Successful in 56s
Test / Python Tests (pytest) (push) Successful in 43s
Lint / Python (flake8) (pull_request) Successful in 50s
Lint / JS (eslint) (pull_request) Successful in 30s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 55s
Test / Python Tests (pytest) (pull_request) Successful in 50s
Lint / JS (eslint) (push) Successful in 16m17s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / Python (flake8) (push) Successful in 1m8s
Security / Python Security (bandit) (push) Successful in 56s
Test / Python Tests (pytest) (push) Successful in 43s
Lint / Python (flake8) (pull_request) Successful in 50s
Lint / JS (eslint) (pull_request) Successful in 30s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 55s
Test / Python Tests (pytest) (pull_request) Successful in 50s
Lint / JS (eslint) (push) Successful in 16m17s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Trace a cord: pick a panel port, press Start, and unplug the cord at the panel. The page polls a new admin-only endpoint that reads every switch port's state from UniFi (cached 2 s), shows the one port that dropped with a button to record the cable, and confirms when it's plugged back in. Several ports dropping at once, or none within 3 minutes, is explained rather than guessed at. Mismatch alerts: the monitor runs the cutsheet check every poll. Each mismatched installed run (wrong neighbor, no link, missing port, port conflict) keeps one cable_mismatch event on its switch, resolved when fixed, and opens a P4 ticket after cutsheet.mismatch_ticket_hours (default 24, 0 never). Suppressing the switch or port stops the ticket. Also fixes buttons with the hidden attribute still showing, which left a Delete button on the new-cable form. Closes #12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd602fdacf
commit
86aa29b378
11 files changed
+446
-1
No files matched your search
@@ -513,3 +513,50 @@ class TestLldpCollection:
|
||||
c = monitor.UnifiClient({'controller': 'https://u.test', 'api_key': 'k'})
|
||||
c.session.get = MagicMock(side_effect=OSError('boom'))
|
||||
assert c.get_wired_clients() == []
|
||||
|
||||
|
||||
class TestCutsheetMismatch:
|
||||
CABLE = {'id': 7, 'label': 'C07', 'a_device': 'sw', 'a_port': '13', 'a_side': '', 'b_device': 'tv',
|
||||
'b_port': '', 'b_side': '', 'status': 'installed'}
|
||||
|
||||
def _run(self, mon, db, seen='printer', consec=1, ticket=None, suppressions=(), open_targets=()):
|
||||
mon.poll_interval = 120
|
||||
mon.cutsheet_ticket_hours = getattr(mon, 'cutsheet_ticket_hours', 24)
|
||||
db.cutsheet_load.return_value = {'items': [], 'cables': [dict(self.CABLE)], 'port_labels': []}
|
||||
db.upsert_event.return_value = (5, consec == 1, consec, ticket)
|
||||
db.get_open_event_targets.return_value = list(open_targets)
|
||||
db.check_suppressed.side_effect = lambda sups, kind, name, detail='': (kind, name) in sups
|
||||
link = {'unifi_switches': {'sw': {'ports': {'Port 13': {
|
||||
'port_idx': 13, 'up': True, 'lldp': {'system_name': seen}}}}}}
|
||||
mon._process_cutsheet(link, list(suppressions))
|
||||
|
||||
def test_mismatch_opens_an_event_but_no_ticket_yet(self, mon, db):
|
||||
self._run(mon, db)
|
||||
args = db.upsert_event.call_args.args
|
||||
assert args[:5] == ('cable_mismatch', 'warning', 'cutsheet', 'sw', 'cable 7')
|
||||
assert 'printer' in args[5]
|
||||
assert not mon.tickets.create.called
|
||||
|
||||
def test_ticket_after_a_day_of_polls(self, mon, db):
|
||||
self._run(mon, db, consec=719)
|
||||
assert not mon.tickets.create.called
|
||||
self._run(mon, db, consec=720)
|
||||
title = mon.tickets.create.call_args.args[0]
|
||||
assert 'Cable C07 does not match the cutsheet' in title
|
||||
assert mon.tickets.create.call_args.kwargs['priority'] == '4'
|
||||
|
||||
def test_no_second_ticket_and_suppression_respected(self, mon, db):
|
||||
self._run(mon, db, consec=900, ticket='123')
|
||||
self._run(mon, db, consec=900, suppressions=[('unifi_device', 'sw')])
|
||||
assert not mon.tickets.create.called
|
||||
|
||||
def test_zero_hours_never_tickets(self, mon, db):
|
||||
mon.cutsheet_ticket_hours = 0
|
||||
self._run(mon, db, consec=10_000)
|
||||
assert db.upsert_event.called and not mon.tickets.create.called
|
||||
|
||||
def test_fixed_cable_resolves_its_event(self, mon, db):
|
||||
self._run(mon, db, seen='tv', open_targets=[('sw', 'cable 7'), ('other', 'cable 9')])
|
||||
assert not db.upsert_event.called
|
||||
resolved = {c.args for c in db.resolve_event.call_args_list}
|
||||
assert ('cable_mismatch', 'sw', 'cable 7') in resolved and ('cable_mismatch', 'other', 'cable 9') in resolved
|
||||
Reference in new issue
Block a user