// import * as http from 'http'; const os = require('os'); const http = require('http') let cpuUse, memoryUse, newSessions, nowTime, zySignDate, zySignId; function getTimeNow(){ const currentDateT = new Date(); console.log('当前系统时间:', currentDateT); const currentDate = new Date(); const hours = String(currentDate.getHours()).padStart(2, '0'); const minutes = String(currentDate.getMinutes()).padStart(2, '0'); const seconds = String(currentDate.getSeconds()).padStart(2, '0'); console.log('当前系统时间:', hours, minutes, seconds); const currentDay = new Date(); const year = currentDay.getFullYear(); const month = String(currentDay.getMonth() + 1).padStart(2, '0'); // 注意月份是从0开始计数的,所以要加1 const day = String(currentDay.getDate()).padStart(2, '0'); console.log('当前日期:', year, month, day); nowTime = year + month + day + hours + minutes + seconds; console.log(nowTime); } function getLoginSession(){ const getToken = JSON.stringify({ "grantType": "password", "userName": "aqtx", "value": "123456" }); const options = { hostname: '192.168.1.15', port: 6334, path: '/rest/plat/v1/sessions', method: 'PUT', headers: { 'Content-Type': 'application/json', 'Content-Length': getToken.length, 'Accept-Language': 'zh-CN', }, }; const req = http.request(options, res => { console.log(`statusCode: ${res.statusCode}`); res.on('data', d => { process.stdout.write(d); newSessions = JSON.parse(d).accessSession; }); }); req.on('error', error => { console.error(error); }); req.write(getToken); req.end(); } function getZySign(){ const eventLog =JSON.stringify({ "occurrenceTime": nowTime }); console.log(eventLog); console.log('-------------------------------------'); const datate = JSON.stringify({ "data": eventLog }); const signdata = { "data": eventLog } const abc = JSON.stringify(signdata); console.log(signdata); console.log('-------------------------------------'); const options = { hostname: '192.168.6.10', port: 9464, path: '/microservice/signature_verification/signature', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(abc), 'Accept-Language': 'zh-CN', }, }; const req = http.request(options, res => { console.log(`statusCode: ${res.statusCode}`); res.on('data', d => { process.stdout.write(d); console.log('\n'); zySignDate = JSON.parse(d).sign_data; zySignId = JSON.parse(d).ID_data; }); }); req.on('error', error => { console.error(error); }); req.write(JSON.stringify(signdata)); req.end(); } function eventUP(){ const deviceType = { "incidentDeviceIp": "192.168.3.240", "incidentDeviceType": "1004", "eventTitle": "其他", "occurrenceTime": nowTime, "eventType": "99", "srcIp": "192.168.3.240", "srcPort": 80, "srcMac": "", "dstIp": "192.168.5.11", "dstPort": 80, "dstMac": "", "protocol": "TCP", "eventContent": "密码卡设备检测", "description": "search", "severity": "low", "signData": zySignDate, "idData": zySignId }; console.log(`事件json:${JSON.stringify(deviceType)}`); const options = { hostname: '192.168.1.15', port: 6334, // path: '/rest/v1/logInfo/aqtx20123060703523', path: `/rest/v1/securityevent/aqtx${nowTime}`, method: 'PUT', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(JSON.stringify(deviceType)), 'X-Auth-Token': newSessions, }, }; const req = http.request(options, res => { console.log(`statusCode: ${res.statusCode}`); res.on('data', d => { process.stdout.write(d); }); }); req.on('error', error => { console.error(error); }); req.write(JSON.stringify(deviceType)); req.end(); } function upOnce(){ getTimeNow(); console.log(`当前上传时间:${nowTime}`); getLoginSession(); getZySign(); setTimeout(()=>{ console.log(`签名数据为: ${zySignDate}`); console.log(`签名标识为: ${zySignId}`); console.log(`会话session: ${newSessions}`); eventUP(); }, 5000); } // upOnce(); setInterval(upOnce, 3*60*1000);