Topology: tap to trace on phones, name cables into a patch panel
Lint / JS (eslint) (push) Successful in 19s
Lint / Python (flake8) (push) Successful in 1m20s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / JS (eslint) (pull_request) Successful in 27s
Lint / Python (flake8) (pull_request) Successful in 1m46s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m9s
Test / Python Tests (pytest) (pull_request) Successful in 1m23s
Security / Python Security (bandit) (push) Successful in 1m10s
Test / Python Tests (pytest) (push) Successful in 1m18s
Lint / JS (eslint) (push) Successful in 19s
Lint / Python (flake8) (push) Successful in 1m20s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / JS (eslint) (pull_request) Successful in 27s
Lint / Python (flake8) (pull_request) Successful in 1m46s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m9s
Test / Python Tests (pytest) (pull_request) Successful in 1m23s
Security / Python Security (bandit) (push) Successful in 1m10s
Test / Python Tests (pytest) (push) Successful in 1m18s
- Touch screens have no hover, so the first tap on a device traces its path to the internet and its power feeds; a second tap opens it. Tapping empty canvas clears it, and the trace survives the 30 s refresh. - A cutsheet cable now carries where its other end goes. An unknown device on a cable documented into a patch panel is drawn as that panel's jacks, named "Patch panel port N"; a named stub notes "via Patch panel port N". The cable panel shows the far end of the cutsheet cable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1495,6 +1495,12 @@ body.fp-marks-off .fp-svg .fp-mark { display: none; }
|
||||
.tp-stub-q { font-family: var(--font); font-size: 30px; font-weight: 700; fill: #9aa3ad; }
|
||||
.tp-st-down .tp-stub-body { stroke: #e0312b; }
|
||||
.tp-stub-jack.tp-off { opacity: .4; }
|
||||
.tp-pp-body { fill: #2b2f35; stroke: #1b1e22; stroke-width: 3; }
|
||||
.tp-pp-jack rect { fill: #121417; stroke: #4a5059; stroke-width: 2; }
|
||||
.tp-pp-jack.tp-pp-used rect { fill: #121417; stroke: #4aa3ff; stroke-width: 4; }
|
||||
.tp-pp-num { font-family: var(--font); font-size: 18px; fill: #8a929c; }
|
||||
.tp-pp-used .tp-pp-num { fill: #cfe6ff; font-weight: 700; }
|
||||
.tp-st-down .tp-pp-body { stroke: #e0312b; }
|
||||
.tp-group-body { stroke-dasharray: 10 8; stroke: #5d6670; }
|
||||
.tp-group-hint { font-family: var(--font); font-size: 20px; fill: #9aa3ad; }
|
||||
.tp-select { font-size: .95em; padding: 1px 4px; margin-left: 4px; }
|
||||
|
||||
+58
-5
@@ -19,7 +19,10 @@ const state = {
|
||||
filters: loadFilters(),
|
||||
expanded: new Set(), // switches whose unknown devices are shown one by one
|
||||
selected: null,
|
||||
pinned: null, // the device a touch screen tapped to trace
|
||||
};
|
||||
// Whether the last press was a mouse, pen or finger: touch has no hover, so taps trace instead
|
||||
let lastPointer = 'mouse';
|
||||
|
||||
function loadFilters() {
|
||||
try {
|
||||
@@ -323,6 +326,24 @@ function stubDrawing() {
|
||||
};
|
||||
}
|
||||
|
||||
// The far end of a cable the cutsheet says goes into a patch panel: the panel's row of jacks,
|
||||
// with the cable landing on its documented port
|
||||
function patchPanelDrawing(node) {
|
||||
const n = 24, pitch = 42, w = 80 + n * pitch, h = 130;
|
||||
const used = Number(node.via.port);
|
||||
const jacks = Array.from({ length: n }, (_, i) => {
|
||||
const x = 40 + i * pitch + 6;
|
||||
const on = i + 1 === used;
|
||||
return `<g class="tp-pp-jack${on ? ' tp-pp-used' : ''}"><rect x="${x}" y="46" width="30" height="34" rx="3"/>
|
||||
<text class="tp-pp-num" x="${x + 15}" y="108" text-anchor="middle">${i + 1}</text></g>`;
|
||||
}).join('');
|
||||
return {
|
||||
w, h,
|
||||
svg: `<rect class="tp-pp-body" x="0" y="20" width="${w}" height="${h - 20}" rx="8"/>${jacks}`,
|
||||
anchor: () => (used >= 1 && used <= n ? { x: 40 + (used - 1) * pitch + 21, y: 46, face: 'top' } : { x: w / 2, y: 20, face: 'top' }),
|
||||
};
|
||||
}
|
||||
|
||||
// A host's drawn front, from its cutsheet item's Front drawing
|
||||
function hostFront(node) {
|
||||
const ctx = { name: node.name, status: node.status, interfaces: node.interfaces || [] };
|
||||
@@ -346,7 +367,7 @@ function artFor(node) {
|
||||
switch (node.kind) {
|
||||
case 'internet': return internetDrawing();
|
||||
case 'modem': return modemDrawing(node);
|
||||
case 'stub': return stubDrawing();
|
||||
case 'stub': return node.via && node.via.kind === 'patch_panel' ? patchPanelDrawing(node) : stubDrawing();
|
||||
case 'group': return groupDrawing(node);
|
||||
case 'ap': return apDrawing(node);
|
||||
case 'strip': return stripDrawing(node);
|
||||
@@ -433,7 +454,8 @@ function cardFor(node, linksByIface) {
|
||||
band = `${art}${sockets.svg}`;
|
||||
anchorAt = end => (end.iface && sockets.pos[end.iface]) || null;
|
||||
} else {
|
||||
const small = ['internet', 'modem', 'stub', 'group', 'ap', 'strip'].includes(node.kind);
|
||||
const panel = node.kind === 'stub' && node.via && node.via.kind === 'patch_panel';
|
||||
const small = !panel && ['internet', 'modem', 'stub', 'group', 'ap', 'strip'].includes(node.kind);
|
||||
w = Math.max(small ? CARD_SMALL_W : CARD_W, Math.min(node.name.length * 27 + 130, 980));
|
||||
const art = artFor(node);
|
||||
const f = fitArt(art, 28, BAND_Y, w - 56, BAND_H);
|
||||
@@ -478,6 +500,8 @@ function cardFor(node, linksByIface) {
|
||||
const name = node.name.length > maxChars ? `${node.name.slice(0, maxChars - 1)}…` : node.name;
|
||||
let sub;
|
||||
if (node.kind === 'group') sub = `on ${node.switch}`;
|
||||
else if (node.kind === 'stub' && node.named_by_via) sub = `${node.via.cable ? `${node.via.cable} · ` : ''}device beyond it unknown`;
|
||||
else if (node.kind === 'stub' && node.via) sub = `via ${node.via.name}`;
|
||||
else if (node.kind === 'stub') sub = node.ip ? `${node.switch} port ${node.port_idx}` : (node.mac || `${node.switch} port ${node.port_idx}`);
|
||||
else if (node.kind === 'host') sub = node.status === 'up' ? 'server' : `server · ${node.status}`;
|
||||
else if (node.kind === 'internet') sub = node.status === 'up' ? 'connected' : node.status;
|
||||
@@ -846,7 +870,10 @@ function renderNode(node, lay) {
|
||||
<g class="tp-badge tp-badge-${esc(node.severity)}" transform="translate(${d.w - 6} 6)"><circle r="30"/><text y="11" text-anchor="middle">${node.alert_count}</text></g>`
|
||||
: '';
|
||||
const alertText = (node.alerts || []).map(a => `${a.severity}: ${a.type.replace(/_/g, ' ')}${a.detail ? ` ${a.detail}` : ''}`).join('; ');
|
||||
const label = `${node.name}${node.kind === 'stub' ? ' (not identified)' : ''} · ${node.status}${alertText ? ` · ${alertText}` : ''}`;
|
||||
const what = node.kind !== 'stub' ? ''
|
||||
: node.named_by_via ? ` (${node.via.device}; what is patched in beyond it is not identified)`
|
||||
: ` (not identified${node.via ? `; via ${node.via.name}` : ''})`;
|
||||
const label = `${node.name}${what} · ${node.status}${alertText ? ` · ${alertText}` : ''}`;
|
||||
const open = node.kind === 'group'
|
||||
? `<g class="tp-node-link" tabindex="0" role="button" data-expand="${esc(node.switch)}" aria-label="${esc(`${node.name} on ${node.switch}: show them`)}">`
|
||||
: (href ? `<a class="tp-node-link" href="${esc(href)}" aria-label="${esc(label)}">` : `<g class="tp-node-link" tabindex="0" aria-label="${esc(label)}">`);
|
||||
@@ -902,6 +929,11 @@ function render() {
|
||||
if (link) showPanel(link);
|
||||
else hidePanel();
|
||||
}
|
||||
// A refresh redraws everything: keep a tapped device traced
|
||||
if (state.pinned) {
|
||||
if (lay.pos[state.pinned]) highlight(state.pinned);
|
||||
else state.pinned = null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Cable panel ─────────────────────────────────────────────────────────
|
||||
@@ -943,7 +975,10 @@ function showPanel(link) {
|
||||
}
|
||||
if (link.cable) {
|
||||
const label = link.cable.label || `cable #${link.cable.id}`;
|
||||
row('Cutsheet', `<a class="device-link" href="/cutsheet#cable-${esc(link.cable.id)}">${esc(label)}</a>${link.cable.type ? ` · ${esc(link.cable.type)}` : ''}${link.cable.color ? ` · ${esc(link.cable.color)}` : ''}`);
|
||||
const far = link.cable.far;
|
||||
const to = far && far.device && !byId[far.device]
|
||||
? `<br><span class="tp-dim-text">into ${esc(far.device)}${far.port ? ` port ${esc(far.port)}` : ''}</span>` : '';
|
||||
row('Cutsheet', `<a class="device-link" href="/cutsheet#cable-${esc(link.cable.id)}">${esc(label)}</a>${link.cable.type ? ` · ${esc(link.cable.type)}` : ''}${link.cable.color ? ` · ${esc(link.cable.color)}` : ''}${to}`);
|
||||
} else if (!link.wan) {
|
||||
row('Cutsheet', '<span class="tp-dim-text">not documented</span>');
|
||||
}
|
||||
@@ -1169,6 +1204,22 @@ function initEvents() {
|
||||
return;
|
||||
}
|
||||
if (!e.target.closest('#tp-pop')) closeOutletEditor();
|
||||
// A touch screen has no hover: the first tap on a device traces it (its path to the internet
|
||||
// and its power feeds), a second tap opens it
|
||||
const tapped = e.target.closest('.tp-node');
|
||||
if (lastPointer === 'touch') {
|
||||
const id = tapped && tapped.querySelector('a.tp-node-link') ? tapped.dataset.node : null;
|
||||
if (id && state.pinned !== id && !e.target.closest('[data-action="select-port"]')) {
|
||||
e.preventDefault();
|
||||
state.pinned = id;
|
||||
highlight(id);
|
||||
return;
|
||||
}
|
||||
if (!tapped) {
|
||||
state.pinned = null;
|
||||
highlight(null);
|
||||
}
|
||||
}
|
||||
const port = e.target.closest('[data-action="select-port"]');
|
||||
if (port) {
|
||||
e.preventDefault();
|
||||
@@ -1212,12 +1263,14 @@ function initEvents() {
|
||||
}
|
||||
});
|
||||
const trace = e => {
|
||||
if (lastPointer === 'touch') return; // taps trace in the click handler instead
|
||||
const node = e.target.closest('.tp-node');
|
||||
highlight(node ? node.dataset.node : null);
|
||||
};
|
||||
svg.addEventListener('pointerdown', e => { lastPointer = e.pointerType; }, true);
|
||||
svg.addEventListener('mouseover', trace);
|
||||
svg.addEventListener('focusin', trace);
|
||||
svg.addEventListener('mouseleave', () => highlight(null));
|
||||
svg.addEventListener('mouseleave', () => { if (lastPointer !== 'touch') highlight(null); });
|
||||
svg.addEventListener('focusout', e => { if (!svg.contains(e.relatedTarget)) highlight(null); });
|
||||
|
||||
document.getElementById('tp-pop').addEventListener('click', e => {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="lt-page-header">
|
||||
<div>
|
||||
<h1 class="lt-page-title">Topology</h1>
|
||||
<p class="g-page-sub">Every device and cable as the switches see them right now. Drag to pan, scroll or pinch to zoom. Hover a device to trace its path to the internet; click a cable for its details, or a group of unknown devices to open it.</p>
|
||||
<p class="g-page-sub">Every device and cable as the switches see them right now. Drag to pan, scroll or pinch to zoom. Hover a device to trace its path to the internet and its power (on a touch screen, tap it once to trace and again to open it); click a cable for its details, or a group of unknown devices to open it.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+26
-1
@@ -326,10 +326,35 @@ class TestCutsheetLabels:
|
||||
'b_port': '', 'status': 'retired'}]
|
||||
g = build(items=items, cables=cables)
|
||||
(stub,) = find(g, 'Dream Machine Pro', 'stub:Dream Machine Pro:8')
|
||||
assert stub['cable'] == {'id': 7, 'label': 'C07', 'type': 'Cat6', 'color': 'Black'}
|
||||
assert stub['cable'] == {'id': 7, 'label': 'C07', 'type': 'Cat6', 'color': 'Black',
|
||||
'far': {'device': 'Patch', 'port': '1', 'kind': ''}}
|
||||
# Retired cables are not on the network any more
|
||||
assert find(g, 'Dream Machine Pro', 'host-a')[0]['cable'] is None
|
||||
|
||||
def test_unknown_device_behind_a_patch_panel_is_named_after_it(self):
|
||||
items = [{'name': 'PP1', 'device': '', 'kind': 'patch_panel'},
|
||||
{'name': 'UDM-Pro', 'device': 'Dream Machine Pro'}]
|
||||
cables = [{'id': 7, 'label': 'C07', 'a_device': 'UDM-Pro', 'a_port': '8', 'b_device': 'PP1',
|
||||
'b_port': '3', 'status': 'installed'}]
|
||||
stub = node(build(items=items, cables=cables), 'stub:Dream Machine Pro:8')
|
||||
assert stub['name'] == 'Patch panel port 3' and stub['named_by_via']
|
||||
assert stub['via'] == {'device': 'PP1', 'port': '3', 'kind': 'patch_panel', 'name': 'Patch panel port 3',
|
||||
'cable': 'C07'}
|
||||
|
||||
def test_a_named_stub_keeps_its_name_and_notes_the_panel(self):
|
||||
items = [{'name': 'PP1', 'device': '', 'kind': 'patch_panel'}]
|
||||
cables = [{'id': 2, 'label': 'C02', 'a_device': '24RJ45-POE', 'a_port': '1', 'b_device': 'PP1',
|
||||
'b_port': '2', 'status': 'installed'}]
|
||||
g = build(items=items, cables=cables)
|
||||
stub = node(g, 'stub:24RJ45-POE:1')
|
||||
assert stub['name'] == 'Micro 2 Eth2' and not stub.get('named_by_via')
|
||||
assert stub['via']['name'] == 'Patch panel port 2'
|
||||
|
||||
def test_a_cable_to_a_live_device_is_not_a_via(self):
|
||||
cables = [{'id': 3, 'label': 'C03', 'a_device': 'Dream Machine Pro', 'a_port': '8',
|
||||
'b_device': '8SFP-AGG', 'b_port': '1', 'status': 'installed'}]
|
||||
assert 'via' not in node(build(cables=cables), 'stub:Dream Machine Pro:8')
|
||||
|
||||
|
||||
class TestEmpty:
|
||||
def test_no_data_yet(self):
|
||||
|
||||
+23
-4
@@ -189,23 +189,34 @@ def build_power(nodes: Dict[str, dict], link_stats: dict, feeds: List[dict]) ->
|
||||
|
||||
def _cable_labels(items: List[dict], cables: List[dict]) -> Dict[Tuple[str, str], dict]:
|
||||
"""{(device, port): cable} for cutsheet cables still in place. A cable can name the
|
||||
device itself or a cutsheet item linked to it."""
|
||||
device_of = {i['name']: (i.get('device') or i['name']) for i in items or []}
|
||||
device itself or a cutsheet item linked to it. Each entry also says where the cable's
|
||||
other end goes ('far': {device, port, kind}), so a cable into a patch panel shows as one."""
|
||||
by_name = {i['name']: i for i in items or []}
|
||||
device_of = {name: (i.get('device') or name) for name, i in by_name.items()}
|
||||
out: Dict[Tuple[str, str], dict] = {}
|
||||
for c in cables or []:
|
||||
if c.get('status') == 'retired':
|
||||
continue
|
||||
for end in ('a', 'b'):
|
||||
for end, other in (('a', 'b'), ('b', 'a')):
|
||||
dev = c.get(f'{end}_device') or ''
|
||||
if not dev:
|
||||
continue
|
||||
far_dev = c.get(f'{other}_device') or ''
|
||||
ref = {'id': c.get('id'), 'label': c.get('label') or '', 'type': c.get('cable_type') or '',
|
||||
'color': c.get('color') or ''}
|
||||
'color': c.get('color') or '',
|
||||
'far': {'device': device_of.get(far_dev, far_dev), 'port': str(c.get(f'{other}_port') or ''),
|
||||
'kind': (by_name.get(far_dev) or {}).get('kind') or ''} if far_dev else None}
|
||||
for name in {dev, device_of.get(dev, dev)}:
|
||||
out[(name, str(c.get(f'{end}_port') or ''))] = ref
|
||||
return out
|
||||
|
||||
|
||||
def _via_name(far: dict) -> str:
|
||||
"""How to name the far end of a cable that leads to cutsheet gear, not a live device."""
|
||||
where = {'patch_panel': 'Patch panel', 'wall_jack': 'Wall jack'}.get(far['kind'], far['device'])
|
||||
return f'{where} port {far["port"]}' if far['port'] else where
|
||||
|
||||
|
||||
def _alerts_by_target(events: List[dict]) -> Dict[str, List[dict]]:
|
||||
out: Dict[str, List[dict]] = {}
|
||||
for ev in events or []:
|
||||
@@ -392,6 +403,14 @@ def build_graph(snapshot: dict, link_stats: dict, modem: Optional[dict], events:
|
||||
'alerts': [], 'alert_count': 0, 'severity': '', 'power': False,
|
||||
}
|
||||
link = add_link(here, _end(stub_id, iface=nodes[stub_id]['iface']), port)
|
||||
# The cutsheet says the cable goes into a patch panel (or other documented gear that
|
||||
# is not on the network): say so, and name a stub that has nothing better after it
|
||||
far = (link['cable'] or {}).get('far')
|
||||
if far and far['device'] not in nodes:
|
||||
nodes[stub_id]['via'] = dict(far, name=_via_name(far), cable=link['cable']['label'])
|
||||
if label == 'unknown device':
|
||||
nodes[stub_id]['name'] = nodes[stub_id]['via']['name']
|
||||
nodes[stub_id]['named_by_via'] = True
|
||||
# A stub labelled by its port name would always "match" it, so compare with what was seen
|
||||
link['name_mismatch'] = name_mismatch(pname, neighbour or mac or 'an unnamed device', sw_name, known_names)
|
||||
if link['name_mismatch']:
|
||||
|
||||
Reference in New Issue
Block a user