2017-08-09 22:18:28 +02:00
var express = require ( 'express' ) ;
var path = require ( 'path' ) ;
var favicon = require ( 'serve-favicon' ) ;
var logger = require ( 'morgan' ) ;
var cookieParser = require ( 'cookie-parser' ) ;
var bodyParser = require ( 'body-parser' ) ;
2017-09-06 08:05:34 +02:00
const execSync = require ( 'child_process' ) . execSync ;
2017-08-09 22:18:28 +02:00
var app = express ( ) ;
2017-09-02 08:04:47 +02:00
/* Read Config */
var json _file = require ( 'jsonfile' ) ;
2017-09-02 11:44:39 +02:00
var glass _config = json _file . readFileSync ( 'config/glass_config.json' ) ;
2017-09-02 08:04:47 +02:00
2017-08-09 22:18:28 +02:00
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app . use ( logger ( 'dev' ) ) ;
app . use ( bodyParser . json ( ) ) ;
app . use ( bodyParser . urlencoded ( { extended : false } ) ) ;
app . use ( cookieParser ( ) ) ;
app . use ( express . static ( path . join ( _ _dirname , 'public' ) ) ) ;
2017-09-06 11:42:05 +02:00
if ( glass _config . ip _ranges _to _allow != "" ) {
2017-09-06 11:07:50 +02:00
var ip _filter = require ( 'express-ipfilter' ) . IpFilter ;
var ips = glass _config . ip _ranges _to _allow ;
app . use ( ip _filter ( ips , { mode : 'allow' } ) ) ;
}
2017-08-09 22:18:28 +02:00
/* Normal Web Routes */
app . use ( '/' , require ( './routes/index' ) ) ;
app . use ( '/users' , require ( './routes/users' ) ) ;
app . use ( '/get_stats' , require ( './routes/get_stats' ) ) ;
2017-09-15 11:40:28 +02:00
app . use ( '/dhcp_statistics' , require ( './routes/dhcp_statistics_page' ) ) ;
2017-08-09 22:18:28 +02:00
app . use ( '/dhcp_leases' , require ( './routes/dhcp_leases' ) ) ;
2017-09-15 13:28:23 +02:00
app . use ( '/dhcp_lease_search' , require ( './routes/dhcp_lease_search' ) ) ;
2017-09-02 11:44:39 +02:00
app . use ( '/dhcp_log' , require ( './routes/dhcp_log' ) ) ;
2017-09-02 12:58:59 +02:00
app . use ( '/dhcp_config' , require ( './routes/dhcp_config' ) ) ;
2017-09-02 14:07:30 +02:00
app . use ( '/dhcp_config_snapshots' , require ( './routes/dhcp_config_snapshots' ) ) ;
app . use ( '/dhcp_config_snapshot_view' , require ( './routes/dhcp_config_snapshot_view' ) ) ;
2017-09-02 12:58:59 +02:00
app . use ( '/dhcp_config_save' , require ( './routes/dhcp_config_save' ) ) ;
2017-09-02 15:45:55 +02:00
app . use ( '/dhcp_start_stop_restart' , require ( './routes/dhcp_start_stop_restart' ) ) ;
2017-08-09 22:18:28 +02:00
app . use ( '/api_examples' , require ( './routes/api_examples' ) ) ;
2017-09-02 08:04:47 +02:00
app . use ( '/glass_settings' , require ( './routes/glass_settings' ) ) ;
2017-09-02 16:59:36 +02:00
app . use ( '/glass_alerts' , require ( './routes/glass_alerts' ) ) ;
app . use ( '/glass_alert_settings_save' , require ( './routes/glass_alert_settings_save' ) ) ;
2017-09-02 08:04:47 +02:00
app . use ( '/glass_settings_save' , require ( './routes/glass_settings_save' ) ) ;
2017-08-09 22:18:28 +02:00
/* API Routes */
app . use ( '/api/get_active_leases/' , require ( './api/get_active_leases' ) ) ;
2017-09-02 08:04:47 +02:00
app . use ( '/api/get_subnet_details/' , require ( './api/get_subnet_details' ) ) ;
2017-09-15 11:40:28 +02:00
app . use ( '/api/get_vendor_count/' , require ( './api/get_vendor_count' ) ) ;
2017-09-15 12:23:02 +02:00
app . use ( '/api/get_mac_oui_count_by_vendor/' , require ( './api/get_mac_oui_count_by_vendor' ) ) ;
2017-09-15 14:19:28 +02:00
app . use ( '/api/get_dhcp_requests/' , require ( './api/get_dhcp_requests' ) ) ;
2017-08-09 22:18:28 +02:00
app . set ( 'view engine' , 'html' ) ;
// catch 404 and forward to error handler
app . use ( function ( req , res , next ) {
2017-09-02 11:44:39 +02:00
var err = new Error ( 'Not Found' ) ;
err . status = 404 ;
next ( err ) ;
2017-08-09 22:18:28 +02:00
} ) ;
// error handler
app . use ( function ( err , req , res , next ) {
2017-09-02 11:44:39 +02:00
// set locals, only providing error in development
res . locals . message = err . message ;
res . locals . error = req . app . get ( 'env' ) === 'development' ? err : { } ;
2017-08-09 22:18:28 +02:00
2017-09-02 11:44:39 +02:00
// render the error page
res . status ( err . status || 500 ) ;
res . send ( err . message ) ;
2017-08-09 22:18:28 +02:00
} ) ;
module . exports = app ;
2017-09-02 11:44:39 +02:00
/ * *
* Global Variables
* /
2017-09-06 08:05:34 +02:00
leases _per _minute = 0 ;
2017-09-02 11:44:39 +02:00
cpu _utilization = 0 ;
total _leases = 0 ;
2017-08-09 22:18:28 +02:00
current _time = 0 ;
leases _per _second = 0 ;
current _leases _per _second = 0 ;
leases _last _update _time = 0 ;
2017-09-02 11:44:39 +02:00
listening _to _log _file = 0 ;
2017-08-09 22:18:28 +02:00
options = { } ;
options . interval = 1000 ;
2017-09-15 10:08:29 +02:00
debug _watch _lease _parse _stream = 0 ;
2017-09-06 09:36:58 +02:00
host _name = execSync ( "cat /etc/hostname" ) . toString ( ) ;
2017-09-15 10:08:29 +02:00
/ * *
* Ingest OUI Database
* /
fs = require ( 'fs' ) ;
var oui _database _file = "bin/oui_table.txt" ;
/* Global oui_data bucket */
oui _data = { } ;
if ( fs . existsSync ( oui _database _file ) ) {
fs . readFile ( oui _database _file , 'utf8' , function ( err , data ) {
if ( err ) {
return console . log ( err ) ;
}
else {
/* Iterate through file */
lines = data . split ( "\n" ) ;
for ( l = 0 ; l < lines . length ; l ++ ) {
/* Trim whitespaces at each ends of the line */
lines [ l ] = lines [ l ] . trim ( ) ;
var oui _line _data = lines [ l ] . split ( ":::" ) ;
if ( typeof oui _line _data [ 1 ] !== "undefined" )
oui _data [ oui _line _data [ 0 ] . trim ( ) ] = oui _line _data [ 1 ] . trim ( ) ;
}
console . log ( "[Glass Server] OUI Database Loaded" ) ;
}
} ) ;
}
2017-09-02 11:44:39 +02:00
/ * *
* Ingest Current Lease File
* /
2017-08-09 22:18:28 +02:00
var lease _parser = require ( './lib/lease_parser.js' ) ;
dhcp _lease _data = { } ;
lease _read _buffer = "" ;
fs = require ( 'fs' ) ;
2017-09-02 08:04:47 +02:00
fs . readFile ( glass _config . leases _file , 'utf8' , function ( err , data ) {
2017-08-09 22:18:28 +02:00
if ( err ) {
return console . log ( err ) ;
}
2017-09-02 11:44:39 +02:00
else {
lease _parser . parse ( data ) ;
2017-09-15 09:20:29 +02:00
console . log ( "[Glass Server] Leases file loaded" ) ;
2017-09-02 11:44:39 +02:00
}
2017-08-09 22:18:28 +02:00
} ) ;
2017-09-02 11:44:39 +02:00
/ * *
* Leases File Listener
* /
2017-09-14 12:06:47 +02:00
var tail _module = require ( 'always-tail2' ) ;
2017-08-09 22:18:28 +02:00
tail = new tail _module (
2017-09-02 08:04:47 +02:00
glass _config . leases _file ,
2017-08-09 22:18:28 +02:00
"\n" ,
options
) ;
tail . on ( "line" , function ( data ) {
unix _time = Math . floor ( new Date ( ) / 1000 ) ;
/* Buffering lines until we get full lease data */
lease _read _buffer = lease _read _buffer + data + "\n" ;
/* End of lease - cut off and parse the buffer */
if ( /}/i . test ( data ) ) {
lease _parser . parse ( lease _read _buffer ) ;
lease _read _buffer = "" ;
}
/* Count leases per second */
if ( /lease/ . test ( data ) ) {
leases _per _second ++ ;
}
if ( current _time != unix _time ) {
current _time = unix _time ;
current _leases _per _second = leases _per _second ;
leases _last _update _time = unix _time ;
leases _per _second = 0 ;
}
} ) ;
2017-09-02 11:44:39 +02:00
/ * *
* Watch DHCP Log File
* /
var json _file = require ( 'jsonfile' ) ;
var glass _config = json _file . readFileSync ( 'config/glass_config.json' ) ;
var options = { } ;
options . interval = 1000 ;
2017-08-09 22:18:28 +02:00
2017-09-06 08:05:34 +02:00
var dashboard _timer = setInterval ( function ( ) {
2017-08-09 22:18:28 +02:00
// console.log("Checking timers...");
unix _time = Math . floor ( new Date ( ) / 1000 ) ;
if ( ( unix _time - 5 ) > leases _last _update _time ) {
current _leases _per _second = 0 ;
}
// console.log(JSON.stringify(dhcp_lease_data, null, 2));
} , 5000 ) ;
2017-09-06 08:05:34 +02:00
/ * *
* Calculate leases per minute
* /
var leases _per _minute _data = [ ] ;
var leases _per _minute _counter = 0 ;
leases _per _minute _counter _timer = setInterval ( function ( ) {
// console.log("leases per minute counter %i", leases_per_minute_counter);
leases _per _minute _data [ leases _per _minute _counter ] = current _leases _per _second ;
leases _per _minute _counter ++ ;
/* Count how many actual data sets we walked that have values */
leases _per _minute = 0 ;
for ( i = 0 ; i < 59 ; i ++ ) {
if ( leases _per _minute _data [ i ] > 0 ) {
leases _per _minute += leases _per _minute _data [ i ] ;
// console.log("iteration " + i + " val: " + leases_per_minute_data[i] + " lpm: " + leases_per_minute);
}
else {
// console.log("no data " + i);
}
}
if ( leases _per _minute _counter == 60 )
leases _per _minute _counter = 0 ;
} , 1000 ) ;
/ * *
* Poll : CPU Utilization
* /
cpu _utilization _poll = setInterval ( function ( ) {
2017-09-06 09:36:58 +02:00
cpu _utilization = parseFloat ( execSync ( "top -bn 1 | awk 'NR>7{s+=$9} END {print s/4}'" ) . toString ( ) )
2017-09-06 08:05:34 +02:00
} , ( 15 * 1000 ) ) ;
/ * *
* Clean Expired Leases
* /
2017-08-09 22:18:28 +02:00
lease _clean _timer = setInterval ( function ( ) {
lease _parser . clean ( ) ;
2017-09-02 11:44:39 +02:00
} , ( 60 * 1000 ) ) ;
function get _socket _clients _connected _count ( ) {
wss . clients . forEach ( function each ( client ) {
if ( client . readyState === WebSocket . OPEN ) {
socket _clients ++ ;
}
} ) ;
return socket _clients ;
}
2017-09-06 10:14:39 +02:00
/ * *
* Watch config changes so we reload it for core functions ...
* /
fs . watch ( 'config/glass_config.json' , function ( event , filename ) {
if ( filename ) {
setTimeout ( function ( ) {
glass _config = json _file . readFileSync ( 'config/glass_config.json' ) ;
2017-09-15 09:20:29 +02:00
console . log ( "[Glass Server] Config Loaded" ) ;
2017-09-06 10:14:39 +02:00
} , 1000 ) ;
} else {
console . log ( 'filename not provided' ) ;
}
} ) ;
2017-09-02 11:44:39 +02:00
/ * *
2017-09-06 09:36:58 +02:00
* Websocket Server
2017-09-02 11:44:39 +02:00
* /
const WebSocket = require ( 'ws' ) ;
const wss = new WebSocket . Server ( { port : 8080 } ) ;
2017-09-06 09:36:58 +02:00
options . interval = 300 ;
2017-09-02 11:44:39 +02:00
var tail _dhcp _log = new tail _module (
glass _config . log _file ,
"\n" ,
options
) ;
2017-09-15 14:19:28 +02:00
dhcp _requests = { } ;
2017-09-02 11:44:39 +02:00
tail _dhcp _log . on ( "line" , function ( data ) {
if ( listening _to _log _file ) {
wss . broadcast _event ( data , 'dhcp_log_subscription' ) ;
}
2017-09-15 14:19:28 +02:00
/* Collect Excessive DHCP Request Data */
if ( /DHCPREQUEST/i . test ( data ) ) {
var request _from = "" ;
var request _for = "" ;
var request _via = "" ;
var request _data = data . split ( " " ) ;
var length = request _data . length ;
for ( var i = 0 ; i < length ; i ++ ) {
if ( request _data [ i ] == "from" ) {
request _from = request _data [ i + 1 ] ;
}
if ( request _data [ i ] == "for" ) {
request _for = request _data [ i + 1 ] ;
}
if ( request _data [ i ] == "via" ) {
request _via = request _data [ i + 1 ] ;
}
}
if ( typeof dhcp _requests [ request _from ] === "undefined" )
dhcp _requests [ request _from ] = { } ;
if ( typeof dhcp _requests [ request _from ] . request _for === "undefined" )
dhcp _requests [ request _from ] . request _for = request _for ;
if ( typeof dhcp _requests [ request _from ] . request _via === "undefined" )
dhcp _requests [ request _from ] . request _via = request _via ;
if ( typeof dhcp _requests [ request _from ] . request _count === "undefined" )
dhcp _requests [ request _from ] . request _count = 0 ;
dhcp _requests [ request _from ] . request _count ++ ;
}
2017-09-02 11:44:39 +02:00
} ) ;
2017-09-15 14:19:28 +02:00
const purge _request _data = setInterval ( function ( ) {
for ( var key in dhcp _requests ) {
if ( dhcp _requests [ key ] . request _count <= 10 )
delete dhcp _requests [ key ] ;
}
} , 600 * 1000 ) ; /* 10 Minutes */
const purge _request _data _hour = setInterval ( function ( ) {
dhcp _requests = { } ;
} , 3600 * 1000 ) ; /* 60 Minutes */
2017-09-02 11:44:39 +02:00
wss . on ( 'connection' , function connection ( ws ) {
socket _clients ++ ;
console . log ( "[WS] CLIENT_CONNECT: Socket clients (" + socket _clients + ")" ) ;
if ( ! listening _to _log _file ) {
/* Watch log file for new information */
2017-09-14 12:06:47 +02:00
var tail _module = require ( 'always-tail2' ) ;
2017-09-02 11:44:39 +02:00
listening _to _log _file = 1 ;
}
} ) ;
wss . on ( 'close' , function close ( ) {
socket _clients -- ;
console . log ( "[WS] CLIENT_DISCONNECT: Socket clients (" + socket _clients + ")" ) ;
} ) ;
function heartbeat ( ) {
this . isAlive = true ;
}
function isJson ( str ) {
try {
JSON . parse ( str ) ;
} catch ( e ) {
return false ;
}
return true ;
}
wss . on ( 'connection' , function connection ( ws ) {
ws . isAlive = true ;
ws . on ( 'pong' , heartbeat ) ;
ws . event _subscription = [ ] ;
ws . on ( 'message' , function incoming ( data ) {
if ( data != "" && isJson ( data ) ) {
var json = JSON . parse ( data ) ;
if ( typeof json [ "event_subscription" ] !== "undefined" ) {
console . log ( "[WS] Incoming Subscription '%s'" , json [ 'event_subscription' ] ) ;
ws . event _subscription [ json [ "event_subscription" ] ] = 1 ;
}
if ( typeof json [ "event_unsubscribe" ] !== "undefined" ) {
console . log ( "[WS] event_unsubscribe '%s'" , json [ 'event_unsubscribe' ] ) ;
delete ws . event _subscription [ json [ "event_unsubscribe" ] ] ;
}
}
} ) ;
stale _connections _audit ( ) ;
} ) ;
wss . broadcast = function broadcast ( data ) {
wss . clients . forEach ( function each ( client ) {
if ( client . readyState === WebSocket . OPEN ) {
client . send ( data ) ;
}
} ) ;
} ;
wss . broadcast _event = function broadcast ( data , event ) {
wss . clients . forEach ( function each ( client ) {
if ( client . readyState === WebSocket . OPEN ) {
if ( client . event _subscription [ event ] )
client . send ( data ) ;
}
} ) ;
} ;
function stale _connections _audit ( ) {
socket _clients = 0 ;
wss . clients . forEach ( function each ( ws ) {
if ( ws . isAlive === false ) return ws . terminate ( ) ;
ws . isAlive = false ;
ws . ping ( '' , false , true ) ;
socket _clients ++ ;
} ) ;
console . log ( "[WS] STATUS: Socket clients (" + socket _clients + ")" ) ;
}
/* Keepalive - kill stale connections (30s poll) */
const interval = setInterval ( function ping ( ) {
stale _connections _audit ( ) ;
} , 30000 ) ;
2017-09-06 08:05:34 +02:00
var socket _clients = 0 ;
/ * *
* Slack Hooks
* /
var Slack = require ( 'slack-node' ) ;
webhookUri = glass _config . slack _webhook _url ;
slack = new Slack ( ) ;
slack . setWebhook ( webhookUri ) ;
function slack _message ( message ) {
2017-09-06 10:14:39 +02:00
console . log ( "[Slack] %s" , message ) ;
2017-09-06 08:05:34 +02:00
slack . webhook ( {
channel : glass _config . slack _alert _channel ,
username : "Glass" ,
2017-09-06 10:14:39 +02:00
icon _emoji : "https://imgur.com/wD3CcBi" ,
2017-09-06 08:05:34 +02:00
text : message
} , function ( err , response ) {
console . log ( response ) ;
} ) ;
}
/ * *
* Alert Checks
* /
alert _status = [ ] ;
2017-09-06 10:14:39 +02:00
alert _status [ 'leases_per_minute' ] = 0 ;
2017-09-14 11:33:36 +02:00
setTimeout ( function ( ) {
2017-09-15 09:20:29 +02:00
console . log ( "[Glass Server] Alert loop started" ) ;
alert _check _timer = setInterval ( function ( ) {
2017-09-14 11:33:36 +02:00
console . log ( "[Timer] Alert Timer check" ) ;
if ( glass _config . leases _per _minute _threshold > 0 ) {
console . log ( "[Timer] lpm: %s lpm_th: %s" , leases _per _minute , glass _config . leases _per _minute _threshold ) ;
if ( leases _per _minute <= glass _config . leases _per _minute _threshold && alert _status [ 'leases_per_minute' ] == 0 ) {
alert _status [ 'leases_per_minute' ] = 1 ;
slack _message ( ":warning: WARNING: DHCP leases per minute have dropped below threshold (" + parseInt ( glass _config . leases _per _minute _threshold ) . toLocaleString ( 'en' ) + ") Current (" + parseInt ( leases _per _minute ) . toLocaleString ( 'en' ) + ")" ) ;
}
else if ( leases _per _minute >= glass _config . leases _per _minute _threshold && alert _status [ 'leases_per_minute' ] == 1 ) {
alert _status [ 'leases_per_minute' ] = 0 ;
slack _message ( ":white_check_mark: CLEAR: DHCP leases per minute have returned to above threshold (" + parseInt ( glass _config . leases _per _minute _threshold ) . toLocaleString ( 'en' ) + ") Current (" + parseInt ( leases _per _minute ) . toLocaleString ( 'en' ) + ")" ) ;
}
2017-09-06 08:05:34 +02:00
}
2017-09-14 11:33:36 +02:00
} , ( 60 * 1000 ) ) ;
2017-09-06 10:50:11 +02:00
2017-09-14 11:33:36 +02:00
alert _status _networks _warning = [ ] ;
alert _status _networks _critical = [ ] ;
2017-09-06 10:50:11 +02:00
2017-09-14 11:33:36 +02:00
alert _subnet _check _timer = setInterval ( function ( ) {
console . log ( "[Timer] Alert Timer check - subnets" ) ;
2017-09-06 10:50:11 +02:00
2017-09-14 11:33:36 +02:00
if ( glass _config . shared _network _warning _threshold > 0 || glass _config . shared _network _critical _threshold > 0 ) {
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' ) ;
var dhcp _data = JSON . parse ( output ) ;
2017-09-06 10:50:11 +02:00
2017-09-14 11:33:36 +02:00
/ *
* Iterate through Shared Networks
* /
for ( var i = 0 ; i < dhcp _data [ 'shared-networks' ] . length ; i ++ ) {
utilization = round ( parseFloat ( dhcp _data [ 'shared-networks' ] [ i ] . used / dhcp _data [ 'shared-networks' ] [ i ] . defined ) * 100 , 2 ) ;
2017-09-06 10:50:11 +02:00
2017-09-14 11:33:36 +02:00
if ( isNaN ( utilization ) )
utilization = 0 ;
2017-09-06 10:50:11 +02:00
2017-09-14 11:33:36 +02:00
/* Initialize these array buckets */
if ( typeof alert _status _networks _warning [ dhcp _data [ 'shared-networks' ] [ i ] . location ] === "undefined" )
alert _status _networks _warning [ dhcp _data [ 'shared-networks' ] [ i ] . location ] = 0 ;
2017-09-06 10:50:11 +02:00
2017-09-14 11:33:36 +02:00
if ( typeof alert _status _networks _critical [ dhcp _data [ 'shared-networks' ] [ i ] . location ] === "undefined" )
alert _status _networks _critical [ dhcp _data [ 'shared-networks' ] [ i ] . location ] = 0 ;
2017-09-06 10:50:11 +02:00
2017-09-14 11:33:36 +02:00
/ *
console . log ( "Location: %s" , dhcp _data [ 'shared-networks' ] [ i ] . location ) ;
console . log ( "Used: %s" , dhcp _data [ 'shared-networks' ] [ i ] . used . toLocaleString ( 'en' ) ) ;
console . log ( "Defined: %s" , dhcp _data [ 'shared-networks' ] [ i ] . defined . toLocaleString ( 'en' ) ) ;
console . log ( "Free: %s" , dhcp _data [ 'shared-networks' ] [ i ] . free . toLocaleString ( 'en' ) ) ;
console . log ( "Utilization: %s" , utilization ) ;
console . log ( " \n" ) ;
* /
/* Check Warnings */
if ( glass _config . shared _network _warning _threshold > 0 ) {
if (
utilization >= glass _config . shared _network _warning _threshold &&
utilization <= glass _config . shared _network _critical _threshold &&
alert _status _networks _warning [ dhcp _data [ 'shared-networks' ] [ i ] . location ] == 0
)
{
alert _status _networks _warning [ dhcp _data [ 'shared-networks' ] [ i ] . location ] = 1 ;
slack _message ( ":warning: WARNING: DHCP shared network utilization (" + dhcp _data [ 'shared-networks' ] [ i ] . location + ") Current: (" + utilization + "%) Threshold: (" + glass _config . shared _network _warning _threshold + "%)" ) ;
}
else if (
utilization <= glass _config . shared _network _warning _threshold &&
alert _status _networks _warning [ dhcp _data [ 'shared-networks' ] [ i ] . location ] == 1
)
{
alert _status _networks _warning [ dhcp _data [ 'shared-networks' ] [ i ] . location ] = 0 ;
slack _message ( ":white_check_mark: CLEAR: Warning DHCP shared network utilization (" + dhcp _data [ 'shared-networks' ] [ i ] . location + ") Current: (" + utilization + "%) Threshold: (" + glass _config . shared _network _warning _threshold + "%)" ) ;
}
2017-09-06 10:50:11 +02:00
}
2017-09-14 11:33:36 +02:00
/* Check Critical */
if ( glass _config . shared _network _critical _threshold > 0 ) {
if (
utilization >= glass _config . shared _network _critical _threshold &&
alert _status _networks _critical [ dhcp _data [ 'shared-networks' ] [ i ] . location ] == 0
)
{
alert _status _networks _critical [ dhcp _data [ 'shared-networks' ] [ i ] . location ] = 1 ;
slack _message ( ":fire: CRITICAL: DHCP shared network utilization (" + dhcp _data [ 'shared-networks' ] [ i ] . location + ") Current: (" + utilization + "%) Threshold: (" + glass _config . shared _network _critical _threshold + "%)" ) ;
}
else if (
utilization <= glass _config . shared _network _critical _threshold &&
alert _status _networks _critical [ dhcp _data [ 'shared-networks' ] [ i ] . location ] == 1
)
{
alert _status _networks _critical [ dhcp _data [ 'shared-networks' ] [ i ] . location ] = 0 ;
slack _message ( ":white_check_mark: CLEAR: Critical DHCP shared network utilization (" + dhcp _data [ 'shared-networks' ] [ i ] . location + ") Current: (" + utilization + "%) Threshold: (" + glass _config . shared _network _critical _threshold + "%)" ) ;
}
2017-09-06 10:50:11 +02:00
}
}
}
2017-09-14 11:33:36 +02:00
} , ( 5 * 1000 ) ) ;
} , 60 * 1000 ) ;
2017-09-06 10:50:11 +02:00
function round ( num , places ) {
var multiplier = Math . pow ( 10 , places ) ;
return Math . round ( num * multiplier ) / multiplier ;
2017-09-15 09:20:29 +02:00
}
console . log ( "[Glass Server] Bootup complete" ) ;