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>
87 lines
2.5 KiB
JavaScript
87 lines
2.5 KiB
JavaScript
// integrations/cisco-mpp-phone/aggregateProbe.js
|
|
//
|
|
// Combine MPP probe JSON payloads into a single view for rendering.
|
|
|
|
import { parseStatusJson, summarizePhoneHealthFromJson } from './statusJson.js';
|
|
import { parseDownloadStatusJson, downloadStatusWarnings } from './downloadStatusJson.js';
|
|
import { parseNsJson } from './nsJson.js';
|
|
import { parseSystemJson } from './systemJson.js';
|
|
import { parseStatusXml, summarizePhoneHealth } from './statusXml.js';
|
|
|
|
/**
|
|
* @param {object} input
|
|
* @param {string} [input.statusJson]
|
|
* @param {string} [input.statusXml]
|
|
* @param {string} [input.downloadStatusJson]
|
|
* @param {string} [input.nsJson]
|
|
* @param {string} [input.systemJson]
|
|
* @param {object[]} [input.probes]
|
|
* @returns {object}
|
|
*/
|
|
export function buildMppProbeView({
|
|
statusJson,
|
|
statusXml,
|
|
downloadStatusJson,
|
|
nsJson,
|
|
systemJson,
|
|
probes,
|
|
} = {}) {
|
|
let parsed = null;
|
|
let baseVerdict = { healthy: false, warnings: ['no status payload'], info: [] };
|
|
|
|
if (statusJson) {
|
|
parsed = parseStatusJson(statusJson);
|
|
baseVerdict = summarizePhoneHealthFromJson(parsed);
|
|
} else if (statusXml) {
|
|
parsed = parseStatusXml(statusXml);
|
|
baseVerdict = summarizePhoneHealth(parsed);
|
|
}
|
|
|
|
const download = downloadStatusJson ? parseDownloadStatusJson(downloadStatusJson) : null;
|
|
const networkNeighbor = nsJson ? parseNsJson(nsJson) : null;
|
|
const system = systemJson ? parseSystemJson(systemJson) : null;
|
|
|
|
const extraWarnings = [
|
|
...downloadStatusWarnings(download),
|
|
];
|
|
|
|
const warnings = [...(baseVerdict.warnings || [])];
|
|
for (const w of extraWarnings) {
|
|
if (!warnings.includes(w)) warnings.push(w);
|
|
}
|
|
|
|
const info = [...(baseVerdict.info || [])];
|
|
if (networkNeighbor?.switchDevice) {
|
|
info.push(`switch: ${networkNeighbor.switchDevice} ${networkNeighbor.switchPort || ''}`.trim());
|
|
}
|
|
if (download?.latestProvisioning?.url) {
|
|
const host = shortenUrl(download.latestProvisioning.url);
|
|
info.push(`last resync: ${host}`);
|
|
}
|
|
|
|
const verdict = {
|
|
healthy: warnings.length === 0,
|
|
warnings,
|
|
info,
|
|
};
|
|
|
|
return {
|
|
parsed,
|
|
download,
|
|
networkNeighbor,
|
|
system,
|
|
verdict,
|
|
probes: Array.isArray(probes) ? probes : [],
|
|
};
|
|
}
|
|
|
|
function shortenUrl(url) {
|
|
if (!url || typeof url !== 'string') return '?';
|
|
try {
|
|
const normalized = url.startsWith('http') ? url : `https://${url}`;
|
|
const u = new URL(normalized);
|
|
return u.hostname;
|
|
} catch {
|
|
return url.length > 40 ? `${url.slice(0, 40)}…` : url;
|
|
}
|
|
}
|