Forensic Data Using the API With Node
const request = require('request'); const cookie = require('cookie'); const baseurl = 'http://viavi.anuview.net/'; const options = { url: baseurl, }; function getData(cookiename, cookievalue) { request({ url: options.url + "rest/api/", method: "POST", json: { "summaryLinkTitle": "Goto Summary Page", "recentTable": "summaryinterfaces", "pastTable": "summaryinterfaces", "keyField": "key", "summaryLink": "/overview/interfaces/", "recentColumn": "recent_sum_bits", "pastColumn": "recent_sum_bits", "keyFieldType": "'dif_device'", "divid": "graph_2", "title": "Top Interfaces (v Previous Week)", "containerClass": "chartDiv", "limit": 10, "type": "chartmovers", "aggregator": "sum", "recentStart": "1682400462089", "recentEnd": "1682411262089", "pastStart": "1681795662089", "pastEnd": "1681806462888", "parentPage": "Enterprise Dashboard" }, headers: { 'Cookie': cookiename + '=' + cookievalue } }, (error, response, body) => { if (error) { console.error(error); } else { console.log(JSON.stringify(body)); // console.log(response); } }); } function loginAndGetData() { request({ url: options.url + '?userName=admin&userPass=CHANGEME' }, (error, response, body) => { if (error) { console.error(error); } else { const setCookieHeader = response.headers['set-cookie']; // console.log(body); if (setCookieHeader) { const cookies = setCookieHeader.map(cookie.parse); // console.log(cookies); if (cookies.length > 0) { for (var c = 0; c < cookies.length; c++) { for (var l in cookies[c]) { if (l.indexOf("JSESSIONIDAnuviewflow") == 0) { console.log(l + " " + cookies[c][l]); getData(l, cookies[c][l]); } } } } } } }); } loginAndGetData();
Output:
JSESSIONIDAnuviewflow79021681397055739 node0nzqazk51i03z1d5k80v8nvqh244271.node0
{"aggregator":"sum","limit":10,"limitpast":40,"results":[{"display":{"display":"NAT Device 1 (169.254.1.16)/0","fieldtype":"dif_device","raw":"169.254.1.16_0"},"key":"-1442971376_0","keytype":"dif_device","pastrank": 2,"pastval":253438848000,"recentrank":1,"recentval":253438848000},{"display":{"display":"NAT Device 4 (169.254.1.19)/0","fieldtype":"dif_device","raw":"169.254.1.19_0"},"key":"-1442971373_0","keytype":"dif_device","p astrank":1,"pastval":253438848000,"recentrank":2,"recentval":253438848000},{"display":{"display":"NAT Device 3 (169.254.1.18)/0","fieldtype":"dif_device","raw":"169.254.1.18_0"},"key":"-1442971374_0","keytype":"dif_d evice","pastrank":4,"pastval":253438848000,"recentrank":3,"recentval":253438848000},{"display":{"display":"NAT Device 2 (169.254.1.17)/0","fieldtype":"dif_device","raw":"169.254.1.17_0"},"key":"-1442971375_0","keytyp e":"dif_device","pastrank":3,"pastval":253438848000,"recentrank":4,"recentval":253438848000},{"display":{"display":"rtr1.wilkieks.com (83.70.199.180)/Dialer1","fieldtype":"dif_device","raw":"83.70.199.180_20"},"key": "1397147572_20","keytype":"dif_device","pastrank":9,"pastval":2958945777,"recentrank":5,"recentval":6217977448},{"display":{"display":"rtr1.wilkieks.com (83.70.199.180)/Vlan1","fieldtype":"dif_device","raw":"83.70.19 9.180_17"},"key":"1397147572_17","keytype":"dif_device","pastrank":10,"pastval":2943232577,"recentrank":6,"recentval":6169683450},{"display":{"display":"10.254.12.30 (10.254.12.30)/4","fieldtype":"dif_device","raw":" 10.254.12.30_4"},"key":"184421406_4","keytype":"dif_device","pastrank":5,"pastval":4719500945,"recentrank":7,"recentval":4726569285},{"display":{"display":"Head Office Primary (172.21.40.250)/WAN Link","fieldtype":"d if_device","raw":"172.21.40.250_30"},"key":"-1407899398_30","keytype":"dif_device","pastrank":6,"pastval":4508339604,"recentrank":8,"recentval":4416171788},{"display":{"display":"Head Office Primary (172.21.40.250)/B ackup Link","fieldtype":"dif_device","raw":"172.21.40.250_13"},"key":"-1407899398_13","keytype":"dif_device","pastrank":7,"pastval":3907989995,"recentrank":9,"recentval":3860144532},{"display":{"display":"Gigamon Ext ended Fields (10.2.0.40)/0","fieldtype":"dif_device","raw":"10.2.0.40_0"},"key":"167903272_0","keytype":"dif_device","pastrank":8,"pastval":3763385096,"recentrank":10,"recentval":3728094416}]}