Move the port inspector onto device pages
Lint / JS (eslint) (push) Successful in 1m14s
Lint / Python (flake8) (push) Successful in 2m12s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m3s
Test / Python Tests (pytest) (push) Successful in 1m11s
Lint / Python (flake8) (pull_request) Successful in 1m1s
Lint / JS (eslint) (pull_request) Successful in 10s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 56s
Test / Python Tests (pytest) (pull_request) Successful in 1m5s

Replace the all-switches Inspector page with a per-device front panel,
port table and detail panel. /inspector now redirects to the dashboard,
and /device/<name>#port-<n> links directly to a port.

Restore neighbor names after UniFi's LLDP change: read local_port_idx
and resolve neighbors by MAC using Prometheus NIC data, UniFi devices
and the wired client table. This also brings back Run Diagnostics on
server ports, which depends on a named neighbor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 10:11:11 -05:00
co-authored by Claude Opus 5.5
parent e32499b7f6
commit bdcfb76c25
13 changed files with 484 additions and 226 deletions
+81
View File
@@ -122,6 +122,87 @@ class TestDetail:
def test_switch_has_ports(self):
assert set(devices.device_detail('24RJ45-POE', SNAPSHOT, LINKS, MODEM)['ports']) == {'Port 3', 'Port 4'}
def test_switch_gets_only_its_lldp_neighbors_for_the_path_check(self):
links = dict(LINKS, hosts=dict(LINKS['hosts'], other={'eth9': {}}))
d = devices.device_detail('24RJ45-POE', SNAPSHOT, links, MODEM)
assert set(d['neighbor_hosts']) == {'large1'}
assert 'eth0' in d['neighbor_hosts']['large1']
def test_router_has_info_even_without_port_data(self):
d = devices.device_detail('Dream Machine Pro', SNAPSHOT, LINKS, MODEM)
assert d['info']['firmware'] == '6.0.17' and d['ports'] == {}
class TestLldpResolution:
HOSTS = {'9c:6b:00:8a:17:e6': ('micro1', 'enp1s0')}
DEVS = {'78:45:58:b1:bd:3a': '24RJ45-POE'}
IPS = {'10.0.0.9': 'storage-01'}
def resolve(self, **lldp):
sw = {'s': {'ports': {'p': {'lldp': lldp}}}}
devices.resolve_lldp_neighbors(sw, self.HOSTS, self.DEVS, self.IPS)
return sw['s']['ports']['p']['lldp']
def test_port_mac_gives_host_and_interface(self):
got = self.resolve(chassis_id='aa:aa:aa:aa:aa:aa', port_id='9C:6B:00:8A:17:E6')
assert (got['system_name'], got['port_id']) == ('micro1', 'enp1s0')
def test_chassis_mac_keeps_a_named_port(self):
got = self.resolve(chassis_id='9c:6b:00:8a:17:e6', port_id='enp9s0')
assert (got['system_name'], got['port_id']) == ('micro1', 'enp9s0')
def test_unifi_device_by_chassis(self):
got = self.resolve(chassis_id='78:45:58:b1:bd:3a', port_id='Port 26')
assert (got['system_name'], got['port_id']) == ('24RJ45-POE', 'Port 26')
def test_management_ip_fallback(self):
got = self.resolve(chassis_id='aa:aa:aa:aa:aa:aa', port_id='x', mgmt_ips=['10.0.0.9'])
assert got['system_name'] == 'storage-01'
def test_unknown_neighbor_stays_unnamed(self):
got = self.resolve(chassis_id='aa:aa:aa:aa:aa:aa', port_id='aa:aa:aa:aa:aa:ab')
assert got['system_name'] == ''
def test_a_reported_name_is_kept(self):
got = self.resolve(system_name='lldp-name', chassis_id='78:45:58:b1:bd:3a', port_id='x')
assert got['system_name'] == 'lldp-name'
def test_port_without_lldp_is_left_alone(self):
sw = {'s': {'ports': {'p': {'lldp': None}}}}
devices.resolve_lldp_neighbors(sw, self.HOSTS, self.DEVS, self.IPS)
assert sw['s']['ports']['p']['lldp'] is None
class TestClientLocations:
HOSTS = {'aa:aa:aa:aa:aa:01': ('large1', 'enp35s0')}
DEVS = {'bb:bb:bb:bb:bb:01': 'sw'}
def apply(self, port, sw_port=10):
switches = {'sw': {'ports': {'Port 10': dict({'port_idx': 10}, **port)}}}
client = {'mac': 'AA:AA:AA:AA:AA:01', 'sw_mac': 'bb:bb:bb:bb:bb:01', 'sw_port': sw_port}
devices.apply_client_locations(switches, [client], self.HOSTS, self.DEVS)
return switches['sw']['ports']['Port 10']['lldp']
def test_server_without_lldp_is_located(self):
got = self.apply({'lldp': None})
assert (got['system_name'], got['port_id'], got['source']) == ('large1', 'enp35s0', 'unifi-clients')
def test_uplink_port_is_skipped(self):
assert self.apply({'lldp': None, 'is_uplink': True}) is None
def test_named_lldp_neighbor_is_kept(self):
assert self.apply({'lldp': {'system_name': 'other'}})['system_name'] == 'other'
def test_unnamed_lldp_entry_is_replaced(self):
assert self.apply({'lldp': {'system_name': '', 'chassis_id': 'x'}})['system_name'] == 'large1'
def test_other_port_is_untouched(self):
assert self.apply({'lldp': None}, sw_port=11) is None
def test_non_host_client_is_ignored(self):
switches = {'sw': {'ports': {'Port 10': {'port_idx': 10, 'lldp': None}}}}
devices.apply_client_locations(
switches, [{'mac': 'cc:cc:cc:cc:cc:cc', 'sw_mac': 'bb:bb:bb:bb:bb:01', 'sw_port': 10}],
self.HOSTS, self.DEVS,
)
assert switches['sw']['ports']['Port 10']['lldp'] is None