diff --git a/app.js b/app.js index a1ab72a..c443ff7 100644 --- a/app.js +++ b/app.js @@ -33,6 +33,8 @@ app.use('/dhcp_config_save', require('./routes/dhcp_config_save')); app.use('/dhcp_start_stop_restart', require('./routes/dhcp_start_stop_restart')); app.use('/api_examples', require('./routes/api_examples')); app.use('/glass_settings', require('./routes/glass_settings')); +app.use('/glass_alerts', require('./routes/glass_alerts')); +app.use('/glass_alert_settings_save', require('./routes/glass_alert_settings_save')); app.use('/glass_settings_save', require('./routes/glass_settings_save')); /* API Routes */ diff --git a/config/glass_config.json b/config/glass_config.json index 7b0c860..78976a0 100644 --- a/config/glass_config.json +++ b/config/glass_config.json @@ -2,6 +2,11 @@ "admin_user": "glassadmin", "admin_password": "glassadmin", "leases_file": "/var/lib/dhcp/dhcpd.leases", - "log_file": "/var/lib/dhcp.log", - "config_file": "/etc/dhcp/dhcpd.conf" + "log_file": "/var/log/dhcp.log", + "config_file": "/etc/dhcp/dhcpd.conf", + "shared_network_critical_threshold": 95, + "shared_network_warning_threshold": 80, + "lease_per_second_threshold": 0, + "slack_webhook_url": "", + "slack_alert_channel": "" } diff --git a/lib/render_template.js b/lib/render_template.js index f26f460..b9d1792 100644 --- a/lib/render_template.js +++ b/lib/render_template.js @@ -24,7 +24,7 @@ module.exports = { return template.replace("[" + variable + "]", value); }, form_body: function (id, inputs) { - return '
' + inputs + '
'; + return '
' + inputs + '
'; }, form_input: function (title, input) { return '
' + input + '
'; diff --git a/public/assets/js/glass-core.js b/public/assets/js/glass-core.js index ee1b434..d186597 100644 --- a/public/assets/js/glass-core.js +++ b/public/assets/js/glass-core.js @@ -4,6 +4,45 @@ $( document ).ajaxComplete(function( event, request, settings ) { check_dashboard_active(); + + + /* + * Form input highlighting events + */ + + //On focus event + $('.form-control').focus(function () { + $(this).parent().addClass('focused'); + }); + + //On focusout event + $('.form-control').focusout(function () { + var $this = $(this); + if ($this.parents('.form-group').hasClass('form-float')) { + if ($this.val() == '') { $this.parents('.form-line').removeClass('focused'); } + } + else { + $this.parents('.form-line').removeClass('focused'); + } + }); + + //On label click + $('body').on('click', '.form-float .form-line .form-label', function () { + $(this).parent().find('input').focus(); + }); + + //Not blank form + $('.form-control').each(function () { + if ($(this).val() !== '') { + $(this).parents('.form-line').addClass('focused'); + } + }); + + $('.form-line').removeClass("focused"); +}); + +$( document ).ready(function() { + $('.form-line').removeClass("focused"); }); function check_dashboard_active() { diff --git a/public/images/slack-icon.png b/public/images/slack-icon.png new file mode 100644 index 0000000..50d2644 Binary files /dev/null and b/public/images/slack-icon.png differ diff --git a/public/templates/glass_alerts.html b/public/templates/glass_alerts.html new file mode 100644 index 0000000..856ff21 --- /dev/null +++ b/public/templates/glass_alerts.html @@ -0,0 +1,46 @@ +
+
+
+
+
+

+ Glass Alerts +

+
+
+ [c_content] +
+
+
+
+ +
+
+
+
+

+ Notification Settings + +

+
+
+ [n_content] +
+
+
+
+ +
+
+ +[save_button] + + \ No newline at end of file diff --git a/public/templates/index.html b/public/templates/index.html index b068822..bcb3270 100644 --- a/public/templates/index.html +++ b/public/templates/index.html @@ -203,9 +203,6 @@ - - - diff --git a/routes/glass_alert_settings_save.js b/routes/glass_alert_settings_save.js new file mode 100644 index 0000000..96bfbbe --- /dev/null +++ b/routes/glass_alert_settings_save.js @@ -0,0 +1,26 @@ +/** + * Created by cmiles on 8/9/2017. + */ + +var express = require('express'); +var router = express.Router(); + +router.post('/', function(req, res, next) { + var request = req.body; + var json_file = require('jsonfile'); + var glass_config = json_file.readFileSync('config/glass_config.json'); + + 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.slack_webhook_url = request.slack_webhook_url; + glass_config.slack_alert_channel = request.slack_alert_channel; + + json_file.writeFile('./config/glass_config.json', glass_config, {spaces: 2}, function(err) { + console.error(err); + }); + + res.send(''); +}); + +module.exports = router; \ No newline at end of file diff --git a/routes/glass_alerts.js b/routes/glass_alerts.js new file mode 100644 index 0000000..14fca3e --- /dev/null +++ b/routes/glass_alerts.js @@ -0,0 +1,55 @@ +/** + * Created by cmiles on 8/9/2017. + */ + +var express = require('express'); +var router = express.Router(); +var fs = require('fs'); +var template_render = require('../lib/render_template.js'); + +router.get('/', function(req, res, next) { + + glass_settings_template = template_render.get_template("glass_alerts"); + + var json_file = require('jsonfile'); + + /* Read Config */ + glass_config = json_file.readFileSync('config/glass_config.json'); + + /* Shared Network Alert Threshold (Critical) */ + input = template_render.form_input('Shared Network Alert Threshold (Critical)', ''); + + /* Shared Network Alert Threshold (Warning) */ + input = input + template_render.form_input('Shared Network Alert Threshold (Warning)', ''); + + /* Leases Per Second Threshold */ + input = input + template_render.form_input('Alert when Leases Per Second Reaches Below this Number', ''); + + //
+ + form_data = template_render.form_body("glass-alerts-form", input); + + glass_settings_template = template_render.set_template_variable(glass_settings_template, "c_content", form_data); + + /* Shared Network Alert Threshold (Critical) */ + input = template_render.form_input('Slack Webhook URL ', ''); + + /* Shared Network Alert Threshold (Warning) */ + input = input + template_render.form_input('Slack Channel ', ''); + + //
+ + form_data = template_render.form_body("glass-notifications-form", input); + + glass_settings_template = template_render.set_template_variable(glass_settings_template, "n_content", form_data); + + glass_settings_template = template_render.set_template_variable( + glass_settings_template, + "save_button", + '' + ); + + res.send(template_render.get_index_template(glass_settings_template, req.url)); +}); + +module.exports = router; \ No newline at end of file diff --git a/routes/glass_settings_save.js b/routes/glass_settings_save.js index 67591a4..61b7e40 100644 --- a/routes/glass_settings_save.js +++ b/routes/glass_settings_save.js @@ -9,8 +9,16 @@ router.post('/', function(req, res, next) { var request = req.body; var json_file = require('jsonfile'); - json_file.writeFile('./config/glass_config.json', request, {spaces: 2}, function(err) { - console.error(err); + var glass_config = json_file.readFileSync('config/glass_config.json'); + + glass_config.admin_user = request.admin_user; + glass_config.admin_password = request.admin_password; + glass_config.leases_file = request.leases_file; + glass_config.log_file = request.log_file; + glass_config.config_file = request.config_file; + + json_file.writeFile('./config/glass_config.json', glass_config, {spaces: 2}, function(err) { + console.error(err) }); res.send('');