// 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, }; }