Allow setting Service Ignore and Disable in UI (#10334)
* Added disable and ignore checkboxes to services modal * Updated add_services function to set disabled field * Modified check-services.php respect service_disable value * Minor code change for consistency in new_service.inc.php * Removed unneeded includes
This commit is contained in:
parent
12cd540a92
commit
5a2f2497bb
|
@ -61,35 +61,18 @@ $sql = 'SELECT D.*,S.*,attrib_value FROM `devices` AS D'
|
|||
.' ORDER by D.device_id DESC;';
|
||||
|
||||
foreach (dbFetchRows($sql) as $service) {
|
||||
// Run the polling function if the associated device is up, "Disable ICMP Test" option is not enabled,
|
||||
// Run the polling function if service is enabled and the associated device is up, "Disable ICMP Test" option is not enabled,
|
||||
// or service hostname/ip is different from associated device
|
||||
if ($service['status'] == 1 || ($service['status'] == 0 && $service['status_reason'] === 'snmp') ||
|
||||
if (!$service['service_disabled'] && ($service['status'] == 1 || ($service['status'] == 0 && $service['status_reason'] === 'snmp') ||
|
||||
$service['attrib_value'] === 'true' || ($service['service_ip'] !== $service['hostname'] &&
|
||||
$service['service_ip'] !== inet6_ntop($service['ip']) )) {
|
||||
// Mark service check as enabled if it was disabled previously because device was down
|
||||
if ($service['service_disabled']) {
|
||||
dbUpdate(
|
||||
array('service_disabled' => 0),
|
||||
'services',
|
||||
'`service_id` = ?',
|
||||
array($service['service_id'])
|
||||
);
|
||||
}
|
||||
$service['service_ip'] !== inet6_ntop($service['ip']) ))) {
|
||||
poll_service($service);
|
||||
$polled_services++;
|
||||
} else {
|
||||
d_echo("\nService check - ".$service['service_id']."\nSkipping service check because device "
|
||||
.$service['hostname']." is down due to icmp.\n");
|
||||
// Mark service check as disabled while device is down and log to eventlog that service check is skipped,
|
||||
// but only if it's not already marked as disabled
|
||||
if (!$service['service_disabled']) {
|
||||
dbUpdate(
|
||||
array('service_disabled' => 1),
|
||||
'services',
|
||||
'`service_id` = ?',
|
||||
array($service['service_id'])
|
||||
);
|
||||
log_event(
|
||||
d_echo("\nService check - ".$service['service_id']."\nSkipping service check because device "
|
||||
.$service['hostname']." is down due to icmp.\n");
|
||||
Log::event(
|
||||
"Service check - {$service['service_desc']} ({$service['service_id']}) -
|
||||
Skipping service check because device {$service['hostname']} is down due to icmp",
|
||||
$service['device_id'],
|
||||
|
@ -97,9 +80,12 @@ foreach (dbFetchRows($sql) as $service) {
|
|||
4,
|
||||
$service['service_id']
|
||||
);
|
||||
} else {
|
||||
d_echo("\nService check - ".$service['service_id']."\nSkipping service check because device "
|
||||
.$service['service_type']." is disabled.\n");
|
||||
}
|
||||
}
|
||||
} //end service foreach
|
||||
}
|
||||
|
||||
$poller_end = microtime(true);
|
||||
$poller_run = ($poller_end - $poller_start);
|
||||
|
|
|
@ -23,11 +23,13 @@ $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'];
|
||||
|
||||
if (is_numeric($service_id) && $service_id > 0) {
|
||||
// Need to edit.
|
||||
$update = array('service_desc' => $desc, 'service_ip' => $ip, 'service_param' => $param);
|
||||
$update = array('service_desc' => $desc, 'service_ip' => $ip, 'service_param' => $param, 'service_ignore' => $ignore, 'service_disabled' => $disabled);
|
||||
if (is_numeric(edit_service($update, $service_id))) {
|
||||
$status = array('status' =>0, 'message' => 'Modified Service: <i>'.$service_id.': '.$type.'</i>');
|
||||
} else {
|
||||
|
@ -35,7 +37,7 @@ if (is_numeric($service_id) && $service_id > 0) {
|
|||
}
|
||||
} else {
|
||||
// Need to add.
|
||||
$service_id = add_service($device_id, $type, $desc, $ip, $param);
|
||||
$service_id = add_service($device_id, $type, $desc, $ip, $param, $ignore, $disabled);
|
||||
if ($service_id == false) {
|
||||
$status = array('status' =>1, 'message' => 'ERROR: Failed to add Service: <i>'.$type.'</i>');
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,9 @@ if (is_numeric($service_id) && $service_id > 0) {
|
|||
'stype' => $service[0]['service_type'],
|
||||
'ip' => $service[0]['service_ip'],
|
||||
'desc' => $service[0]['service_desc'],
|
||||
'param' => $service[0]['service_param']
|
||||
'param' => $service[0]['service_param'],
|
||||
'ignore' => $service[0]['service_ignore'],
|
||||
'disabled' => $service[0]['service_disabled']
|
||||
);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
|
|
@ -26,7 +26,6 @@ if (LegacyAuth::user()->hasGlobalAdmin()) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal fade bs-example-modal-sm" id="create-service" tabindex="-1" role="dialog" aria-labelledby="Create" aria-hidden="true">
|
||||
|
@ -46,7 +45,7 @@ if (LegacyAuth::user()->hasGlobalAdmin()) {
|
|||
<span id="ajax_response"> </span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-service">
|
||||
<div class="form-service row">
|
||||
<label for='stype' class='col-sm-3 control-label'>Type: </label>
|
||||
<div class="col-sm-9">
|
||||
<select id='stype' name='stype' placeholder='type' class='form-control has-feedback'>
|
||||
|
@ -54,25 +53,37 @@ if (LegacyAuth::user()->hasGlobalAdmin()) {
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-service'>
|
||||
<div class='form-service row'>
|
||||
<label for='desc' class='col-sm-3 control-label'>Description: </label>
|
||||
<div class='col-sm-9'>
|
||||
<textarea id='desc' name='desc' class='form-control'></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-service">
|
||||
<div class="form-service row">
|
||||
<label for='ip' class='col-sm-3 control-label'>IP Address: </label>
|
||||
<div class="col-sm-9">
|
||||
<input type='text' id='ip' name='ip' class='form-control has-feedback' placeholder='<?php echo $device['hostname']?>'/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-service">
|
||||
<div class="form-service row">
|
||||
<label for='param' class='col-sm-3 control-label'>Parameters: </label>
|
||||
<div class="col-sm-9">
|
||||
<input type='text' id='param' name='param' class='form-control has-feedback' placeholder=''/>
|
||||
<input type='text' id='param' name='param' class='form-control has-feedback' placeholder=''/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-service">
|
||||
<div class="form-service row">
|
||||
<label for='ignore' class='col-sm-3 control-label'>Ignore: </label>
|
||||
<div class="col-sm-9">
|
||||
<input type='checkbox' id='ignore' name='ignore'>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-service row">
|
||||
<label for='disabled' class='col-sm-3 control-label'>Disabled: </label>
|
||||
<div class="col-sm-9">
|
||||
<input type='checkbox' id='disabled' name='disabled'>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-service row">
|
||||
<div class="col-sm-offset-3 col-sm-9">
|
||||
<button class="btn btn-success btn-sm" type="submit" name="service-submit" id="service-submit" value="save">Save Service</button>
|
||||
</div>
|
||||
|
@ -93,6 +104,8 @@ $('#create-service').on('hide.bs.modal', function (event) {
|
|||
$('#ip').val('');
|
||||
$('#desc').val('');
|
||||
$('#param').val('');
|
||||
$('#ignore').val('');
|
||||
$('#disabled').val('');
|
||||
});
|
||||
|
||||
// on-load
|
||||
|
@ -112,8 +125,17 @@ $('#create-service').on('show.bs.modal', function (e) {
|
|||
$('#ip').val(output['ip']);
|
||||
$('#desc').val(output['desc']);
|
||||
$('#param').val(output['param']);
|
||||
$('#ignore').val(output['ignore']);
|
||||
$('#disabled').val(output['disabled']);
|
||||
if ($('#ignore').attr('value') == 1) {
|
||||
$('#ignore').prop("checked", true);
|
||||
}
|
||||
if ($('#disabled').attr('value') == 1) {
|
||||
$('#disabled').prop("checked", true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// on-submit
|
||||
|
|
|
@ -35,7 +35,7 @@ function get_service_status($device = null)
|
|||
return $service_count;
|
||||
}
|
||||
|
||||
function add_service($device, $type, $desc, $ip = 'localhost', $param = "", $ignore = 0)
|
||||
function add_service($device, $type, $desc, $ip = 'localhost', $param = "", $ignore = 0, $disabled = 0)
|
||||
{
|
||||
|
||||
if (!is_array($device)) {
|
||||
|
@ -46,7 +46,7 @@ function add_service($device, $type, $desc, $ip = 'localhost', $param = "", $ign
|
|||
$ip = $device['hostname'];
|
||||
}
|
||||
|
||||
$insert = array('device_id' => $device['device_id'], 'service_ip' => $ip, 'service_type' => $type, 'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $desc, 'service_param' => $param, 'service_ignore' => $ignore, 'service_status' => 3, 'service_message' => 'Service not yet checked', 'service_ds' => '{}');
|
||||
$insert = array('device_id' => $device['device_id'], 'service_ip' => $ip, 'service_type' => $type, 'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $desc, 'service_param' => $param, 'service_ignore' => $ignore, 'service_status' => 3, 'service_message' => 'Service not yet checked', 'service_ds' => '{}', 'servcie_disabled' => $disabled);
|
||||
return dbInsert($insert, 'services');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue