Forensic Data Using the API With Node
From Observer GigaFlow Support | VIAVI Solutions Inc.
Revision as of 08:38, 25 April 2023 by Kevin Wilkie (Talk | contribs)
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=viavi254' }, (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();