diff --git a/app.js b/app.js
index 90575d9..0d5ab0d 100644
--- a/app.js
+++ b/app.js
@@ -516,11 +516,28 @@ setTimeout(function(){
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') + ")");
+
+ 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') + ")");
+
+ email_alert("CRITICAL: Leases Per Minute Threshold", "DHCP leases per minute dropped below critical threshold
" +
+ "Threshold: (" + parseInt(glass_config.leases_per_minute_threshold).toLocaleString('en') + ")
" +
+ "Current: (" + parseInt(leases_per_minute).toLocaleString('en') + ")
" +
+ "This is usually indicative of a process or hardware problem and needs to be addressed immediately");
}
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') + ")");
+
+ 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') + ")");
+
+ email_alert("CLEAR: Leases Per Minute Threshold", "DHCP leases per minute have returned to normal
" +
+ "Threshold: (" + parseInt(glass_config.leases_per_minute_threshold).toLocaleString('en') + ")
" +
+ "Current: (" + parseInt(leases_per_minute).toLocaleString('en') + ")"
+ );
+
}
}
}, (60 * 1000));
@@ -571,7 +588,11 @@ setTimeout(function(){
)
{
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 + "%)");
+
+ 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 &&
@@ -579,7 +600,11 @@ setTimeout(function(){
)
{
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 + "%)");
+
+ 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 + "%)"
+ );
}
}
@@ -612,4 +637,55 @@ function round(num, places) {
return Math.round(num * multiplier) / multiplier;
}
+/* Load Mailer */
+const nodemailer = require('nodemailer');
+
+let transporter = nodemailer.createTransport({
+ sendmail: true,
+ newline: 'unix',
+ path: '/usr/sbin/sendmail'
+});
+
+console.log("[Glass Server] Loading E-Mail template...");
+
+fs = require('fs');
+var email_body = fs.readFileSync('./public/templates/email_template.html', "utf8");
+
+function email_alert(alert_title, alert_message) {
+ /* E-Mail Template Load */
+ console.log("Sending E-Mail...\n");
+
+ if(typeof glass_config.email_alert_to === "undefined")
+ return false;
+
+ if (glass_config.email_alert_to == ""){
+ console.log("[Glass Server] No email_to specified - returning...");
+ return false;
+ }
+
+ email_body = email_body.replace("[body_content_placeholder]", alert_message);
+ email_body = email_body.replace("[alert_title]", alert_title);
+ email_body = email_body.replace("[local_time]", new Date().toString() );
+
+ var mailOptions = {
+ from: "Glass Alerting Monitor glass@noreply.com",
+ to: glass_config.email_alert_to,
+ subject: "[Glass] " + alert_title,
+ html: email_body,
+ };
+ transporter.sendMail(mailOptions, function(error, info){
+ if(error){
+ console.log(error);
+ }
+ else {
+ console.log('Message sent: ' + info.response);
+ };
+ });
+}
+
+email_alert("CRITICAL: Leases Per Minute Threshold", "DHCP leases per minute dropped below critical threshold
" +
+ "Threshold: (" + parseInt(glass_config.leases_per_minute_threshold).toLocaleString('en') + ")
" +
+ "Current: (" + parseInt(leases_per_minute).toLocaleString('en') + ")
" +
+ "This is usually indicative of a process or hardware problem and needs to be addressed immediately");
+
console.log("[Glass Server] Bootup complete");
\ No newline at end of file
diff --git a/config/glass_config.json b/config/glass_config.json
index 159e611..f139b35 100644
--- a/config/glass_config.json
+++ b/config/glass_config.json
@@ -5,9 +5,12 @@
"log_file": "/var/log/dhcp.log",
"config_file": "/etc/dhcp/dhcpd.conf",
"shared_network_critical_threshold": "95",
- "shared_network_warning_threshold": "80",
- "slack_webhook_url": "https://hooks.slack.com/services/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",
- "slack_alert_channel": "#alerting",
- "leases_per_minute_threshold": "1000",
- "ip_ranges_to_allow": [""]
+ "shared_network_warning_threshold": "0",
+ "slack_webhook_url": "",
+ "slack_alert_channel": "",
+ "leases_per_minute_threshold": "50",
+ "ip_ranges_to_allow": [
+ ""
+ ],
+ "email_alert_to": ""
}
diff --git a/public/assets/css/glass.css b/public/assets/css/glass.css
new file mode 100644
index 0000000..467e23a
--- /dev/null
+++ b/public/assets/css/glass.css
@@ -0,0 +1,3 @@
+.info-box .content .text {
+ margin-top: 5px !important;
+}
\ No newline at end of file
diff --git a/public/templates/counters.html b/public/templates/counters.html
index 1fc861e..06677a7 100644
--- a/public/templates/counters.html
+++ b/public/templates/counters.html
@@ -40,7 +40,7 @@
- |
-
-
|