Nagios Services

- Moved check-services.php to a poller module
    - Added performance data collection to the poller
    - Centralised DB functions to includes/services.inc.php
    - Created add/edit/delete functions off the device, services page
    - Removed legacy edit/delete interfaces.
    - Moved and modified check.inc scripts
    - Documentation Updates
    - Modified services table
This commit is contained in:
Aaron Daniels
2016-03-15 22:16:08 +10:00
parent 2d2f56c3dc
commit 0d6cfec589
61 changed files with 1040 additions and 802 deletions

View File

@@ -3,30 +3,24 @@
if (is_admin() === true || is_read() === true) {
if ($_POST['addsrv']) {
if ($_SESSION['userlevel'] >= '10') {
include 'includes/service-add.inc.php';
}
}
$updated = '1';
if ($_POST['delsrv']) {
if ($_SESSION['userlevel'] >= '10') {
include 'includes/service-delete.inc.php';
}
}
if ($_POST['confirm-editsrv']) {
echo 'yeah';
if ($_SESSION['userlevel'] >= '10') {
include 'includes/service-edit.inc.php';
}
}
if ($handle = opendir($config['install_dir'].'/includes/services/')) {
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..' && !strstr($file, '.')) {
$servicesform .= "<option value='$file'>$file</option>";
$service_id = service_add($_POST['device'], $_POST['type'], $_POST['descr'], $_POST['ip'], $_POST['params'], 0);
if ($service_id) {
$message .= $message_break.'Service added ('.$service_id.')!';
$message_break .= '<br />';
}
}
}
// Build the types list.
if ($handle = opendir($config['nagios_plugins'])) {
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..' && !strstr($file, '.') && strstr($file, 'check_')) {
list(,$check_name) = explode('_',$file,2);
$servicesform .= "<option value='$check_name'>$check_name</option>";
}
}
closedir($handle);
}
@@ -37,45 +31,6 @@ if (is_admin() === true || is_read() === true) {
print_message('Device Settings Saved');
}
if (dbFetchCell('SELECT COUNT(*) from `services` WHERE `device_id` = ?', array($device['device_id'])) > '0') {
$i = '1';
foreach (dbFetchRows('select * from services WHERE device_id = ? ORDER BY service_type', array($device['device_id'])) as $service) {
$existform .= "<option value='".$service['service_id']."'>".$service['service_type'].'</option>';
}
}
echo '<div class="row">';
if ($existform) {
echo '<div class="col-sm-6">';
if ($_POST['editsrv'] == 'yes') {
include_once 'includes/print-service-edit.inc.php';
}
else {
echo "
<h3><span class='label label-info threeqtr-width'>Edit / Delete Service</span></h3>
<form method='post' action='' class='form-horizontal'>
<div class='well well-lg'>
<div class='form-group'>
<label for='service' class='col-sm-2 control-label'>Type: </label>
<div class='col-sm-4'>
<select name='service' class='form-control input-sm'>
$existform
</select>
</div>
</div>
<div class='form-group'>
<div class='col-sm-offset-2 col-sm-4'>
<button type='submit' class='btn btn-primary btn-sm' name='editsrv' id='editsrv' value='yes'>Edit</button> <button type='submit' class='btn btn-danger btn-sm' name='delsrv' id='delsrv' value='yes'>Delete</button>
</div>
</div>
</div>
</form>";
}
echo '</div>';
}
echo '<div class="col-sm-6">';
include_once 'includes/print-service-add.inc.php';

View File

@@ -7,12 +7,10 @@ $ports['up'] = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id =
$ports['down'] = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up'", array($device['device_id']));
$ports['disabled'] = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifAdminStatus` = 'down'", array($device['device_id']));
$services['total'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ?", array($device['device_id']));
$services['up'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_status` = '1' AND `service_ignore` ='0'", array($device['device_id']));
$services['down'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_status` = '0' AND `service_ignore` = '0'", array($device['device_id']));
$services['disabled'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_ignore` = '1'", array($device['device_id']));
$services = service_status($device['device_id']);
$services['total'] = array_sum($services);
if ($services['down']) {
if ($services[0]) {
$services_colour = $warn_colour_a;
}
else {

View File

@@ -1,49 +1,44 @@
<?php
if ($services['total']) {
echo '<div class="container-fluid">';
echo '<div class="row">
<div class="col-md-12">
<div class="panel panel-default panel-condensed">
<div class="panel-heading">';
echo "<img src='images/16/cog.png'><strong> Services</strong>";
echo ' </div>
<table class="table table-hover table-condensed table-striped">';
echo "
<tr>
<td><img src='images/16/cog.png'> $services[total]</td>
<td><img src='images/16/cog_go.png'> $services[up]</td>
<td><img src='images/16/cog_error.png'> $services[down]</td>
<td><img src='images/16/cog_disable.png'> $services[disabled]</td>
</tr>
<tr>
<td colspan='4'>";
foreach (dbFetchRows('SELECT * FROM services WHERE device_id = ? ORDER BY service_type', array($device['device_id'])) as $data) {
if ($data['service_status'] == '0' && $data['service_ignore'] == '1') {
$status = 'grey';
}
if ($data['service_status'] == '1' && $data['service_ignore'] == '1') {
$status = 'green';
}
if ($data['service_status'] == '0' && $data['service_ignore'] == '0') {
// Build the string.
foreach (service_get ($device['device_id']) as $data) {
if ($data['service_status'] == '1') {
// Ok
$status = 'green';
} elseif ($data['service_status'] == '0') {
// Critical
$status = 'red';
} elseif ($data['service_status'] == '2') {
// Warning
$status = 'red';
} else {
// Unknown
$status = 'grey';
}
if ($data['service_status'] == '1' && $data['service_ignore'] == '0') {
$status = 'blue';
}
echo "$break<a class=$status>".strtolower($data['service_type']).'</a>';
$string .= $break . '<a class=' . $status . '>' . strtolower ($data['service_type']) . '</a>';
$break = ', ';
}
echo '</td></tr></table>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
}//end if
?>
<div class="container-fluid">
<div class="row col-md-12">
<div class="panel panel-default panel-condensed">
<div class="panel-heading">
<img src='images/16/cog.png'><strong> Services</strong>
</div>
<table class="table table-hover table-condensed table-striped">
<tr>
<td title="Total"><img src='images/16/cog.png'> <?=$services['total']?></td>
<td title="Status - Ok"><img src='images/16/cog_add.png'> <?=$services[1]?></td>
<td title="Status - Critical"><img src='images/16/cog_delete.png'> <?=$services[0]?></td>
<td title="Status - Unknown"><img src='images/16/cog_error.png'> <?=$services[2]?></td>
</tr>
<tr>
<td colspan='4'><?=$string?></td>
</tr>
</table>
</div>
</div>
</div>
<?php
}

View File

@@ -1,5 +1,14 @@
<?php print_optionbar_start();
<?php
$pagetitle[] = 'Services';
require_once '../includes/services.inc.php';
$services = service_get($device['device_id']);
require_once 'includes/modal/new_service.inc.php';
require_once 'includes/modal/delete_service.inc.php';
print_optionbar_start();
echo "<span style='font-weight: bold;'>Services</span> &#187; ";
$menu_options = array(
@@ -29,43 +38,85 @@ foreach ($menu_options as $option => $text) {
$sep = ' | ';
}
unset($sep);
echo '<div class="pull-right"><a data-toggle="modal" href="#create-service"><img src="images/16/add.png" border="0" align="absmiddle"> Add Service</a></div>';
print_optionbar_end();
if (dbFetchCell('SELECT COUNT(service_id) FROM `services` WHERE device_id = ?', array($device['device_id'])) > '0') {
echo "<div style='margin: 5px;'><table cellpadding=7 border=0 cellspacing=0 width=100%>";
$i = '1';
foreach (dbFetchRows('SELECT * FROM `services` WHERE `device_id` = ? ORDER BY `service_type`', array($device['device_id'])) as $service) {
include 'includes/print-service.inc.php';
?>
<div class="row col-sm-12"><span id="message"></span></div>
<?php
if (count($services) > '0') {
// Loop over each service, pulling out the details.
?>
<table class="table table-hover table-condensed table-striped">
<?php
foreach ($services as $service) {
$service['service_ds'] = htmlspecialchars_decode($service['service_ds']);
if ($service['service_status'] == 1) {
$status = "<span class='green'>Ok</span>";
}
elseif ($service['service_status'] == 2) {
$status = "<span class='red'>Warning</span>";
}
elseif ($service['service_status'] == 0) {
$status = "<span class='red'>Critical</span>";
}
else {
$status = "<span class='grey'>Unknown</span>";
}
?>
<tr id="row_<?=$service['service_id']?>">
<td>
<div class="col-sm-12">
<div class="col-sm-2"><?=$service['service_type']?></div>
<div class="col-sm-6"><?=$service['service_desc']?></div>
<div class="col-sm-2"><?=$status?></div>
<div class="pull-right">
<button type='button' class='btn btn-primary btn-sm' aria-label='Edit' data-toggle='modal' data-target='#create-service' data-service_id='<?=$service['service_id']?>' name='edit-service'><span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></button>
<button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#confirm-delete' data-service_id='<?=$service['service_id']?>' name='delete-service'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></button>
</div>
</div>
<div class="col-sm-12">
<div class="col-sm-8"><?=nl2br(trim($service['service_message']))?></div>
<div class="col-sm-4"><?=formatUptime(time() - $service['service_changed'])?></div>
</div>
<?php
if ($vars['view'] == 'details') {
$graph_array['height'] = '100';
$graph_array['width'] = '210';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $service['service_id'];
$graph_array['type'] = 'service_availability';
// if we have a script for this check, use it.
$check_script = $config['install_dir'].'/includes/services/check_'.strtolower($service['service_type']).'.inc.php';
if (is_file($check_script)) {
include $check_script;
$periods = array(
'day',
'week',
'month',
'year',
);
// If we have a replacement DS use it.
if (isset($check_ds)) {
$service['service_ds'] = $check_ds;
}
}
echo '<tr style="background-color: '.$bg.'; padding: 7px;"><td colspan=4>';
include 'includes/print-graphrow.inc.php';
echo '</td></tr>';
$graphs = json_decode($service['service_ds'],TRUE);
foreach ($graphs as $k => $v) {
$graph_array['device'] = $device['device_id'];
$graph_array['type'] = 'device_service';
$graph_array['service'] = $service['service_id'];
$graph_array['ds'] = $k;
?>
<div class="col-sm-12">
<?php
include 'includes/print-graphrow.inc.php';
?>
</div>
<?php
}
}
}
echo '</table></div>';
?>
</td>
</tr>
</table>
<?php
}
else {
echo 'No Services';
?>
<div class='row col-sm-12'>No Services</div>
<?php
}
$pagetitle[] = 'Services';
?>