Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include Libraries
- const axios = require('axios')
- const soapRequest = require('easy-soap-request')
- const parseString = require('xml2js').parseString
- const fs = require('fs')
- require('dotenv').config()
- // configuration
- const periodic = process.env.periodic
- function sleep(millis) {
- return new Promise(resolve => setTimeout(resolve, millis));
- }
- async function ambildata(ip) {
- console.log("File Test:" + ip)
- const destination_url = process.env.server_api
- // liat isi message dari file
- fs.readFile(ip, 'utf8' , (err, data) => {
- parseString(data, async function (err, msg) {
- let json = {
- "ip_address": ip,
- "message": msg['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['GetAttLogResponse'][0]['Row']
- }
- fs.writeFile('rawdata.'+ip+'.txt', data, function (err) {
- if (err) return console.log(err);
- console.log('saved log file xml');
- })
- fs.writeFile('machinedata.'+ip+'.txt', JSON.stringify(msg, null, 4), function (err) {
- if (err) return console.log(err);
- console.log('saved log file json');
- })
- axios.post(destination_url, json).then(function (post) {
- console.log(post.status)
- })
- })
- console.log("Finish")
- })
- }
- async function main() {
- ambildata('rawdata.192.168.1.201.txt')
- await sleep(periodic)
- }
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement