mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
webui - Services bootstrap enable + status (#12736)
* Services bootstrap enable + status * style * copyright * generic create-service.inc.php to allow updates of some fields only * generic create-service.inc.php to allow updates of some fields only
This commit is contained in:
@@ -1,47 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
* create-service.inc.php
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2016 Aaron Daniels
|
||||
* @author Aaron Daniels <aaron@daniels.id.au>
|
||||
*/
|
||||
|
||||
if (! Auth::user()->hasGlobalAdmin()) {
|
||||
exit('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
$service_id = $vars['service_id'];
|
||||
$type = $vars['stype'];
|
||||
$desc = $vars['desc'];
|
||||
$ip = $vars['ip'];
|
||||
$param = $vars['param'];
|
||||
$ignore = isset($vars['ignore']) ? 1 : 0;
|
||||
$disabled = isset($vars['disabled']) ? 1 : 0;
|
||||
$device_id = $vars['device_id'];
|
||||
$template_id = $vars['template_id'];
|
||||
$name = $vars['name'];
|
||||
foreach (['desc', 'ip', 'ignore', 'disabled', 'param', 'name', 'template_id'] as $varname) {
|
||||
if (isset($vars[$varname])) {
|
||||
$update['service_' . $varname] = $vars[$varname];
|
||||
$$varname = $vars[$varname];
|
||||
}
|
||||
}
|
||||
foreach (['stype', 'device_id', 'service_id'] as $varname) {
|
||||
if (isset($vars[$varname])) {
|
||||
$$varname = $vars[$varname];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_numeric($service_id) && $service_id > 0) {
|
||||
// Need to edit.
|
||||
$update = ['service_desc' => $desc, 'service_ip' => $ip, 'service_param' => $param, 'service_ignore' => $ignore, 'service_disabled' => $disabled, 'service_template_id' => $template_id, 'service_name' => $name];
|
||||
if (is_numeric(edit_service($update, $service_id))) {
|
||||
$status = ['status' =>0, 'message' => 'Modified Service: <i>' . $service_id . ': ' . $type . '</i>'];
|
||||
$status = ['status' =>0, 'message' => 'Modified Service: <i>' . $service_id . ': ' . $stype . '</i>'];
|
||||
} else {
|
||||
$status = ['status' =>1, 'message' => 'ERROR: Failed to modify service: <i>' . $service_id . '</i>'];
|
||||
}
|
||||
} else {
|
||||
// Need to add.
|
||||
$service_id = add_service($device_id, $type, $desc, $ip, $param, $ignore, $disabled, 0, $name);
|
||||
$service_id = add_service($device_id, $stype, $desc, $ip, $param, $ignore, $disabled, 0, $name);
|
||||
if ($service_id == false) {
|
||||
$status = ['status' =>1, 'message' => 'ERROR: Failed to add Service: <i>' . $type . '</i>'];
|
||||
$status = ['status' =>1, 'message' => 'ERROR: Failed to add Service: <i>' . $stype . '</i>'];
|
||||
} else {
|
||||
$status = ['status' =>0, 'message' => 'Added Service: <i>' . $service_id . ': ' . $type . '</i>'];
|
||||
$status = ['status' =>0, 'message' => 'Added Service: <i>' . $service_id . ': ' . $stype . '</i>'];
|
||||
}
|
||||
}
|
||||
header('Content-Type: application/json');
|
||||
|
@@ -96,13 +96,15 @@ if (Auth::user()->hasGlobalAdmin()) {
|
||||
<div class="form-group row">
|
||||
<label for='ignore' class='col-sm-3 control-label'>Ignore alert tag: </label>
|
||||
<div class="col-sm-9">
|
||||
<input type='checkbox' id='ignore' name='ignore'>
|
||||
<input type="hidden" name="ignore" id='ignore' value="0">
|
||||
<input type='checkbox' id='ignore_box' name='ignore_box' onclick="$('#ignore').attr('value', $('#ignore_box').prop('checked')?1:0);">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for='disabled' class='col-sm-3 control-label'>Disable polling and alerting: </label>
|
||||
<div class="col-sm-9">
|
||||
<input type='checkbox' id='disabled' name='disabled'>
|
||||
<input type='hidden' id='disabled' name='disabled' value="0">
|
||||
<input type='checkbox' id='disabled_box' name='disabled_box' onclick="$('#disabled').attr('value', $('#disabled_box').prop('checked')?1:0);">
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
@@ -127,7 +129,9 @@ $('#create-service').on('hide.bs.modal', function (event) {
|
||||
$('#desc').val('');
|
||||
$('#param').val('');
|
||||
$('#ignore').val('');
|
||||
$('#ignore_box').val('');
|
||||
$('#disabled').val('');
|
||||
$('#disabled_box').val('');
|
||||
$('#service_template_id').val('');
|
||||
$('#name').val('');
|
||||
$('#service_template_name').val('');
|
||||
@@ -152,11 +156,13 @@ $('#create-service').on('show.bs.modal', function (e) {
|
||||
$('#param').val(output['param']);
|
||||
$('#ignore').val(output['ignore']);
|
||||
$('#disabled').val(output['disabled']);
|
||||
$('#ignore_box').val(output['ignore']);
|
||||
$('#disabled_box').val(output['disabled']);
|
||||
if ($('#ignore').attr('value') == 1) {
|
||||
$('#ignore').prop("checked", true);
|
||||
$('#ignore_box').prop("checked", true);
|
||||
}
|
||||
if ($('#disabled').attr('value') == 1) {
|
||||
$('#disabled').prop("checked", true);
|
||||
$('#disabled_box').prop("checked", true);
|
||||
}
|
||||
$('#service_template_id').val(output['service_template_id']);
|
||||
$('#name').val(output['name']);
|
||||
|
@@ -177,11 +177,11 @@ require_once 'includes/html/modal/delete_service.inc.php';
|
||||
echo '<th style="width:10%;max-width: 10%;">Check Type</th>';
|
||||
echo '<th style="width:10%;max-width: 15%;">Remote Host</th>';
|
||||
echo '<th >Message</th>';
|
||||
echo '<th style="width:15%;max-width: 15%;">Description</th>';
|
||||
echo '<th style="width:16%;max-width: 25%;">Description</th>';
|
||||
echo '<th style="width:15%;max-width: 15%;">Last Changed</th>';
|
||||
echo '<th style="width:5%;max-width: 5%;">Ignored</th>';
|
||||
echo '<th style="width:5%;max-width: 5%;">Disabled</th>';
|
||||
echo '<th style="width:5%;max-width:5%;"></th>';
|
||||
echo '<th style="width:2%;max-width: 2%;">Alert</th>';
|
||||
echo '<th style="width:4%;max-width: 4%;">Status</th>';
|
||||
echo '<th style="width:80px;max-width: 80px;"></th>';
|
||||
echo '</thead>';
|
||||
}
|
||||
|
||||
@@ -195,8 +195,37 @@ require_once 'includes/html/modal/delete_service.inc.php';
|
||||
echo '<td>' . nl2br(\LibreNMS\Util\Clean::html($service['service_message'], [])) . '</td>';
|
||||
echo '<td>' . nl2br(\LibreNMS\Util\Clean::html($service['service_desc'], [])) . '</td>';
|
||||
echo '<td>' . \LibreNMS\Util\Time::formatInterval(time() - $service['service_changed']) . '</td>';
|
||||
echo '<td>' . nl2br(\LibreNMS\Util\Clean::html($service['service_ignore'], [])) . '</td>';
|
||||
echo '<td>' . nl2br(\LibreNMS\Util\Clean::html($service['service_disabled'], [])) . '</td>';
|
||||
|
||||
$service_checked = '';
|
||||
$ico = 'pause';
|
||||
if ($service['service_ignore'] && $service['service_disabled']) {
|
||||
$color = 'default';
|
||||
$orig_colour = 'danger';
|
||||
$orig_ico = $ico;
|
||||
} elseif (! $service['service_ignore'] && ! $service['service_disabled']) {
|
||||
$ico = 'check';
|
||||
$color = 'success';
|
||||
$orig_colour = $color;
|
||||
$orig_ico = $ico;
|
||||
$service_checked = 'checked';
|
||||
} elseif (! $service['service_ignore'] && $service['service_disabled']) {
|
||||
$color = 'default';
|
||||
$orig_colour = 'success';
|
||||
$orig_ico = 'check';
|
||||
} elseif ($service['service_ignore'] && ! $service['service_disabled']) {
|
||||
$color = 'danger';
|
||||
$orig_colour = $color;
|
||||
$orig_ico = $ico;
|
||||
$service_checked = 'checked';
|
||||
}
|
||||
$service_id = $service['service_id'];
|
||||
$service_name = \LibreNMS\Util\Clean::html($service['service_name']);
|
||||
|
||||
echo '<td>' . '<span id="service_status-' . $service_id . '" class="fa fa-fw fa-2x text-' . $color . ' fa-' . $ico . '" data-original-title="" title=""></span></td>';
|
||||
|
||||
echo "<td><div id='on-off-checkbox-" . $service_id . " class='btn-group btn-group-sm' role='group'>";
|
||||
echo "<input id='" . $service_id . "' type='checkbox' name='service_status' data-orig_colour='" . $orig_colour . "' data-orig_state='" . $orig_ico . "' data-service_id='" . $service_id . "' data-service_name='" . $service_name . "' " . $service_checked . " data-size='small' data-toggle='modal'>";
|
||||
echo '</div></td>';
|
||||
|
||||
if (Auth::user()->hasGlobalAdmin()) {
|
||||
echo "<td>
|
||||
@@ -223,3 +252,48 @@ require_once 'includes/html/modal/delete_service.inc.php';
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$("[name='service_status']").bootstrapSwitch('offColor','danger');
|
||||
$('input[name="service_status"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||
event.preventDefault();
|
||||
var $this = $(this);
|
||||
var service_id = $(this).data("service_id");
|
||||
var service_name = $(this).data("service_name");
|
||||
var service_disabled = $(this).data("service_disabled");
|
||||
var orig_state = $(this).data("orig_state");
|
||||
var orig_colour = $(this).data("orig_colour");
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax_form.php',
|
||||
data: { type: "create-service", service_id: service_id, disabled: (1 - state) },
|
||||
dataType: "html",
|
||||
success: function(msg) {
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
if(state) {
|
||||
$('#service_status-'+service_id).removeClass('fa-pause');
|
||||
$('#service_status-'+service_id).addClass('fa-'+orig_state);
|
||||
$('#service_status-'+service_id).removeClass('text-default');
|
||||
$('#service_status-'+service_id).removeClass('text-danger');
|
||||
$('#service_status-'+service_id).removeClass('text-success');
|
||||
$('#service_status-'+service_id).addClass('text-'+orig_colour);
|
||||
} else {
|
||||
$('#service_status-'+service_id).removeClass('fa-check');
|
||||
$('#service_status-'+service_id).addClass('fa-pause');
|
||||
$('#service_status-'+service_id).removeClass('text-success');
|
||||
$('#service_status-'+service_id).removeClass('text-danger');
|
||||
$('#service_status-'+service_id).addClass('text-default');
|
||||
}
|
||||
} else {
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
$('#'+service_id).bootstrapSwitch('toggleState',true );
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$("#message").html('<div class="alert alert-info">This service could not be updated.</div>');
|
||||
$('#'+service_id).bootstrapSwitch('toggleState',true );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user