Advertisement
vitareinforce

simulasi

Feb 7th, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // Include Libraries
  2. const axios = require('axios')
  3. const soapRequest = require('easy-soap-request')
  4. const parseString = require('xml2js').parseString
  5. const fs = require('fs')
  6. require('dotenv').config()
  7.  
  8. // configuration
  9. const periodic = process.env.periodic
  10.  
  11. function sleep(millis) {
  12. return new Promise(resolve => setTimeout(resolve, millis));
  13. }
  14.  
  15. async function ambildata(ip) {
  16.  
  17. console.log("File Test:" + ip)
  18.  
  19. const destination_url = process.env.server_api
  20. // liat isi message dari file
  21. fs.readFile(ip, 'utf8' , (err, data) => {
  22. parseString(data, async function (err, msg) {
  23. let json = {
  24. "ip_address": ip,
  25. "message": msg['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['GetAttLogResponse'][0]['Row']
  26. }
  27. fs.writeFile('rawdata.'+ip+'.txt', data, function (err) {
  28. if (err) return console.log(err);
  29. console.log('saved log file xml');
  30. })
  31. fs.writeFile('machinedata.'+ip+'.txt', JSON.stringify(msg, null, 4), function (err) {
  32. if (err) return console.log(err);
  33. console.log('saved log file json');
  34. })
  35. axios.post(destination_url, json).then(function (post) {
  36. console.log(post.status)
  37. })
  38. })
  39. console.log("Finish")
  40. })
  41. }
  42.  
  43. async function main() {
  44. ambildata('rawdata.192.168.1.201.txt')
  45. await sleep(periodic)
  46. }
  47.  
  48. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement