Keep every switch port and show SFP modules
Security / Python Security (bandit) (push) Successful in 1m50s
Test / Python Tests (pytest) (push) Successful in 1m52s
Lint / Python (flake8) (pull_request) Successful in 1m20s
Lint / Python (flake8) (push) Successful in 1m16s
Lint / JS (eslint) (pull_request) Successful in 10s
Lint / JS (eslint) (push) Successful in 15s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m5s
Test / Python Tests (pytest) (pull_request) Successful in 1m7s
Security / Python Security (bandit) (push) Successful in 1m50s
Test / Python Tests (pytest) (push) Successful in 1m52s
Lint / Python (flake8) (pull_request) Successful in 1m20s
Lint / Python (flake8) (push) Successful in 1m16s
Lint / JS (eslint) (pull_request) Successful in 10s
Lint / JS (eslint) (push) Successful in 15s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m5s
Test / Python Tests (pytest) (pull_request) Successful in 1m7s
Ports were keyed by their UniFi name, so when two ports shared a name the later one replaced the earlier. The 24-port switch lost port 13 this way (ports 13 and 14 are both "Office TV"). A repeated name is now kept as "<name> (Port N)". Traffic rates are now matched to the previous poll by port number rather than name. Names are re-read from UniFi every poll, so a port renamed there keeps its rates instead of losing them for a cycle. Collect what UniFi reports about each SFP cage: whether a module is present, its type (DAC or optic), part, serial, fault flags, and DOM readings when the module has them. The faceplate draws empty cages, optics, DACs and unidentified modules differently and outlines a faulted module in red. The port panel gets an SFP Module section. Both ends of a DAC report the same cable serial, so each end links to the other. Closes #7 Closes #8 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+29
-4
@@ -54,13 +54,38 @@ function rj45Svg(port, p) {
|
||||
}
|
||||
|
||||
// An SFP+ cage seen head-on. Fills with a module when the port has link.
|
||||
// What sits in a cage: 'empty', 'optic', 'dac', or 'module' when the module
|
||||
// doesn't say what it is. Without module data (older snapshots, or a gateway
|
||||
// that doesn't report it) a linked port is shown as an optic, as before.
|
||||
function sfpModuleKind(port) {
|
||||
const sfp = port && port.sfp;
|
||||
if (sfp) return !sfp.found ? 'empty' : (sfp.kind || 'module');
|
||||
return port && port.up ? 'optic' : 'empty';
|
||||
}
|
||||
|
||||
function sfpSvg(port, w, h) {
|
||||
const inner = port && port.up
|
||||
? `<rect class="fp-module" x="2.5" y="2.5" width="${w - 5}" height="${h - 5}" rx="1"/>
|
||||
const kind = sfpModuleKind(port);
|
||||
const sfp = port && port.sfp;
|
||||
const fault = sfp && (sfp.rx_fault || sfp.tx_fault) ? ' fp-module-fault' : '';
|
||||
const body = `<rect class="fp-module${fault}" x="2.5" y="2.5" width="${w - 5}" height="${h - 5}" rx="1"/>`;
|
||||
let inner;
|
||||
if (kind === 'optic') {
|
||||
inner = `${body}
|
||||
<rect class="fp-module-lc" x="6.5" y="6" width="9" height="${h - 12}" rx="1.2"/>
|
||||
<rect class="fp-module-lc" x="${w - 15.5}" y="6" width="9" height="${h - 12}" rx="1.2"/>`
|
||||
: `<path class="fp-cage-spring" d="M4 5 H${w - 4} M4 ${h - 5} H${w - 4}"/>
|
||||
<rect class="fp-module-lc" x="${w - 15.5}" y="6" width="9" height="${h - 12}" rx="1.2"/>`;
|
||||
} else if (kind === 'dac') {
|
||||
// A DAC's cable leaves through a boot in the middle of the module
|
||||
inner = `${body}
|
||||
<rect class="fp-dac-boot" x="${w / 2 - 7}" y="4.5" width="14" height="${h - 9}" rx="2.5"/>
|
||||
<circle class="fp-dac-cable" cx="${w / 2}" cy="${h / 2}" r="3.2"/>`;
|
||||
} else if (kind === 'module') {
|
||||
// Present but unidentified: the module body with its pull tab, no connector detail
|
||||
inner = `${body}
|
||||
<rect class="fp-cage-rail" x="${w / 2 - 6}" y="${h / 2 - 1.5}" width="12" height="3" rx="1"/>`;
|
||||
} else {
|
||||
inner = `<path class="fp-cage-spring" d="M4 5 H${w - 4} M4 ${h - 5} H${w - 4}"/>
|
||||
<rect class="fp-cage-rail" x="${w / 2 - 8}" y="${h / 2 - 2}" width="16" height="4" rx="1"/>`;
|
||||
}
|
||||
return `<rect class="fp-cage" width="${w}" height="${h}" rx="1"/>${inner}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,20 +66,66 @@ function portTitle(port, idx) {
|
||||
return escHtml(neighbor ? `${port.name} → ${neighbor}` : port.name);
|
||||
}
|
||||
|
||||
function sfpKindLabel(sfp) {
|
||||
if (sfp.kind === 'dac') return 'DAC';
|
||||
if (sfp.kind === 'optic') return sfp.compliance || 'Optic';
|
||||
return 'Module';
|
||||
}
|
||||
|
||||
function faceplatePortTitle(port, idx, role) {
|
||||
const parts = [role ? `Port ${idx} (${role})` : `Port ${idx}`];
|
||||
const sfp = port && port.sfp;
|
||||
if (!port || !port.up) {
|
||||
parts.push('no link');
|
||||
parts.push(sfp && !sfp.found ? 'empty cage' : 'no link');
|
||||
} else {
|
||||
const speed = portSpeedLabel(port);
|
||||
if (speed) parts.push(speed);
|
||||
if (port.poe_power > 0) parts.push(`${port.poe_power.toFixed(1)} W PoE`);
|
||||
}
|
||||
if (sfp && sfp.found) parts.push(sfp.part ? `${sfpKindLabel(sfp)} ${sfp.part}` : sfpKindLabel(sfp));
|
||||
if (sfp && (sfp.rx_fault || sfp.tx_fault)) parts.push('module fault');
|
||||
const neighbor = port && port.lldp && (port.lldp.system_name || port.lldp.chassis_id);
|
||||
if (neighbor) parts.push(`→ ${neighbor}`);
|
||||
return escHtml(parts.join(' · '));
|
||||
}
|
||||
|
||||
// ── SFP module section of the port panel ────────────────────────────────
|
||||
function sfpPanelHtml(sfp) {
|
||||
if (!sfp) return '';
|
||||
const row = (label, val, tip) =>
|
||||
`<div class="panel-row"><span class="panel-label"${tip ? ` data-tooltip="${escHtml(tip)}"` : ''}>${label}</span><span class="panel-val">${val}</span></div>`;
|
||||
const head = '<div class="lt-divider"><span class="lt-divider-label">SFP Module</span></div>';
|
||||
if (!sfp.found) return head + row('Module', '<span class="val-neutral">Empty cage</span>');
|
||||
|
||||
const rows = [row('Type', escHtml(sfpKindLabel(sfp)))];
|
||||
const model = [sfp.vendor, sfp.part].filter(Boolean).join(' ');
|
||||
if (model) rows.push(row('Part', escHtml(model)));
|
||||
if (sfp.serial) rows.push(row('Serial', escHtml(sfp.serial)));
|
||||
if (sfp.rx_fault || sfp.tx_fault) {
|
||||
const which = [sfp.rx_fault && 'receive', sfp.tx_fault && 'transmit'].filter(Boolean).join(' and ');
|
||||
rows.push(row('Fault', `<span class="val-crit">${which} fault</span>`, 'Flags the module itself raises: receive = loss of signal, transmit = laser fault.'));
|
||||
}
|
||||
if (sfp.rx_power_dbm != null) {
|
||||
rows.push(row('RX power', `${sfp.rx_power_dbm.toFixed(2)} dBm ${renderPowerBar(sfp.rx_power_dbm, -18, -25)}`, 'Light received from the far end'));
|
||||
}
|
||||
if (sfp.tx_power_dbm != null) {
|
||||
rows.push(row('TX power', `${sfp.tx_power_dbm.toFixed(2)} dBm ${renderPowerBar(sfp.tx_power_dbm, -10, -13)}`, 'Light this module sends'));
|
||||
}
|
||||
if (sfp.temperature_c != null) rows.push(row('Temp', `${sfp.temperature_c.toFixed(1)} °C`));
|
||||
if (sfp.voltage_v != null) rows.push(row('Voltage', `${sfp.voltage_v.toFixed(2)} V`));
|
||||
if (sfp.current_ma != null) rows.push(row('Bias', `${sfp.current_ma.toFixed(1)} mA`, 'Laser bias current'));
|
||||
if (sfp.kind === 'dac' && sfp.rx_power_dbm == null) {
|
||||
rows.push(row('Readings', '<span class="val-neutral">None: copper DACs have no optics</span>'));
|
||||
}
|
||||
const peer = sfp.cable_peer;
|
||||
if (peer) {
|
||||
const href = `${deviceUrl(peer.switch)}#port-${encodeURIComponent(peer.port_idx)}`;
|
||||
rows.push(row('Other end', `<a class="device-link" href="${escHtml(href)}">${escHtml(peer.switch)} port ${escHtml(String(peer.port_idx))}</a>`,
|
||||
'Both ends of this DAC report the same cable serial'));
|
||||
}
|
||||
return head + rows.join('');
|
||||
}
|
||||
|
||||
// Faceplate jacks are too small for text, so one line under the panel names
|
||||
// the hovered or selected port.
|
||||
function updateFaceplateReadout(el) {
|
||||
@@ -305,6 +351,7 @@ function renderPanel(swName, idx) {
|
||||
<div class="panel-row"><span class="panel-label" data-tooltip="Autonegotiation: NIC and switch automatically agree speed and duplex.">Auto-neg</span><span class="panel-val val-neutral">${autoneg}</span></div>
|
||||
<div class="panel-row"><span class="panel-label">Media</span><span class="panel-val">${escHtml(mediaStr)}</span></div>
|
||||
|
||||
${sfpPanelHtml(d.sfp)}
|
||||
${poeHtml}
|
||||
${trafficHtml}
|
||||
${errHtml}
|
||||
|
||||
@@ -1210,6 +1210,9 @@ tr.device-row.is-selected { background: var(--bg-tertiary); box-shadow: inset 3p
|
||||
.fp-cage-rail { fill: #3b3c41; }
|
||||
.fp-module { fill: #a5a7ad; stroke: #6a6b70; stroke-width: .6; }
|
||||
.fp-module-lc { fill: #2a4a7f; stroke: #1a2a44; stroke-width: .5; }
|
||||
.fp-module-fault { stroke: #e0312b; stroke-width: 1.4; }
|
||||
.fp-dac-boot { fill: #2b2c30; stroke: #17171a; stroke-width: .5; }
|
||||
.fp-dac-cable { fill: #111113; }
|
||||
|
||||
.fp-led-idle { fill: #6a6b70; }
|
||||
.fp-led-off { fill: #4b4c50; }
|
||||
|
||||
Reference in New Issue
Block a user