Statistics Page and API - MAC Address OUI Count by Vendor

This commit is contained in:
Akkadius 2017-09-15 05:23:02 -05:00
parent 7f0b98c597
commit 187ffb5f0e
4 changed files with 83 additions and 4 deletions

View File

@ -0,0 +1,37 @@
var express = require('express');
var router = express.Router();
var fs = require('fs');
router.get('/', function(req, res, next) {
var stat_data = {};
var count = 0;
for (var key in dhcp_lease_data) {
/* Mac OUI Lookup */
var mac_oui = dhcp_lease_data[key].mac.split(":").join("").toUpperCase().slice(0,6);
if(typeof stat_data[mac_oui] === "undefined")
stat_data[mac_oui] = {};
if(typeof stat_data[mac_oui].count === "undefined")
stat_data[mac_oui].count = 0;
stat_data[mac_oui].count++;
if(stat_data[mac_oui].mac_prefix !== "undefined") {
stat_data[mac_oui].mac_prefix = mac_oui;
}
if(stat_data[mac_oui].vendor !== "undefined"){
if(typeof oui_data[mac_oui] !== "undefined") {
stat_data[mac_oui].vendor = oui_data[mac_oui];
}
}
}
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(stat_data));
});
module.exports = router;

View File

@ -15,7 +15,7 @@ router.get('/', function(req, res, next) {
const execSync = require('child_process').execSync;
output = execSync('./bin/dhcpd-pools -c ' + glass_config.config_file + ' -l ' + glass_config.leases_file + ' -f j -A -s e');
console.log(JSON.parse(output));
// console.log(JSON.parse(output));
res.send(JSON.stringify(JSON.parse(output)));
});

1
app.js
View File

@ -49,6 +49,7 @@ app.use('/glass_settings_save', require('./routes/glass_settings_save'));
app.use('/api/get_active_leases/', require('./api/get_active_leases'));
app.use('/api/get_subnet_details/', require('./api/get_subnet_details'));
app.use('/api/get_vendor_count/', require('./api/get_vendor_count'));
app.use('/api/get_mac_oui_count_by_vendor/', require('./api/get_mac_oui_count_by_vendor'));
app.set('view engine', 'html');

View File

@ -34,6 +34,24 @@
</div>
</div>
</div>
<div class="card">
<div class="header">
<h2>MAC Address OUI Count by Vendor</h2>
</div>
<div class="body">
<table id="device_list_mac" class="table table-bordered table-striped table-hover js-basic-example dataTable dashboard-task-infos">
<thead>
<tr>
<th>MAC Address OUI</th>
<th>Vendor</th>
<th>Count</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<!-- #END# Donut Chart -->
</div>
@ -41,7 +59,6 @@
<script type="text/javascript">
var chart_data = [];
$.getJSON( "/api/get_vendor_count", function( data ) {
$.each(data, function(k, v) {
if(v >= 3)
chart_data.push({"label": k, "value": v});
@ -59,12 +76,36 @@
});
device_list = $('#device_list_table').DataTable({
dom: 'tip',
dom: 'rftip',
responsive: true,
"pageLength": 20,
"aaSorting": [],
"order": [[ 1, "desc" ]]
"order": [[ 1, "desc" ]],
"searching": true
});
});
$.getJSON( "/api/get_mac_oui_count_by_vendor", function( data ) {
$.each(data, function(k, v) {
// console.log(k);
$('#device_list_mac > tbody:last-child').append('<tr>' +
'<td>' + data[k].mac_prefix + '</td>' +
'<td>' + data[k].vendor + '</td>' +
'<td>' + data[k].count.toLocaleString('en') + '</td>' +
'</tr>'
);
});
device_list = $('#device_list_mac').DataTable({
dom: 'rftip',
responsive: true,
"pageLength": 20,
"aaSorting": [],
"order": [[ 2, "desc" ]]
});
});
</script>