wg-eventUP.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // import * as http from 'http';
  2. const os = require('os');
  3. const http = require('http')
  4. let cpuUse, memoryUse, newSessions, nowTime, zySignDate, zySignId;
  5. function getTimeNow(){
  6. const currentDateT = new Date();
  7. console.log('当前系统时间:', currentDateT);
  8. const currentDate = new Date();
  9. const hours = String(currentDate.getHours()).padStart(2, '0');
  10. const minutes = String(currentDate.getMinutes()).padStart(2, '0');
  11. const seconds = String(currentDate.getSeconds()).padStart(2, '0');
  12. console.log('当前系统时间:', hours, minutes, seconds);
  13. const currentDay = new Date();
  14. const year = currentDay.getFullYear();
  15. const month = String(currentDay.getMonth() + 1).padStart(2, '0'); // 注意月份是从0开始计数的,所以要加1
  16. const day = String(currentDay.getDate()).padStart(2, '0');
  17. console.log('当前日期:', year, month, day);
  18. nowTime = year + month + day + hours + minutes + seconds;
  19. console.log(nowTime);
  20. }
  21. function getLoginSession(){
  22. const getToken = JSON.stringify({
  23. "grantType": "password",
  24. "userName": "aqtx",
  25. "value": "123456"
  26. });
  27. const options = {
  28. hostname: '192.168.1.15',
  29. port: 6334,
  30. path: '/rest/plat/v1/sessions',
  31. method: 'PUT',
  32. headers: {
  33. 'Content-Type': 'application/json',
  34. 'Content-Length': getToken.length,
  35. 'Accept-Language': 'zh-CN',
  36. },
  37. };
  38. const req = http.request(options, res => {
  39. console.log(`statusCode: ${res.statusCode}`);
  40. res.on('data', d => {
  41. process.stdout.write(d);
  42. newSessions = JSON.parse(d).accessSession;
  43. });
  44. });
  45. req.on('error', error => {
  46. console.error(error);
  47. });
  48. req.write(getToken);
  49. req.end();
  50. }
  51. function getZySign(){
  52. const eventLog =JSON.stringify({
  53. "occurrenceTime": nowTime
  54. });
  55. console.log(eventLog);
  56. console.log('-------------------------------------');
  57. const datate = JSON.stringify({
  58. "data": eventLog
  59. });
  60. const signdata = {
  61. "data": eventLog
  62. }
  63. const abc = JSON.stringify(signdata);
  64. console.log(signdata);
  65. console.log('-------------------------------------');
  66. const options = {
  67. hostname: '192.168.6.10',
  68. port: 9464,
  69. path: '/microservice/signature_verification/signature',
  70. method: 'POST',
  71. headers: {
  72. 'Content-Type': 'application/json',
  73. 'Content-Length': Buffer.byteLength(abc),
  74. 'Accept-Language': 'zh-CN',
  75. },
  76. };
  77. const req = http.request(options, res => {
  78. console.log(`statusCode: ${res.statusCode}`);
  79. res.on('data', d => {
  80. process.stdout.write(d);
  81. console.log('\n');
  82. zySignDate = JSON.parse(d).sign_data;
  83. zySignId = JSON.parse(d).ID_data;
  84. });
  85. });
  86. req.on('error', error => {
  87. console.error(error);
  88. });
  89. req.write(JSON.stringify(signdata));
  90. req.end();
  91. }
  92. function eventUP(){
  93. const deviceType = {
  94. "incidentDeviceIp": "192.168.3.240",
  95. "incidentDeviceType": "1004",
  96. "eventTitle": "其他",
  97. "occurrenceTime": nowTime,
  98. "eventType": "99",
  99. "srcIp": "192.168.3.240",
  100. "srcPort": 80,
  101. "srcMac": "",
  102. "dstIp": "192.168.5.11",
  103. "dstPort": 80,
  104. "dstMac": "",
  105. "protocol": "TCP",
  106. "eventContent": "密码卡设备检测",
  107. "description": "search",
  108. "severity": "low",
  109. "signData": zySignDate,
  110. "idData": zySignId
  111. };
  112. console.log(`事件json:${JSON.stringify(deviceType)}`);
  113. const options = {
  114. hostname: '192.168.1.15',
  115. port: 6334,
  116. // path: '/rest/v1/logInfo/aqtx20123060703523',
  117. path: `/rest/v1/securityevent/aqtx${nowTime}`,
  118. method: 'PUT',
  119. headers: {
  120. 'Content-Type': 'application/json',
  121. 'Content-Length': Buffer.byteLength(JSON.stringify(deviceType)),
  122. 'X-Auth-Token': newSessions,
  123. },
  124. };
  125. const req = http.request(options, res => {
  126. console.log(`statusCode: ${res.statusCode}`);
  127. res.on('data', d => {
  128. process.stdout.write(d);
  129. });
  130. });
  131. req.on('error', error => {
  132. console.error(error);
  133. });
  134. req.write(JSON.stringify(deviceType));
  135. req.end();
  136. }
  137. function upOnce(){
  138. getTimeNow();
  139. console.log(`当前上传时间:${nowTime}`);
  140. getLoginSession();
  141. getZySign();
  142. setTimeout(()=>{
  143. console.log(`签名数据为: ${zySignDate}`);
  144. console.log(`签名标识为: ${zySignId}`);
  145. console.log(`会话session: ${newSessions}`);
  146. eventUP();
  147. }, 5000);
  148. }
  149. // upOnce();
  150. setInterval(upOnce, 3*60*1000);