UNPKG

iobroker.kisshome-defender

Version:
110 lines 4.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const node_crypto_1 = require("node:crypto"); const utils_1 = require("./lib/utils"); const workingDir = 'C:/pWork/iobroker-data/kisshome-defender'; const result = { analysisDurationMs: 0, totalBytes: 0, packets: 0, results: [], countries: {}, }; const MACs = [ '00:11:22:33:44:55', '66:77:88:99:AA:BB', 'CC:DD:EE:FF:00:11', '22:33:44:55:66:77', '88:99:AA:BB:CC:DD', ]; for (let i = -7; i <= 0; i++) { const date = new Date(); date.setDate(date.getDate() + i); for (let h = 0; h < 24; h++) { const time = new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, Math.floor(Math.random() * 60), 0).toISOString(); const oneResult = { uuid: (0, node_crypto_1.randomUUID)(), time, isAlert: false, score: 0, // Worst score of all detections in this result statistics: { suricataTotalRules: 0, suricataAnalysisDurationMs: 0, analysisDurationMs: 0, totalBytes: 0, packets: 0, devices: [], }, detections: [], }; let theBiggestScore = 0; let isAlert = false; for (let a = 0; a < MACs.length; a++) { const mac = MACs[a]; const bytes = mac === '88:99:AA:BB:CC:DD' ? Math.floor(Math.random() * 100000000) : Math.floor(Math.random() * 1000000); const packets = Math.floor(bytes / 1000); // Assuming 1000 bytes per packet oneResult.statistics.packets += packets; oneResult.statistics.totalBytes += bytes; oneResult.statistics.devices.push({ mac, data_volume: { packet_count: 5, data_volume_bytes: bytes, }, external_ips: { '1.1.1.1': { country: 'DE', data_volume_bytes: Math.floor(bytes * 0.5), // 50% of bytes for Germany }, '1.1.1.2': { country: 'US', data_volume_bytes: Math.floor(bytes * 0.3), // 30% of bytes for US }, '1.1.1.3': { country: 'FR', data_volume_bytes: Math.floor(bytes * 0.2), // 20% of bytes for France }, }, }); result.totalBytes += bytes; result.packets += packets; const score = Math.floor(Math.random() * 1000) / 10; // Random score between 0 and 100 const scoreMl = Math.floor(Math.random() * 1000) / 10; // Random score between 0 and 100 const biggestScore = Math.max(score, scoreMl); // Generate for each MAC a detection const detection = { mac, suricata: [ { type: score > 90 ? 'Alert' : 'Normal', description: score > 90 ? 'Dangerous alert' : 'Nothing special', first_occurrence: time, number_occurrences: score > 70 ? Math.floor(Math.random() * 5) + 1 : 0, // Random occurrences between 1 and 5 score, // Random score between 0 and 99 }, ], ml: { type: scoreMl > 90 ? 'Alert' : 'Normal', description: scoreMl > 90 ? 'Dangerous ML alert' : scoreMl > 70 ? 'Just ML warning' : 'OK', first_occurrence: time, number_occurrences: scoreMl > 70 ? Math.floor(Math.random() * 3) + 1 : 0, // Random occurrences between 1 and 3 score: scoreMl, // Random score between 0 and 49 }, worstScore: biggestScore, isAlert: biggestScore > 10, // Assuming the worst type is Alert for this example }; oneResult.detections.push(detection); theBiggestScore = Math.max(theBiggestScore, biggestScore); isAlert = isAlert || detection.isAlert; } oneResult.isAlert = isAlert; oneResult.score = theBiggestScore; result.results.push(oneResult); } } (0, node_fs_1.writeFileSync)((0, node_path_1.join)(workingDir, `${(0, utils_1.getTimestamp)()}.json`), JSON.stringify(result, null, 2)); //# sourceMappingURL=generateTestData.js.map