-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoller.js
48 lines (42 loc) · 1.75 KB
/
Poller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var request = require("request");
var fs = require("fs");
const json2csv = require('json2csv').parser;
const fields = ['total_events', 'items', 'node', 'org', 'msg', 'utc', 'site', 'severity', 'admin', 'id']
const opts = { fields };
var elasticsearch = require('elasticsearch');
var timestamp = new Date().toString()
console.log('node.js application starting...');
fs.open("events.json", 'w', function (err, file) {
if (err) throw err;
console.log('json created ');
});
fs.open("nodes.json", 'w', function (err, file) {
if (err) throw err;
console.log('json created ');
});
var options = { method: 'GET',
url: 'https://<yourSCM>.riverbed.cc/api/scm.reporting/1.0/event_logs',
headers:
{ 'Cache-Control': 'no-cache',
Authorization: 'Basic Yourbasicauthuse postman',
'Content-Type': 'application/json;charset=UTF-8',
Accept: 'application/json' } };
request(options, function (error, response, body)
{ if (error) throw new Error(error);
var obj;
obj = JSON.parse(body);
fs.writeFile("events.json", JSON.stringify(obj.items),{flag: "r+"}, err => err ? console.error(err) : console.log("Got events and appended file Ok"));;
});
var options = { method: 'GET',
url: 'https://<yourSCM>.riverbed.cc/api/scm.reporting/1.0/nodes',
headers:
{ 'Cache-Control': 'no-cache',
Authorization: 'Basic Yourbasicauthuse postman',
'Content-Type': 'application/json;charset=UTF-8',
Accept: 'application/json' } };
request(options, function (error, response, body)
{ if (error) throw new Error(error);
var objn;
objn = JSON.parse(body);
fs.writeFile("nodes.json", JSON.stringify(objn.items),{flag: "r+"}, err => err ? console.error(err) : console.log("Got nodes and appended file Ok"));;
});