Topology: a live page drawn from the real gear
Lint / JS (eslint) (push) Successful in 21s
Lint / Python (flake8) (push) Successful in 1m20s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m0s
Test / Python Tests (pytest) (push) Successful in 1m48s
Lint / Python (flake8) (pull_request) Successful in 1m44s
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 1m42s
Test / Python Tests (pytest) (pull_request) Successful in 1m16s
Lint / JS (eslint) (push) Successful in 21s
Lint / Python (flake8) (push) Successful in 1m20s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m0s
Test / Python Tests (pytest) (push) Successful in 1m48s
Lint / Python (flake8) (pull_request) Successful in 1m44s
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 1m42s
Test / Python Tests (pytest) (pull_request) Successful in 1m16s
The dashboard's hand-drawn diagram was out of date. /topology replaces it with the network as the switches report it, every device drawn to scale from its faceplate or cutsheet front, and one cable per physical link leaving the port it is plugged into. - topology.py builds the graph: switch-to-switch cables seen from both ends are merged, servers get one cable per NIC, the gateway's internet port goes to the modem and on to the internet, unknown neighbours are stubs, and gear with no live cable is drawn where it was last seen. - Ports named after a different device than the one plugged in are flagged. - Cables show medium, speed, state and traffic; click one for its details, hover a device to trace its path to the internet; pan, zoom and filters. - The monitor now keeps host_macs (MAC to host NIC) in link_stats. - The old dashboard diagram and its JS and CSS are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import cutsheet
|
||||
import db
|
||||
import devices
|
||||
import diagnose
|
||||
import topology
|
||||
from monitor import PulseClient, UnifiClient
|
||||
|
||||
logging.basicConfig(
|
||||
@@ -1195,17 +1196,7 @@ def _racks(items: list) -> list:
|
||||
return racks
|
||||
|
||||
|
||||
_VIRTUAL_IFACE = ('lo', 'vmbr', 'bond', 'docker', 'veth', 'tap', 'fwbr', 'fwpr', 'fwln', 'br-', 'virbr', 'wg', 'tun')
|
||||
|
||||
|
||||
def _physical_interfaces(name: str, snapshot: dict) -> list:
|
||||
"""A host's physical NICs in name order, with their state: [{'name', 'up'}].
|
||||
|
||||
Drawn fronts light one RJ45 per NIC in this order (first NIC on the leftmost jack).
|
||||
"""
|
||||
ifaces = ((snapshot.get('hosts') or {}).get(name) or {}).get('interfaces') or {}
|
||||
return [{'name': n, 'up': str(state).lower() == 'up', 'unused': str(state).lower() == 'unused'}
|
||||
for n, state in sorted(ifaces.items()) if not n.startswith(_VIRTUAL_IFACE)]
|
||||
_physical_interfaces = devices.physical_interfaces
|
||||
|
||||
|
||||
def _device_status(name: str, snapshot: dict) -> str:
|
||||
@@ -1314,6 +1305,35 @@ def api_rack():
|
||||
})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Topology
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@app.route('/topology')
|
||||
@require_auth
|
||||
def topology_page():
|
||||
return render_template('topology.html', user=_get_user())
|
||||
|
||||
|
||||
@app.route('/api/topology')
|
||||
@require_auth
|
||||
def api_topology():
|
||||
"""Every device and physical cable, for the topology page (see topology.build_graph)."""
|
||||
events = db.get_active_events(limit=_PAGE_LIMIT)
|
||||
_annotate_suppressions(events, db.get_active_suppressions())
|
||||
try:
|
||||
_ensure_cutsheet_schema()
|
||||
sheet = db.cutsheet_load()
|
||||
except Exception as e:
|
||||
logger.error(f'Cutsheet unavailable for topology: {e}')
|
||||
sheet = {'items': [], 'cables': []}
|
||||
graph = topology.build_graph(
|
||||
_state_json('network_snapshot'), _state_json('link_stats'), _state_json('modem_stats'),
|
||||
events, sheet['items'], sheet['cables'], _state_json('known_uplinks'),
|
||||
)
|
||||
return jsonify(graph)
|
||||
|
||||
|
||||
@app.route('/api/cutsheet/racks', methods=['POST'])
|
||||
@require_auth
|
||||
@require_admin
|
||||
|
||||
Reference in New Issue
Block a user