collabSupport/commands/vcMonitor.js
jmcqueen 351f89a9a4 Initial commit: CollabFinder Webex bot
Multi-integration Webex chat/HTTP bot that unifies phone, AV, and
network status for retail store support. Consolidates data from
Webex Calling, Meraki, Workspace ONE (MDM), Atlas AMP, RED digital
signage, and OptiSigns into rich per-store status commands.

Key surfaces:
- /phonestatus, /avstatus — per-store phone & AV device reports with
  clickable Meraki deep-links and per-port detail.
- /webexhost — check/assign Webex Meetings host licenses via the
  Service App; adaptive-card confirmation flow, HTTP-API-gated.
- /offboarduser — full Webex Admin offboarding (auth revoke, device
  wipe, license removal); adaptive-card confirmation.
- /jirapoll — on-demand trigger for the hourly Jira poller.
- /bulkavstatuscsv — bulk store CSV export with concurrency limits.

Automation:
- Hourly Jira poller (node-cron) with an X.AI (Grok) ticket classifier
  that categorizes unassigned tickets as phone/av/skip, extracts store
  numbers from free-text, and enriches Jira with the same detailed
  markdown the chat commands emit (converted to Jira ADF, preserves
  bold + Meraki links). Idempotent via a `bot-enriched` Jira label.

Architecture:
- Node.js 20+, ESM, Express 5, webex-node-bot-framework.
- Layered integrations (integrations/*), services (services/*),
  commands (commands/*), utils (utils/*).
- Shared markdown renderers (services/renderers/*) feed both chat
  handlers and the Jira poller so the two surfaces stay in sync.
- Hand-rolled markdown-to-ADF converter (utils/markdownToAdf.js) —
  no new npm dependency.
- Node built-in test runner (`node --test tests/*.test.js`), 30 tests
  covering the converter, renderers, and poller ADF assembly.

Docker + docker-compose deployment. Config via .env
(see .env.example for the full option surface).
2026-07-01 16:55:03 -04:00

71 lines
3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// src/commands/vcMonitor.js
// Thin handler for /vcMonitor <serialNumber> [start|stop|status] [Full|Limited|...]
// First iteration: on-demand start of packet capture via cloud xAPI ExtendedLogging.
import {
startPacketCapture,
stopPacketCapture,
getExtendedLoggingStatus
} from '../services/vcMonitorService.js';
import { logger } from '../utils/logger.js';
export async function handleVcMonitor(bot, trigger) {
logger('vc-monitor', 'Handler entered');
const args = trigger.args || [];
const query = trigger.query || {};
const serialNumber = args[0]?.trim() || query.serial || query.serialNumber || query.s || query.serialnum;
if (!serialNumber) {
logger('vc-monitor', 'No serial number provided showing usage', 'warn');
await bot.say('markdown',
'**Usage:** `/vcMonitor <serialNumber> [action] [PacketDumpType]`\n\n' +
'Actions (default = start):\n' +
'• `start` (or omit) — begin capture\n' +
'• `stop` — stop the current extended logging session\n' +
'• `status` — show current Logging.ExtendedLogging.Mode + PacketDump\n\n' +
'PacketDumpType (only for start):\n' +
'• `Full` — everything including RTP media (~3 min)\n' +
'• `Limited` — non-RTP/signaling only (~10 min)\n' +
'• `FullRotate` — rolling capture (last ~1h worth)\n\n' +
'Examples:\n' +
'• `/vcMonitor FOC2419NTN2` — start Full capture (on demand)\n' +
'• `/vcMonitor FOC2419NTN2 Limited`\n' +
'• `/vcMonitor FOC2419NTN2 stop`\n' +
'• `/vcMonitor FOC2419NTN2 status`\n\n' +
'**After capture:** Download the full log bundle from Control Hub (Issues & Diagnostics → System Logs). The .pcap files are inside the bundle.'
);
return;
}
// Parse action + optional dump type
let action = (args[1] || query.action || 'start').toLowerCase().trim();
let dumpType = args[2] || query.type || query.packetDump || query.dump || 'Full';
// Convenience: allow `/vcMonitor SERIAL Full` to mean start Full
if (['full', 'limited', 'fullrotate', 'none'].includes(action)) {
dumpType = action;
action = 'start';
}
logger('vc-monitor', `Command for ${serialNumber}: action=${action} dumpType=${dumpType}`);
try {
if (action === 'start' || action === 'begin' || action === 'capture') {
await startPacketCapture(bot, serialNumber, dumpType);
} else if (action === 'stop' || action === 'end') {
await stopPacketCapture(bot, serialNumber);
} else if (action === 'status' || action === 'show' || action === 'state') {
await getExtendedLoggingStatus(bot, serialNumber);
} else {
await bot.say('markdown',
`Unknown action "${action}". Supported: start, stop, status.\n\n` +
`Example: \`/vcMonitor ${serialNumber} start Full\``
);
}
} catch (error) {
// Service already sent user-facing error + logged. Just make sure we don't crash the handler.
logger('vc-monitor', `Handler caught error for ${serialNumber}/${action}: ${error.message}`, 'error');
}
}