/** * Prueft die Zuordnung Geraetetyp -> Werkzeuge. * * Anlass: "SNMP-Switch" stand an jeder IP-Kamera und erzeugte dort eine * Messung "nicht messbar" im Kundenprotokoll. Wichtiger als das Wegsortieren * ist aber, dass NICHTS verschwindet: deviceType ist geraten. * * Start: node tools/pruefe-geraeteaktionen.mjs */ const { passtZuGeraet, teileNachGeraetetyp } = await import('../src/lib/tools/geraeteaktionen.ts'); const WERKZEUGE = [{ id: 'ping' }, { id: 'portscan' }, { id: 'snmp' }]; const faelle = [ { typ: 'Kamera', snmpVorn: false, name: 'IP-Kamera -> SNMP nachrangig' }, { typ: 'IP-Kamera', snmpVorn: false, name: 'Schreibweise mit Praefix' }, { typ: 'Switch', snmpVorn: true, name: 'Switch -> SNMP vorn' }, { typ: 'SNMP-Switch', snmpVorn: true, name: 'Teilstring trifft' }, { typ: 'Drucker', snmpVorn: true, name: 'Drucker koennen SNMP (Toner/Zaehler)' }, { typ: 'NAS', snmpVorn: true, name: 'NAS -> SNMP vorn' }, { typ: 'Router', snmpVorn: true, name: 'Router -> SNMP vorn' }, { typ: 'Windows-PC', snmpVorn: false, name: 'PC -> SNMP nachrangig' }, { typ: 'Wallbox', snmpVorn: false, name: 'Wallbox spricht Modbus, nicht SNMP' }, { typ: 'IoT/SPS', snmpVorn: false, name: 'SPS spricht Modbus, nicht SNMP' }, { typ: '', snmpVorn: true, name: 'LEER -> alles gleichrangig (nie weniger)' }, { typ: undefined, snmpVorn: true, name: 'UNBEKANNT -> alles gleichrangig' }, { typ: 'Linux-Gerät', snmpVorn: false, name: 'Linux-Geraet -> nachrangig, aber erreichbar' }, ]; let fehler = 0; for (const f of faelle) { const { passend, nachrangig } = teileNachGeraetetyp(WERKZEUGE, f.typ); const snmpVorn = passend.some((t) => t.id === 'snmp'); // Zwei harte Zusicherungen: die erwartete Einsortierung UND dass kein // Werkzeug verschwindet. const vollzaehlig = passend.length + nachrangig.length === WERKZEUGE.length; const pingVorn = passend.some((t) => t.id === 'ping'); const portVorn = passend.some((t) => t.id === 'portscan'); const ok = snmpVorn === f.snmpVorn && vollzaehlig && pingVorn && portVorn; if (!ok) fehler++; console.log(`${ok ? 'OK ' : 'FEHL'} ${f.name}`); console.log(` typ="${f.typ}" vorn=[${passend.map((t) => t.id)}] nachrangig=[${nachrangig.map((t) => t.id)}]`); } console.log(fehler === 0 ? 'ALLE FAELLE KORREKT' : `${fehler} FEHLER`); process.exit(fehler === 0 ? 0 : 1);