mirror of
https://github.com/Akkadius/glass-isc-dhcp.git
synced 2025-07-30 17:15:43 +02:00
LPM alerting
This commit is contained in:
parent
3082923936
commit
9cb1cde275
37
app.js
37
app.js
@ -208,6 +208,19 @@ function get_socket_clients_connected_count() {
|
||||
return socket_clients;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}, 1000);
|
||||
} else {
|
||||
console.log('filename not provided');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Websocket Server
|
||||
*/
|
||||
@ -333,10 +346,12 @@ slack = new Slack();
|
||||
slack.setWebhook(webhookUri);
|
||||
|
||||
function slack_message(message) {
|
||||
console.log("[Slack] %s", message);
|
||||
|
||||
slack.webhook({
|
||||
channel: glass_config.slack_alert_channel,
|
||||
username: "Glass",
|
||||
icon_emoji: "https://i.imgur.com/VDzAuAq.png",
|
||||
icon_emoji: "https://imgur.com/wD3CcBi",
|
||||
text: message
|
||||
}, function (err, response) {
|
||||
console.log(response);
|
||||
@ -348,17 +363,19 @@ function slack_message(message) {
|
||||
*/
|
||||
|
||||
alert_status = [];
|
||||
alert_status['leases_per_second'] = 0;
|
||||
alert_status['leases_per_minute'] = 0;
|
||||
|
||||
alert_check_timer = setInterval(function(){
|
||||
if(glass_config.lease_per_second_threshold > 0) {
|
||||
if (current_leases_per_second <= glass_config.lease_per_second_threshold && alert_status['leases_per_second'] == 0) {
|
||||
alert_status['leases_per_second'] = 1;
|
||||
// slack_message(":warning: WARNING: DHCP leases per second have dropped below critical threshold (" + glass_config.lease_per_second_threshold + ") Current LP/s (" + current_leases_per_second + ")");
|
||||
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 critical threshold (" + glass_config.leases_per_minute_threshold.toLocaleString('en') + ") Current LP/s (" + leases_per_minute.toLocaleString('en') + ")");
|
||||
}
|
||||
else if (current_leases_per_second >= glass_config.lease_per_second_threshold && alert_status['leases_per_second'] == 1) {
|
||||
alert_status['leases_per_second'] = 0;
|
||||
// slack_message(":white_check_mark: CLEAR: DHCP leases per second have returned to above the critical threshold (" + glass_config.lease_per_second_threshold + ") Current LP/s (" + current_leases_per_second + ")");
|
||||
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 the critical threshold (" + glass_config.leases_per_minute_threshold.toLocaleString('en') + ") Current LP/s (" + leases_per_minute.toLocaleString('en') + ")");
|
||||
}
|
||||
}
|
||||
}, (5 * 1000));
|
||||
}, (60 * 1000));
|
@ -6,7 +6,7 @@
|
||||
"config_file": "/etc/dhcp/dhcpd.conf",
|
||||
"shared_network_critical_threshold": 95,
|
||||
"shared_network_warning_threshold": 80,
|
||||
"lease_per_second_threshold": 0,
|
||||
"leases_per_minute_threshold": 0,
|
||||
"slack_webhook_url": "",
|
||||
"slack_alert_channel": ""
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ router.post('/', function(req, res, next) {
|
||||
|
||||
glass_config.shared_network_critical_threshold = request.shared_network_critical_threshold;
|
||||
glass_config.shared_network_warning_threshold = request.shared_network_warning_threshold;
|
||||
glass_config.lease_per_second_threshold = request.lease_per_second_threshold;
|
||||
glass_config.leases_per_minute_threshold = request.leases_per_minute_threshold;
|
||||
glass_config.slack_webhook_url = request.slack_webhook_url;
|
||||
glass_config.slack_alert_channel = request.slack_alert_channel;
|
||||
|
||||
|
@ -17,13 +17,13 @@ router.get('/', function(req, res, next) {
|
||||
glass_config = json_file.readFileSync('config/glass_config.json');
|
||||
|
||||
/* Shared Network Alert Threshold (Critical) */
|
||||
input = template_render.form_input('Shared Network Alert Threshold (Critical)', '<input type="input" class="form-control" id="shared_network_critical_threshold" placeholder="95%" value="' + glass_config.shared_network_critical_threshold + '">');
|
||||
input = template_render.form_input('Shared Network Alert Threshold % (Critical)', '<input type="input" class="form-control" id="shared_network_critical_threshold" placeholder="95%" value="' + glass_config.shared_network_critical_threshold + '">');
|
||||
|
||||
/* Shared Network Alert Threshold (Warning) */
|
||||
input = input + template_render.form_input('Shared Network Alert Threshold (Warning)', '<input type="input" class="form-control" id="shared_network_warning_threshold" placeholder="80" value="' + glass_config.shared_network_warning_threshold + '">');
|
||||
input = input + template_render.form_input('Shared Network Alert Threshold % (Warning)', '<input type="input" class="form-control" id="shared_network_warning_threshold" placeholder="80" value="' + glass_config.shared_network_warning_threshold + '">');
|
||||
|
||||
/* Leases Per Second Threshold */
|
||||
input = input + template_render.form_input('Alert when Leases Per Second Reaches Below this Number', '<input type="input" class="form-control" id="lease_per_second_threshold" placeholder="0" value="' + glass_config.lease_per_second_threshold + '">');
|
||||
/* Leases Per Minute Threshold */
|
||||
input = input + template_render.form_input('Alert when Leases Per Minute Reaches Below this Number', '<input type="input" class="form-control" id="leases_per_minute_threshold" placeholder="0" value="' + glass_config.leases_per_minute_threshold + '">');
|
||||
|
||||
// <div id="glass_settings_result"></div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user