collabSupport/integrations/cisco-mpp-phone/nsJson.js
jmcqueen f7953b8eb5 Add MPP desk phone diagnostics follow-up to /phonestatus via relay.
Wire CP-78xx probe discovery, relay phone-probe commands, and a chat follow-up message so store desk phones get registration, switch, and provisioning detail alongside DECT and WAN diagnostics.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 18:01:01 -04:00

54 lines
1.6 KiB
JavaScript

// integrations/cisco-mpp-phone/nsJson.js
//
// Parser for /ns.json (network statistics + LLDP/CDP neighbors).
import { coerceRows, fieldsFromRows } from './jsonRows.js';
const ERROR_COUNTER_FIELDS = [
'RxDropPkts', 'RxUndersizePkts', 'RxOversizePkts', 'RxFragments', 'RxJabbers',
'RxAlignErrs', 'RxFCSErrs', 'RxSymbolErrs', 'TxDropPkts', 'TxCollisions',
'TxLateCollisions',
];
/**
* @param {string|Array} raw
* @returns {object}
*/
export function parseNsJson(raw) {
const rows = coerceRows(raw);
const fields = fieldsFromRows(rows);
const neighbor = {
lldpDevice: fields['LLDPNeighborDeviceId'] || null,
lldpPort: fields['LLDPNeighborPort'] || null,
lldpIp: fields['LLDPNeighborIP'] || null,
cdpDevice: fields['CDPNeighborDeviceId'] || null,
cdpPort: fields['CDPNeighborPort'] || null,
cdpIp: fields['CDPNeighborIP'] || null,
};
const switchDevice = neighbor.lldpDevice || neighbor.cdpDevice || null;
const switchPort = neighbor.lldpPort || neighbor.cdpPort || null;
const switchIp = neighbor.lldpIp || neighbor.cdpIp || null;
const portSpeed = (fields['PortSpeed'] || '').trim() || null;
const errorCounters = {};
for (const key of ERROR_COUNTER_FIELDS) {
const val = fields[key];
if (val != null && val !== '' && val !== '0') {
errorCounters[key] = val;
}
}
return {
fields,
neighbor,
switchDevice,
switchPort,
switchIp,
portSpeed,
errorCounters,
txFrames: fields['Tx Frames'] || fields['TxtotalGoodPkt'] || null,
rxFrames: fields['Rx Frames'] || fields['RxtotalPkt'] || null,
};
}