2017-09-02 16:59:36 +02:00
/ * *
* 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' ) ;
2017-09-06 11:42:05 +02:00
var authorize = require ( '../lib/authorize.js' ) ;
2017-09-02 16:59:36 +02:00
2017-09-06 11:42:05 +02:00
router . get ( '/' , authorize . auth , function ( req , res , next ) {
2017-09-02 16:59:36 +02:00
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) */
2017-09-06 10:14:39 +02:00
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 + '">' ) ;
2017-09-02 16:59:36 +02:00
/* Shared Network Alert Threshold (Warning) */
2017-09-06 10:14:39 +02:00
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 + '">' ) ;
2017-09-02 16:59:36 +02:00
2017-09-06 10:14:39 +02:00
/* 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 + '">' ) ;
2017-09-02 16:59:36 +02:00
// <div id="glass_settings_result"></div>
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 <img src="images/slack-icon.png" style="height:25px; width: auto;"> ' , '<input type="input" class="form-control" id="slack_webhook_url" placeholder="https://hooks.slack.com/services/xxx/xxx/xxx" value="' + glass _config . slack _webhook _url + '">' ) ;
/* Shared Network Alert Threshold (Warning) */
input = input + template _render . form _input ( 'Slack Channel <img src="images/slack-icon.png" style="height:25px; width: auto;"> ' , '<input type="input" class="form-control" id="slack_alert_channel" placeholder="#channel" value="' + glass _config . slack _alert _channel + '">' ) ;
// <div id="glass_settings_result"></div>
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" ,
'<button type="button" class="btn btn-primary waves-effect" onclick="save_alarm_settings()"><i class="material-icons">add_alert</i> <span>Save Alarm Settings</span></button>'
) ;
res . send ( template _render . get _index _template ( glass _settings _template , req . url ) ) ;
} ) ;
module . exports = router ;