Cutsheet: port names in UniFi that no longer fit, document a cable from topology
Lint / JS (eslint) (push) Successful in 23s
Lint / Python (flake8) (push) Successful in 1m10s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / Python (flake8) (pull_request) Successful in 53s
Lint / JS (eslint) (pull_request) Successful in 11s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (push) Successful in 1m26s
Test / Python Tests (pytest) (push) Successful in 1m49s
Security / Python Security (bandit) (pull_request) Successful in 2m17s
Test / Python Tests (pytest) (pull_request) Successful in 2m12s
Lint / JS (eslint) (push) Successful in 23s
Lint / Python (flake8) (push) Successful in 1m10s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / Python (flake8) (pull_request) Successful in 53s
Lint / JS (eslint) (pull_request) Successful in 11s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (push) Successful in 1m26s
Test / Python Tests (pytest) (push) Successful in 1m49s
Security / Python Security (bandit) (pull_request) Successful in 2m17s
Test / Python Tests (pytest) (pull_request) Successful in 2m12s
- topology.port_name_report: switch port names that no longer fit what is plugged in, as a checklist with suggested names: named after the wrong device, named after a device that moved to another port, named with nothing plugged in (and who was last seen there), and still "Port N" with a known device on it. Ports named after a device that is only off are left alone. Gandalf only reports; it never renames anything in UniFi. - /api/cutsheet returns it as port_names; the cutsheet page shows it as "Port names in UniFi", grouped, with a summary chip. - The topology cable panel's "not documented" gets a "document it" link that opens the cutsheet's new-cable form with both ends, the NIC and DAC filled in; /cutsheet?... now takes b_device, b_port and cable_type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+51
-1
@@ -74,6 +74,7 @@ function renderSummary() {
|
||||
chip(matches, 'match what Gandalf sees', 'cs-chip-ok', 'cs-cables-section'),
|
||||
chip(problems, problems === 1 ? 'problem' : 'problems', problems ? 'cs-chip-bad' : '', 'cs-cables-section'),
|
||||
chip(_cs.suggestions.length, 'undocumented links', _cs.suggestions.length ? 'cs-chip-warn' : '', 'cs-suggest-section'),
|
||||
chip(portFixes(), 'port names to fix', portFixes() ? 'cs-chip-warn' : '', 'cs-portnames-section'),
|
||||
chip(labels, 'labels to make', labels ? 'cs-chip-warn' : '', 'cs-labels-section'),
|
||||
].join('');
|
||||
}
|
||||
@@ -153,6 +154,51 @@ function renderSuggestions() {
|
||||
${_showAllSuggestions ? 'Show fewer' : `Show all ${list.length}`}</button>` : ''}`;
|
||||
}
|
||||
|
||||
// ── Port names in UniFi ─────────────────────────────────────────────────
|
||||
const PORT_NAME_GROUPS = [
|
||||
['wrong', 'Named after the wrong device', 'cs-chip-bad'],
|
||||
['moved', 'Named after a device that moved', 'cs-chip-warn'],
|
||||
['empty', 'Named, but nothing is plugged in', ''],
|
||||
['unnamed', 'Unnamed, with a known device plugged in', ''],
|
||||
];
|
||||
|
||||
// Wrong and moved names are worth fixing; empty and unnamed ports are only worth a look
|
||||
function portFixes() {
|
||||
return (_cs.port_names || []).filter(r => r.kind === 'wrong' || r.kind === 'moved').length;
|
||||
}
|
||||
|
||||
function renderPortNames() {
|
||||
const rows = _cs.port_names || [];
|
||||
document.getElementById('cs-portnames-count').textContent = rows.length;
|
||||
const wrap = document.getElementById('cs-portnames');
|
||||
if (!rows.length) {
|
||||
wrap.innerHTML = emptyState('✅', 'Every port name fits what is plugged in', '');
|
||||
return;
|
||||
}
|
||||
wrap.innerHTML = PORT_NAME_GROUPS.map(([kind, title, cls]) => {
|
||||
const list = rows.filter(r => r.kind === kind);
|
||||
if (!list.length) return '';
|
||||
const table = `<div class="lt-table-wrap">
|
||||
<table class="lt-table lt-table-sm">
|
||||
<caption class="lt-sr-only">${esc(title)}</caption>
|
||||
<thead><tr><th>Switch port</th><th>Name in UniFi</th><th>What Gandalf sees</th><th>Suggested name</th></tr></thead>
|
||||
<tbody>${list.map(r => `
|
||||
<tr>
|
||||
<td>${deviceLink(r.switch)} <a class="cs-port" href="/device/${encodeURIComponent(r.switch)}#port-${esc(r.port_idx)}">port ${esc(r.port_idx)}</a></td>
|
||||
<td>${esc(r.port_name)}</td>
|
||||
<td>${esc(r.detail)}</td>
|
||||
<td>${r.suggestion ? `<code>${esc(r.suggestion)}</code>` : '<span class="val-neutral">your call</span>'}</td>
|
||||
</tr>`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>`;
|
||||
// The long, low-priority group starts folded
|
||||
const open = kind !== 'unnamed' ? ' open' : '';
|
||||
return `<details class="cs-portname-group"${open}>
|
||||
<summary><span class="cs-chip ${cls}"><b>${list.length}</b> ${esc(title)}</span></summary>${table}</details>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function cableAt(name, port, side) {
|
||||
return _cs.cables.find(c => c.status !== 'retired' &&
|
||||
['a', 'b'].some(e => c[`${e}_device`] === name && c[`${e}_port`] === String(port) && c[`${e}_side`] === side));
|
||||
@@ -331,6 +377,7 @@ function render() {
|
||||
renderSummary();
|
||||
renderCables();
|
||||
renderSuggestions();
|
||||
renderPortNames();
|
||||
renderPanels();
|
||||
renderLabels();
|
||||
renderRack();
|
||||
@@ -700,7 +747,10 @@ function printLabels() {
|
||||
function openFromQuery() {
|
||||
const q = new URLSearchParams(window.location.search);
|
||||
if (!CS_CAN_EDIT || !q.get('a_device')) return;
|
||||
openCable(null, { a_device: q.get('a_device'), a_port: q.get('a_port') || '' });
|
||||
openCable(null, {
|
||||
a_device: q.get('a_device'), a_port: q.get('a_port') || '',
|
||||
b_device: q.get('b_device') || '', b_port: q.get('b_port') || '', cable_type: q.get('cable_type') || '',
|
||||
});
|
||||
history.replaceState(null, '', window.location.pathname);
|
||||
}
|
||||
|
||||
|
||||
@@ -1102,6 +1102,9 @@ polygon.fp-led-off { fill: #6b6c71; }
|
||||
.cs-chip-bad { border-color: var(--status-critical, #e0312b); }
|
||||
.cs-chip-bad b { color: var(--status-critical, #e0312b); }
|
||||
.cs-chip-warn b { color: var(--accent-amber, #f0a020); }
|
||||
.cs-portname-group { margin: 0 0 12px; }
|
||||
.cs-portname-group > summary { cursor: pointer; list-style-position: inside; margin-bottom: 8px; }
|
||||
.cs-portname-group code { white-space: nowrap; }
|
||||
.cs-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
|
||||
.cs-filters .lt-input { flex: 1 1 240px; min-width: 0; }
|
||||
.cs-filters .lt-select { flex: 0 1 180px; }
|
||||
|
||||
+18
-1
@@ -974,6 +974,23 @@ function endHtml(end, byId) {
|
||||
return `${name}${where ? ` · ${where}` : ''}`;
|
||||
}
|
||||
|
||||
// A link to the cutsheet's new-cable form, filled in with both ends as Gandalf sees them
|
||||
function documentLink(link, byId) {
|
||||
if (!TOPO_CAN_EDIT || link.ghost || link.bundle) return '';
|
||||
const sw = [link.a, link.b].find(e => e.port_idx != null && (byId[e.node] || {}).kind !== 'stub');
|
||||
if (!sw) return '';
|
||||
const far = sw === link.a ? link.b : link.a;
|
||||
const farNode = byId[far.node] || {};
|
||||
const q = new URLSearchParams({ a_device: sw.node, a_port: String(sw.port_idx) });
|
||||
if (farNode.kind && farNode.kind !== 'stub') {
|
||||
q.set('b_device', far.node);
|
||||
if (far.port_idx != null) q.set('b_port', String(far.port_idx));
|
||||
else if (far.iface) q.set('b_port', far.iface);
|
||||
}
|
||||
if (link.medium === 'dac') q.set('cable_type', 'DAC');
|
||||
return ` · <a class="device-link" href="/cutsheet?${esc(q.toString())}">document it</a>`;
|
||||
}
|
||||
|
||||
function showPanel(link) {
|
||||
const byId = Object.fromEntries(state.data.nodes.map(n => [n.id, n]));
|
||||
const panel = document.getElementById('tp-panel');
|
||||
@@ -1001,7 +1018,7 @@ function showPanel(link) {
|
||||
? `<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>');
|
||||
row('Cutsheet', `<span class="tp-dim-text">not documented</span>${documentLink(link, byId)}`);
|
||||
}
|
||||
const warn = link.name_mismatch
|
||||
? `<p class="tp-panel-warn">⚠ The port is named after <strong>${esc(link.name_mismatch.named)}</strong>, but <strong>${esc(link.name_mismatch.actual)}</strong> is plugged into it. Rename the port in UniFi, or check the cable.</p>`
|
||||
|
||||
Reference in New Issue
Block a user