Add debugging output to server bootup - Fix DHCP Lease option array logic

This commit is contained in:
Akkadius 2017-09-15 02:20:29 -05:00
parent 4de691f66a
commit 82c39d3d72
3 changed files with 14 additions and 8 deletions

7
app.js
View File

@ -103,6 +103,7 @@ fs.readFile(glass_config.leases_file, 'utf8', function (err,data) {
}
else {
lease_parser.parse(data);
console.log("[Glass Server] Leases file loaded");
}
});
@ -193,7 +194,6 @@ leases_per_minute_counter_timer = setInterval(function(){
/**
* Poll: CPU Utilization
*/
cpu_utilization_poll = setInterval(function(){
cpu_utilization = parseFloat(execSync("top -bn 1 | awk 'NR>7{s+=$9} END {print s/4}'").toString())
}, (15 * 1000));
@ -221,6 +221,7 @@ fs.watch('config/glass_config.json', function (event, filename) {
if (filename) {
setTimeout(function(){
glass_config = json_file.readFileSync('config/glass_config.json');
console.log("[Glass Server] Config Loaded");
}, 1000);
} else {
console.log('filename not provided');
@ -371,6 +372,8 @@ function slack_message(message) {
alert_status = [];
alert_status['leases_per_minute'] = 0;
setTimeout(function(){
console.log("[Glass Server] Alert loop started");
alert_check_timer = setInterval(function(){
console.log("[Timer] Alert Timer check");
if(glass_config.leases_per_minute_threshold > 0) {
@ -472,3 +475,5 @@ function round(num, places) {
var multiplier = Math.pow(10, places);
return Math.round(num * multiplier) / multiplier;
}
console.log("[Glass Server] Bootup complete");

View File

@ -92,11 +92,12 @@ module.exports = {
if (typeof dhcp_lease_data[ip_address]['options'] === "undefined")
dhcp_lease_data[ip_address]['options'] = [];
}
if (/}/i.test(lines[l]) && typeof dhcp_lease_data[ip_address]['options'] !== "undefined"){
if (option_data.length > 0)
dhcp_lease_data[ip_address]['options'].push(option_data);
if (lines[l].charAt(0) == "}" && typeof dhcp_lease_data[ip_address]['options'] !== "undefined"){
if (typeof option_data !== 'undefined') {
dhcp_lease_data[ip_address]['options'] = option_data;
}
option_data = {};
option_data = [];
}
}
}

View File

@ -28,7 +28,7 @@ router.get('/', function(req, res, next) {
table_row = table_row + '<td>' + (dhcp_lease_data[key].host ? dhcp_lease_data[key].host : '') + '</td>';
table_row = table_row + '<td>' + human_time(dhcp_lease_data[key].start * 1000) + '</td>';
table_row = table_row + '<td>' + human_time(dhcp_lease_data[key].end * 1000) + '</td>';
table_row = table_row + '<td></td>';
table_row = table_row + '<td>' + </td>';
table_data = table_data + '<tr>' + table_row + '</tr>';
}