Skip to content

Commit

Permalink
Update Device MAC Statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthrino committed Aug 8, 2018
1 parent 8b09755 commit 4bac035
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
5 changes: 2 additions & 3 deletions public/templates/dhcp_device_statistics_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h2>MAC Address OUI Count by Vendor</h2>
</div>

<script type="text/javascript">
'use strict';

$('.hide_me').hide();

var chart_data = [];
Expand All @@ -98,7 +98,7 @@ <h2>MAC Address OUI Count by Vendor</h2>
Morris.Donut({
element: "device_chart",
data: chart_data,
colors: ['rgb(233, 30, 99)', 'rgb(0, 188, 212)', 'rgb(255, 152, 0)', 'rgb(0, 150, 136)'],
colors: ['rgb(153, 0, 0)', 'rgb(253, 128, 0)', 'rgb(0, 51, 25)', 'rgb(0, 0, 51)'],
formatter: function (y) {
return y.toLocaleString('en')
}
Expand Down Expand Up @@ -139,7 +139,6 @@ <h2>MAC Address OUI Count by Vendor</h2>
$('.hide_me').show();
});


$.getJSON("/api/get_dhcp_requests", function (data) {
$.each(data, function (k, v) {
$('#excessive_requests > tbody:last-child').append('<tr>' +
Expand Down
18 changes: 18 additions & 0 deletions routes/get_dhcp_requests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var express = require('express');
var router = express.Router();
var fs = require('fs');

router.get('/', function(req, res, next) {

var stat_data = global.dhcp_requests;

for (var key in stat_data) {
if(stat_data[key].request_count <= 10)
delete stat_data[key];
}

res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(stat_data));
});

module.exports = router;
9 changes: 6 additions & 3 deletions routes/get_mac_device_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ router.get('/', function (req, res, next) {

/* Fetch lease data for network*/
var response_data = api_agent.fire_kea_api(lease_get_req_data, global.anterius_config.server_addr, global.anterius_config.server_port).then(function (api_data) {
// console.log(api_data);
console.log(api_data);
return api_data;
});

Expand All @@ -25,22 +25,24 @@ router.get('/', function (req, res, next) {
}
else {
leases_data = data.arguments.leases;
// console.log(leases_data);
console.log(leases_data);
var vendor_stats = {}, device_stats = {};
var count = 0;
// console.log(global.oui_data);

/* Leases Data parser - retrieve mac oui data */
for (var i = 0; i < leases_data.length; i++) {

/* Mac OUI Lookup */
var mac_oui = leases_data[i]['hw-address'].split(":").join("").toUpperCase().slice(0, 6);

// console.log(mac_oui, global.oui_data[mac_oui]);

/* Vendor List and Device Count block*/
leases_data[i].mac_oui_vendor = '';
if (typeof global.oui_data[mac_oui] !== "undefined") {
leases_data[i].mac_oui_vendor = global.oui_data[mac_oui];
}

if ((typeof leases_data[i].mac_oui_vendor !== "undefined" ? leases_data[i].mac_oui_vendor : 'Misc') == "")
continue;

Expand Down Expand Up @@ -73,6 +75,7 @@ router.get('/', function (req, res, next) {
}
}

// console.log(vendor_stats, device_stats);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ 'vendor_stats': vendor_stats, 'device_stats': device_stats }));
}
Expand Down

0 comments on commit 4bac035

Please sign in to comment.