Skip to content
Permalink
Browse files

Improvements to NEMS TV Dashboard

  • Loading branch information...
NEMS Linux
NEMS Linux committed Jul 11, 2019
1 parent 447abd3 commit f89c77f31a75f606a26d68387ddd6287dfc5c7aa
Showing with 103 additions and 9 deletions.
  1. +61 −6 config/index.php
  2. +8 −1 tv/index.php
  3. +34 −2 tv/livestatus.php
@@ -169,6 +169,8 @@
}
if (is_array($nemsconf) && isset($_POST) && count($_POST) > 0) { // Overwrite the existing conf data
// only need to include the conf options that are included in NEMS SST. The rest will be re-written from existing values.
$nemsconf['tv_require_notify'] = sanitize($_POST['tv_require_notify']);
$nemsconf['tv_24h'] = sanitize($_POST['tv_24h']);
$nemsconf['osbpass'] = sanitize($_POST['osbpass']);
$nemsconf['osbkey'] = sanitize($_POST['osbkey']);
$nemsconf['webhook'] = sanitize($_POST['webhook']);
@@ -255,8 +257,9 @@ function sanitize($string) {
<ul class="nav nav-tabs">
<li class="active"><a href="#general" data-toggle="tab">General</a></li>
<li><a href="#cloud" data-toggle="tab">NEMS Cloud Services</a></li>
<li style="display:none;"><a href="#networking" data-toggle="tab">Networking</a></li>
<li style="display:none;"><a href="#networking" data-toggle="tab">Networking</a></li>
<li><a href="#notifications" data-toggle="tab">Notifications</a></li>
<li><a href="#tv" data-toggle="tab">TV Dashboard</a></li>
<li><a href="#options" data-toggle="tab">Optional Services</a></li>
</ul>
<div class="tab-content">
@@ -730,6 +733,63 @@ function sanitize($string) {
</div>




<!-- tv dashboard -->
<?php if (ver('nems') >= 1.4) { ?>

<div class="tab-pane fade in" id="tv">
<div class="row">
<div class="col-md-12">
<div class="row">

<div>


<div class="col-md-12">

<header>NEMS TV Dashboard Configuration</header>
<fieldset>

<?php
if (checkConfEnabled('tvpw') == true) $checked = 'CHECKED="CHECKED"'; else $checked = '';
echo '<div class="row" style="margin-bottom: 20px;"><label class="toggle col-md-4"><input ' . $checked . ' name="tvpw" type="checkbox" class="services"><i></i>Allow TV Dashboard Without Password</label></div>';
?>

<section>
<label class="label">When should issues appear on NEMS TV Dashboard?</label>
<label class="select">
<select name="tv_require_notify">
<option value="1"<?php if (!isset($nemsconf['tv_require_notify']) || $nemsconf['tv_require_notify'] == 1) echo ' SELECTED'; ?>>Once they enter their individual notification period (Default)</option>
<option value="2"<?php if ($nemsconf['tv_require_notify'] == 2) echo ' SELECTED'; ?>>Immediately</option>
</select>
<i></i>
</label>
</section>

<section>
<label class="label">Clock Format</label>
<label class="select">
<select name="tv_24h">
<option value="3"<?php if (!isset($nemsconf['tv_24h']) || $nemsconf['tv_24h'] == 3) echo ' SELECTED'; ?>>3:25</option>
<option value="2"<?php if ($nemsconf['tv_24h'] == 2) echo ' SELECTED'; ?>>3:25 PM</option>
<option value="1"<?php if ($nemsconf['tv_24h'] == 1) echo ' SELECTED'; ?>>15:25</option>
</select>
<i></i>
</label>
</section>

</fieldset>


</div>

</div></div></div></div>
</div>
<?php } ?>

<!-- / tv dashboard -->

<div class="tab-pane fade in" id="options">
<div class="row">
<div class="col-md-12">
@@ -757,11 +817,6 @@ function sanitize($string) {
if (checkConfEnabled('monitorix') == true) $checked = 'CHECKED="CHECKED"'; else $checked = '';
echo '<label class="toggle text-right"><input ' . $checked . ' name="monitorix" type="checkbox" class="services reboot"><i></i>Monitorix</label>';
if (ver('nems') >= 1.4) {
if (checkConfEnabled('tvpw') == true) $checked = 'CHECKED="CHECKED"'; else $checked = '';
echo '<label class="toggle text-right"><input ' . $checked . ' name="tvpw" type="checkbox" class="services"><i></i>Allow TV Dashboard Without Password</label>';
}
?>
<script>
window.onload = function() {
@@ -63,9 +63,16 @@
// timestamp stuff
function createTimeStamp() {
<?php
$tv_24h = intval(trim(shell_exec('/usr/local/bin/nems-info tv_24h')));
?>
// create timestamp
var ts = new Date();
ts = ts.toLocaleTimeString(navigator.language, {hour: '2-digit', minute:'2-digit'}).replace(/(:\d{2}| [AP]M)$/, "");
// see if the user has set 24 hour or 12 hour format
var options = { <?php
if ($tv_24h == 1) echo 'hour12: false';
?> };
ts = ts.toLocaleTimeString(navigator.language, {hour: '2-digit', minute:'2-digit'}, options)<?php if ($tv_24h != 2) echo '.replace(/(:\d{2}| [AP]M)$/, "")'; ?>;
$("#timestamp_wrap").empty().append("<div class=\"timestamp_drop\"></div><div class=\"timestamp_stamp\">" + ts +"</div>");
}
@@ -24,6 +24,9 @@
'host_name ~ ',
);
$in_notification_period = shell_exec('/usr/local/bin/nems-info tv_require_notify');
if ($in_notification_period != 1 && $in_notification_period != 2) $in_notification_period = 1; // use default setting if for some reason nems-info didn't provide the setting
function _print_duration($start_time, $end_time)
{
$duration = $end_time - $start_time;
@@ -129,6 +132,7 @@ function queryLivestatus($query) {
$hosts = array();
while ( list(, $filter) = each($custom_filters) ) {
if ($in_notification_period == 1) {
$query = <<<"EOQ"
GET hosts
Columns: host_name alias
@@ -141,7 +145,19 @@ function queryLivestatus($query) {
OutputFormat: json
ResponseHeader: fixed16
EOQ;
} else {
$query = <<<"EOQ"
GET hosts
Columns: host_name alias
Filter: $filter
Filter: scheduled_downtime_depth = 0
Filter: acknowledged = 0
Filter: host_acknowledged = 0
Filter: hard_state != 0
OutputFormat: json
ResponseHeader: fixed16
EOQ;
}
$json=queryLivestatus($query);
$tmp = json_decode($json, true);
if ( count($tmp) ) {
@@ -331,6 +347,7 @@ function queryLivestatus($query) {
$services = array();
while ( list(, $filter) = each($custom_filters) ) {
if ($in_notification_period == 1) {
$query = <<<"EOQ"
GET services
Columns: host_name description state plugin_output last_hard_state_change last_check
@@ -346,7 +363,22 @@ function queryLivestatus($query) {
OutputFormat: json
ResponseHeader: fixed16
EOQ;
} else {
$query = <<<"EOQ"
GET services
Columns: host_name description state plugin_output last_hard_state_change last_check
Filter: $filter
Filter: scheduled_downtime_depth = 0
Filter: host_scheduled_downtime_depth = 0
Filter: service_scheduled_downtime_depth = 0
Filter: host_acknowledged = 0
Filter: acknowledged = 0
Filter: state != 0
Filter: state_type = 1
OutputFormat: json
ResponseHeader: fixed16
EOQ;
}
$json=queryLivestatus($query);
$tmp = json_decode($json, true);
if ( count($tmp) ) {

0 comments on commit f89c77f

Please sign in to comment.
You can’t perform that action at this time.