Monitoring: Fix group and state summaries for IDO and Stadusdat

This commit is contained in:
Eric Lippmann 2013-10-22 14:35:58 +02:00
parent c5bed8ad00
commit 46569bad32
13 changed files with 518 additions and 290 deletions

View File

@ -300,21 +300,21 @@ class Monitoring_ListController extends MonitoringController
$query = GroupsummaryView::fromRequest(
$this->_request,
array(
'servicegroup_name',
'cnt_hosts_up',
'cnt_hosts_unreachable',
'cnt_hosts_unreachable_unhandled',
'cnt_hosts_down',
'cnt_hosts_down_unhandled',
'cnt_hosts_pending',
'cnt_services_ok',
'cnt_services_unknown',
'cnt_services_unknown_unhandled',
'cnt_services_critical',
'cnt_services_critical_unhandled',
'cnt_services_warning',
'cnt_services_warning_unhandled',
'cnt_services_pending'
'servicegroup',
'hosts_up',
'hosts_unreachable_handled',
'hosts_unreachable_unhandled',
'hosts_down_handled',
'hosts_down_unhandled',
'hosts_pending',
'services_ok',
'services_unknown_handled',
'services_unknown_unhandled',
'services_critical_handled',
'services_critical_unhandled',
'services_warning_handled',
'services_warning_unhandled',
'services_pending'
)
)->getQuery();
$this->handleFormatRequest($query);
@ -329,21 +329,21 @@ class Monitoring_ListController extends MonitoringController
$query = GroupsummaryView::fromRequest(
$this->_request,
array(
'hostgroup_name',
'cnt_hosts_up',
'cnt_hosts_unreachable',
'cnt_hosts_unreachable_unhandled',
'cnt_hosts_down',
'cnt_hosts_down_unhandled',
'cnt_hosts_pending',
'cnt_services_ok',
'cnt_services_unknown',
'cnt_services_unknown_unhandled',
'cnt_services_critical',
'cnt_services_critical_unhandled',
'cnt_services_warning',
'cnt_services_warning_unhandled',
'cnt_services_pending'
'hostgroup',
'hosts_up',
'hosts_unreachable_handled',
'hosts_unreachable_unhandled',
'hosts_down_handled',
'hosts_down_unhandled',
'hosts_pending',
'services_ok',
'services_unknown_handled',
'services_unknown_unhandled',
'services_critical_handled',
'services_critical_unhandled',
'services_warning_handled',
'services_warning_unhandled',
'services_pending'
)
)->getQuery();
$this->handleFormatRequest($query);
@ -394,7 +394,7 @@ class Monitoring_ListController extends MonitoringController
if ($this->getParam('format') === 'sql'
&& IcingaConfig::app()->global->get('environment', 'production') === 'development') {
echo '<pre>'
. htmlspecialchars(wordwrap($query->__toString()))
. htmlspecialchars(wordwrap($query->dump()))
. '</pre>';
exit;
}

View File

@ -1,30 +1,81 @@
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<?= $this->sortControl->render($this); ?>
<?= $this->paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?>
<table class="table table-condensed">
<table>
<tbody>
<?php foreach($hostgroups as $hostgroup): ?>
<tr>
<td>
<a href="<?= $this->href('monitoring/list/services', array('hostgroups' => $hostgroup->hostgroup_name)); ?>">
<?= $hostgroup->hostgroup_name; ?>
<a href="<?= $this->href('monitoring/list/services', array('hostgroup' => $hostgroup->hostgroup)); ?>">
<?= $hostgroup->hostgroup; ?>
</a>
</td>
<td>
<div>
<span><?= $hostgroup->cnt_hosts_up; ?></span>
<span><?= $hostgroup->cnt_hosts_unreachable; ?>/<?= $hostgroup->cnt_hosts_unreachable_unhandled; ?></span>
<span><?= $hostgroup->cnt_hosts_down; ?>/<?= $hostgroup->cnt_hosts_down_unhandled; ?></span>
<span><?= $hostgroup->cnt_hosts_pending; ?></span>
<div class="nav navbar-nav topbar-host-status-summary">
<span class="topbar-status-up">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 0, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Hosts Up">
<?= $hostgroup->hosts_up ?>
</a>
</span>
<span class="topbar-status-down">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 1, 'host_unhandled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Hosts Down Unhandled">
<?= $hostgroup->hosts_down_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 1, 'host_handled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Hosts Down Handled">
<?= $hostgroup->hosts_down_handled ?>
</a>
</span>
<span class="topbar-status-unreachable">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 2, 'host_unhandled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Hosts Unreachable Unhandled">
<?= $hostgroup->hosts_unreachable_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 2, 'host_handled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Hosts Unreachable Handled">
<?= $hostgroup->hosts_unreachable_handled ?>
</a>
</span>
<span class="topbar-status-pending">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 99)); ?>" title="Hosts Pending">
<?= $hostgroup->hosts_pending ?>
</a>
</span>
</div>
</td>
<td>
<div>
<span><?= $hostgroup->cnt_services_ok; ?></span>
<span><?= $hostgroup->cnt_services_unknown; ?>/<?= $hostgroup->cnt_services_unknown_unhandled; ?></span>
<span><?= $hostgroup->cnt_services_critical; ?>/<?= $hostgroup->cnt_services_critical_unhandled; ?></span>
<span><?= $hostgroup->cnt_services_warning; ?>/<?= $hostgroup->cnt_services_warning_unhandled; ?></span>
<span><?= $hostgroup->cnt_services_pending; ?></span>
<div class="nav navbar-nav topbar-service-status-summary">
<span class="topbar-status-ok">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 0, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Services Ok">
<?= $hostgroup->services_ok ?>
</a>
</span>
<span class="topbar-status-critical">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 2, 'service_unhandled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Services Critical Unhandled">
<?= $hostgroup->services_critical_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 2, 'service_handled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Services Critical Handled">
<?= $hostgroup->services_critical_handled ?>
</a>
</span>
<span class="topbar-status-warning">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 1, 'service_unhandled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Services Warning Unhandled">
<?= $hostgroup->services_warning_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 1, 'service_handled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Services Warning Handled">
<?= $hostgroup->services_warning_handled ?>
</a>
</span>
<span class="topbar-status-unknown">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 3, 'service_unhandled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Services Unknown Unhandled">
<?= $hostgroup->services_unknown_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 3, 'service_handled' => 1, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Services Unknown Handled">
<?= $hostgroup->services_unknown_handled ?>
</a>
</span>
<span class="topbar-status-pending">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 99, 'hostgroup' => $hostgroup->hostgroup)); ?>" title="Services Pending">
<?= $hostgroup->services_pending ?>
</a>
</span>
</div>
</td>
</tr>

View File

@ -6,25 +6,76 @@
<?php foreach($servicegroups as $servicegroup): ?>
<tr>
<td>
<a href="<?= $this->href('monitoring/list/services', array('servicegroups' => $servicegroup->servicegroup_name)); ?>">
<?= $servicegroup->servicegroup_name; ?>
<a href="<?= $this->href('monitoring/list/services', array('servicegroup' => $servicegroup->servicegroup)); ?>">
<?= $servicegroup->servicegroup; ?>
</a>
</td>
<td>
<div>
<span><?= $servicegroup->cnt_hosts_up; ?></span>
<span><?= $servicegroup->cnt_hosts_unreachable; ?>/<?= $servicegroup->cnt_hosts_unreachable_unhandled; ?></span>
<span><?= $servicegroup->cnt_hosts_down; ?>/<?= $servicegroup->cnt_hosts_down_unhandled; ?></span>
<span><?= $servicegroup->cnt_hosts_pending; ?></span>
<div class="nav navbar-nav topbar-host-status-summary">
<span class="topbar-status-up">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 0, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Hosts Up">
<?= $servicegroup->hosts_up ?>
</a>
</span>
<span class="topbar-status-down">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 1, 'host_unhandled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Hosts Down Unhandled">
<?= $servicegroup->hosts_down_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 1, 'host_handled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Hosts Down Handled">
<?= $servicegroup->hosts_down_handled ?>
</a>
</span>
<span class="topbar-status-unreachable">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 2, 'host_unhandled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Hosts Unreachable Unhandled">
<?= $servicegroup->hosts_unreachable_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 2, 'host_handled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Hosts Unreachable Handled">
<?= $servicegroup->hosts_unreachable_handled ?>
</a>
</span>
<span class="topbar-status-pending">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 99)); ?>" title="Hosts Pending">
<?= $servicegroup->hosts_pending ?>
</a>
</span>
</div>
</td>
<td>
<div>
<span><?= $servicegroup->cnt_services_ok; ?></span>
<span><?= $servicegroup->cnt_services_unknown; ?>/<?= $servicegroup->cnt_services_unknown_unhandled; ?></span>
<span><?= $servicegroup->cnt_services_critical; ?>/<?= $servicegroup->cnt_services_critical_unhandled; ?></span>
<span><?= $servicegroup->cnt_services_warning; ?>/<?= $servicegroup->cnt_services_warning_unhandled; ?></span>
<span><?= $servicegroup->cnt_services_pending; ?></span>
<div class="nav navbar-nav topbar-service-status-summary">
<span class="topbar-status-ok">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 0, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Services Ok">
<?= $servicegroup->services_ok ?>
</a>
</span>
<span class="topbar-status-critical">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 2, 'service_unhandled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Services Critical Unhandled">
<?= $servicegroup->services_critical_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 2, 'service_handled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Services Critical Handled">
<?= $servicegroup->services_critical_handled ?>
</a>
</span>
<span class="topbar-status-warning">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 1, 'service_unhandled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Services Warning Unhandled">
<?= $servicegroup->services_warning_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 1, 'service_handled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Services Warning Handled">
<?= $servicegroup->services_warning_handled ?>
</a>
</span>
<span class="topbar-status-unknown">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 3, 'service_unhandled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Services Unknown Unhandled">
<?= $servicegroup->services_unknown_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 3, 'service_handled' => 1, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Services Unknown Handled">
<?= $servicegroup->services_unknown_handled ?>
</a>
</span>
<span class="topbar-status-pending">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 99, 'servicegroup' => $servicegroup->servicegroup)); ?>" title="Services Pending">
<?= $servicegroup->services_pending ?>
</a>
</span>
</div>
</td>
</tr>

View File

@ -1,7 +1,7 @@
<?php
$servicegroups = array();
foreach ($object->servicegroups as $name => $alias) {
$servicegroups[] = '<a href="' . $this->href('monitoring/list/service', array('servicegroup' => $name)) . '">'
$servicegroups[] = '<a href="' . $this->href('monitoring/list/services', array('servicegroup' => $name)) . '">'
. $alias
. '</a>';
}

View File

@ -1,27 +1,27 @@
<div class="nav navbar-nav topbar-host-status-summary">
<span class="topbar-status-up">
<a href="<?= $this->href('monitoring/list/hosts', array('host_severity' => 4)); ?>" title="Hosts Up">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 0)); ?>" title="Hosts Up">
<?= $hostSummary->hosts_up ?>
</a>
</span>
<span class="topbar-status-down">
<a href="<?= $this->href('monitoring/list/hosts', array('host_severity' => 36)); ?>" title="Hosts Down Unhandled">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 1, 'host_unhandled' => 1)); ?>" title="Hosts Down Unhandled">
<?= $hostSummary->hosts_down_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/hosts', array('host_severity' => array(33, 34))); ?>" title="Hosts Down Handled">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 1, 'host_handled' => 1)); ?>" title="Hosts Down Handled">
<?= $hostSummary->hosts_down_handled ?>
</a>
</span>
<span class="topbar-status-unreachable">
<a href="<?= $this->href('monitoring/list/hosts', array('host_severity' => 68)); ?>" title="Hosts Unreachable Unhandled">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 2, 'host_unhandled' => 1)); ?>" title="Hosts Unreachable Unhandled">
<?= $hostSummary->hosts_unreachable_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/hosts', array('host_severity' => array(65, 66))); ?>" title="Hosts Unreachable Handled">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 2, 'host_handled' => 1)); ?>" title="Hosts Unreachable Handled">
<?= $hostSummary->hosts_unreachable_handled ?>
</a>
</span>
<span class="topbar-status-pending">
<a href="<?= $this->href('monitoring/list/hosts', array('host_severity' => 20)); ?>" title="Hosts Pending">
<a href="<?= $this->href('monitoring/list/hosts', array('host_state' => 99)); ?>" title="Hosts Pending">
<?= $hostSummary->hosts_pending ?>
</a>
</span>
@ -29,36 +29,36 @@
<div class="nav navbar-nav topbar-service-status-summary">
<span class="topbar-status-ok">
<a href="<?= $this->href('monitoring/list/services', array('service_severity' => 4)); ?>" title="Services Ok">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 0)); ?>" title="Services Ok">
<?= $serviceSummary->services_ok ?>
</a>
</span>
<span class="topbar-status-critical">
<a href="<?= $this->href('monitoring/list/services', array('service_severity' => 132)); ?>" title="Services Critical Unhandled">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 2, 'service_unhandled' => 1)); ?>" title="Services Critical Unhandled">
<?= $serviceSummary->services_critical_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_severity' => array(129, 130))); ?>" title="Services Critical Handled">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 2, 'service_handled' => 1)); ?>" title="Services Critical Handled">
<?= $serviceSummary->services_critical_handled ?>
</a>
</span>
<span class="topbar-status-warning">
<a href="<?= $this->href('monitoring/list/services', array('service_severity' => 36)); ?>" title="Services Warning Unhandled">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 1, 'service_unhandled' => 1)); ?>" title="Services Warning Unhandled">
<?= $serviceSummary->services_warning_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_severity' => array(33, 34))); ?>" title="Services Warning Handled">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 1, 'service_handled' => 1)); ?>" title="Services Warning Handled">
<?= $serviceSummary->services_warning_handled ?>
</a>
</span>
<span class="topbar-status-unknown">
<a href="<?= $this->href('monitoring/list/services', array('service_severity' => 68)); ?>" title="Services Unknown Unhandled">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 3, 'service_unhandled' => 1)); ?>" title="Services Unknown Unhandled">
<?= $serviceSummary->services_unknown_unhandled ?>
</a>/
<a href="<?= $this->href('monitoring/list/services', array('service_severity' => array(65, 66))); ?>" title="Services Unknown Handled">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 3, 'service_handled' => 1)); ?>" title="Services Unknown Handled">
<?= $serviceSummary->services_unknown_handled ?>
</a>
</span>
<span class="topbar-status-pending">
<a href="<?= $this->href('monitoring/list/services', array('service_severity' => 20)); ?>" title="Services Pending">
<a href="<?= $this->href('monitoring/list/services', array('service_state' => 99)); ?>" title="Services Pending">
<?= $serviceSummary->services_pending ?>
</a>
</span>

View File

@ -1,144 +1,74 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
class GroupsummaryQuery extends IdoQuery
use \Zend_Db_Select;
class GroupSummaryQuery extends IdoQuery
{
protected $useSubqueryCount = true;
protected $columnMap = array(
'hoststatus' => array(
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
'cnt_hosts_up' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 0 THEN 1 ELSE 0 END)',
'cnt_hosts_unreachable' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 2 AND hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth != 0 THEN 1 ELSE 0 END)',
'cnt_hosts_unreachable_unhandled' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 2 AND hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth = 0 THEN 1 ELSE 0 END)',
'cnt_hosts_down' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 1 AND hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth != 0 THEN 1 ELSE 0 END)',
'cnt_hosts_down_unhandled' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 1 AND hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth = 0 THEN 1 ELSE 0 END)',
'cnt_hosts_pending' => 'SUM(CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 1 ELSE 0 END)'
'hoststatussummary' => array(
'hosts_up' => 'SUM(CASE WHEN object_type = \'host\' AND state = 0 THEN 1 ELSE 0 END)',
'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime != 0 THEN 1 ELSE 0 END)',
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime != 0 THEN 1 ELSE 0 END)',
'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
'hosts_pending' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 THEN 1 ELSE 0 END)',
'hostgroup' => 'hostgroup'
),
'servicestatus' => array(
'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END',
'cnt_services_ok' => 'SUM(CASE WHEN ss.has_been_checked != 0 AND ss.has_been_checked IS NOT NULL AND ss.current_state = 0 THEN 1 ELSE 0 END)',
'cnt_services_unknown' => 'SUM(CASE WHEN ss.has_been_checked != 0 AND ss.has_been_checked IS NOT NULL AND ss.current_state = 3 AND ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth != 0 THEN 1 ELSE 0 END)',
'cnt_services_unknown_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 0 AND ss.has_been_checked IS NOT NULL AND ss.current_state = 3 AND ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth = 0 THEN 1 ELSE 0 END)',
'cnt_services_critical' => 'SUM(CASE WHEN ss.has_been_checked != 0 AND ss.has_been_checked IS NOT NULL AND ss.current_state = 2 AND ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth != 0 THEN 1 ELSE 0 END)',
'cnt_services_critical_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 0 AND ss.has_been_checked IS NOT NULL AND ss.current_state = 2 AND ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth = 0 THEN 1 ELSE 0 END)',
'cnt_services_warning' => 'SUM(CASE WHEN ss.has_been_checked != 0 AND ss.has_been_checked IS NOT NULL AND ss.current_state = 1 AND ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth != 0 THEN 1 ELSE 0 END)',
'cnt_services_warning_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 0 AND ss.has_been_checked IS NOT NULL AND ss.current_state = 1 AND ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth = 0 THEN 1 ELSE 0 END)',
'cnt_services_pending' => 'SUM(CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 1 ELSE 0 END)'
),
'hostgroups' => array(
'hostgroup_name' => 'hgo.name1 COLLATE latin1_general_ci'
),
'servicegroups' => array(
'servicegroup_name' => 'sgo.name1 COLLATE latin1_general_ci'
'servicestatussummary' => array(
'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)',
'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)',
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) = 0 THEN 1 ELSE 0 END)',
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) = 0 THEN 1 ELSE 0 END)',
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) = 0 THEN 1 ELSE 0 END)',
'servicegroup' => 'servicegroup'
)
);
protected function joinBaseTables()
{
$this->baseQuery = $this->db->select()->from(
array('ho' => $this->prefix . 'objects'),
array()
)->join(
array('hs' => $this->prefix . 'hoststatus'),
'ho.object_id = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
)->join(
array('h' => $this->prefix . 'hosts'),
'hs.host_object_id = h.host_object_id',
array()
$columns = array(
'object_type',
'host_state',
'host_name'
);
$this->joinedVirtualTables = array(
'hosts' => true,
'hoststatus' => true
);
}
protected function joinServiceStatus()
{
$this->requireVirtualTable('services');
}
protected function joinServices()
{
$this->baseQuery->join(
array('s' => $this->prefix . 'services'),
's.host_object_id = h.host_object_id',
array()
)->join(
array('so' => $this->prefix . 'objects'),
'so.' . $this->object_id . ' = s.service_object_id AND so.is_active = 1',
array()
)->joinLeft(
array('ss' => $this->prefix . 'servicestatus'),
'so.' . $this->object_id . ' = ss.service_object_id',
array()
);
}
protected function joinHostgroups()
{
if (in_array('servicegroup_name', $this->getColumns())) {
return $this->joinServiceHostgroups();
// Prepend group column since we'll use columns index 0 later for grouping
if (in_array('servicegroup', $this->getColumns())) {
array_unshift($columns, 'servicegroup');
} else {
return $this->joinHostHostgroups();
array_unshift($columns, 'hostgroup');
}
}
protected function joinHostHostgroups()
{
$this->baseQuery->join(
array('hgm' => $this->prefix . 'hostgroup_members'),
'hgm.host_object_id = h.host_object_id',
array()
)->join(
array('hg' => $this->prefix . 'hostgroups'),
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
array()
)->join(
array('hgo' => $this->prefix . 'objects'),
'hgo.' . $this->object_id . ' = hg.hostgroup_object_id AND hgo.is_active = 1',
array()
);
$this->baseQuery->group('hgo.name1');
return $this;
}
protected function joinServiceHostgroups()
{
$this->baseQuery->join(
array('hgm' => $this->prefix . 'hostgroup_members'),
'hgm.host_object_id = s.host_object_id',
array()
)->join(
array('hg' => $this->prefix . 'hostgroups'),
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
array()
)->join(
array('hgo' => $this->prefix . 'objects'),
'hgo.' . $this->object_id . ' = hg.hostgroup_object_id AND hgo.is_active = 1',
array()
$hosts = $this->createSubQuery(
'Hoststatus',
$columns + array(
'state' => 'host_state',
'acknowledged' => 'host_acknowledged',
'in_downtime' => 'host_in_downtime'
)
);
return $this;
}
protected function joinServicegroups()
{
$this->requireVirtualTable('services');
$this->baseQuery->join(
array('sgm' => $this->prefix . 'servicegroup_members'),
'sgm.service_object_id = s.service_object_id',
array()
)->join(
array('sg' => $this->prefix . 'servicegroups'),
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
array()
)->join(
array('sgo' => $this->prefix . 'objects'),
'sgo.' . $this->object_id. ' = sg.servicegroup_object_id AND sgo.is_active = 1',
array()
$services = $this->createSubQuery(
'Status',
$columns + array(
'state' => 'service_state',
'acknowledged' => 'service_acknowledged',
'in_downtime' => 'service_in_downtime'
)
);
$union = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
$this->baseQuery = $this->db->select()->from(array('statussummary' => $union), array())->group($columns[0]);
$this->joinedVirtualTables = array(
'servicestatussummary' => true,
'hoststatussummary' => true
);
$this->baseQuery->group('sgo.name1');
return $this;
}
}
// @codingStandardsIgnoreStop

View File

@ -28,53 +28,51 @@
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
/**
*
*/
class HoststatusQuery extends IdoQuery
{
protected $allowCustomVars = true;
protected $columnMap = array(
'hosts' => array(
'host' => 'ho.name1 COLLATE latin1_general_ci',
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
'host' => 'ho.name1 COLLATE latin1_general_ci',
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
'host_display_name' => 'h.display_name',
'host_alias' => 'h.alias',
'host_address' => 'h.address',
'host_ipv4' => 'INET_ATON(h.address)',
'host_icon_image' => 'h.icon_image',
'hosts_up' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 0 THEN 1 ELSE 0 END)',
'hosts_unreachable_handled' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 2 AND hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth != 0 THEN 1 ELSE 0 END)',
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 2 AND hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth = 0 THEN 1 ELSE 0 END)',
'hosts_down_handled' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 1 AND hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth != 0 THEN 1 ELSE 0 END)',
'hosts_down_unhandled' => 'SUM(CASE WHEN hs.has_been_checked != 0 AND hs.has_been_checked IS NOT NULL AND hs.current_state = 1 AND hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth = 0 THEN 1 ELSE 0 END)',
'hosts_pending' => 'SUM(CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 1 ELSE 0 END)'
'host_alias' => 'h.alias',
'host_address' => 'h.address',
'host_ipv4' => 'INET_ATON(h.address)',
'host_icon_image' => 'h.icon_image',
'object_type' => '(\'host\')'
),
'hoststatus' => array(
'problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
'handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
'unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END',
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
'host_output' => 'hs.output',
'host_long_output' => 'hs.long_output',
'host_perfdata' => 'hs.perfdata',
'host_problem' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
'host_acknowledged' => 'hs.problem_has_been_acknowledged',
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
'host_does_active_checks' => 'hs.active_checks_enabled',
'host_accepts_passive_checks' => 'hs.passive_checks_enabled',
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
'host_last_hard_state' => 'hs.last_hard_state',
'host_check_command' => 'hs.check_command',
'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)',
'host_next_check' => 'CASE WHEN hs.should_be_scheduled THEN UNIX_TIMESTAMP(hs.next_check) ELSE NULL END',
'host_check_execution_time' => 'hs.execution_time',
'host_check_latency' => 'hs.latency',
'host_notifications_enabled' => 'hs.notifications_enabled',
'host_last_time_up' => 'hs.last_time_up',
'host_last_time_down' => 'hs.last_time_down',
'host_last_time_unreachable' => 'hs.last_time_unreachable',
'host_current_check_attempt' => 'hs.current_check_attempt',
'host_max_check_attempts' => 'hs.max_check_attempts',
'host_severity' => 'CASE WHEN hs.current_state = 0
'problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
'handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
'unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END',
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
'host_output' => 'hs.output',
'host_long_output' => 'hs.long_output',
'host_perfdata' => 'hs.perfdata',
'host_problem' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
'host_acknowledged' => 'hs.problem_has_been_acknowledged',
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
'host_does_active_checks' => 'hs.active_checks_enabled',
'host_accepts_passive_checks' => 'hs.passive_checks_enabled',
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
'host_last_hard_state' => 'hs.last_hard_state',
'host_check_command' => 'hs.check_command',
'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)',
'host_next_check' => 'CASE WHEN hs.should_be_scheduled THEN UNIX_TIMESTAMP(hs.next_check) ELSE NULL END',
'host_check_execution_time' => 'hs.execution_time',
'host_check_latency' => 'hs.latency',
'host_notifications_enabled' => 'hs.notifications_enabled',
'host_last_time_up' => 'hs.last_time_up',
'host_last_time_down' => 'hs.last_time_down',
'host_last_time_unreachable' => 'hs.last_time_unreachable',
'host_current_check_attempt' => 'hs.current_check_attempt',
'host_max_check_attempts' => 'hs.max_check_attempts',
'host_severity' => 'CASE WHEN hs.current_state = 0
THEN
CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL
THEN 16
@ -104,16 +102,19 @@ class HoststatusQuery extends IdoQuery
ELSE 4
END
END
END',
END'
),
'hostgroups' => array(
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
),
'servicegroups' => array(
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
),
'contactgroups' => array(
'contactgroup' => 'contactgroup',
'contactgroup' => 'contactgroup',
),
'contacts' => array(
'contact' => 'hco.name1 COLLATE latin1_general_ci',
'contact' => 'hco.name1 COLLATE latin1_general_ci',
),
'services' => array(
'services_cnt' => 'SUM(1)',
@ -125,12 +126,12 @@ class HoststatusQuery extends IdoQuery
'services_problem' => 'SUM(CASE WHEN ss.current_state > 0 THEN 1 ELSE 0 END)',
'services_problem_handled' => 'SUM(CASE WHEN ss.current_state > 0 AND (ss.problem_has_been_acknowledged = 1 OR ss.scheduled_downtime_depth > 0) THEN 1 ELSE 0 END)',
'services_problem_unhandled' => 'SUM(CASE WHEN ss.current_state > 0 AND (ss.problem_has_been_acknowledged = 0 AND ss.scheduled_downtime_depth = 0) THEN 1 ELSE 0 END)',
'services_warning_handled' => 'SUM(CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged = 1 OR ss.scheduled_downtime_depth > 0) THEN 1 ELSE 0 END)',
'services_critical_handled' => 'SUM(CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged = 1 OR ss.scheduled_downtime_depth > 0) THEN 1 ELSE 0 END)',
'services_unknown_handled' => 'SUM(CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged = 1 OR ss.scheduled_downtime_depth > 0) THEN 1 ELSE 0 END)',
'services_warning_unhandled' => 'SUM(CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged = 0 AND ss.scheduled_downtime_depth = 0) THEN 1 ELSE 0 END)',
'services_critical_unhandled' => 'SUM(CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged = 0 AND ss.scheduled_downtime_depth = 0) THEN 1 ELSE 0 END)',
'services_unknown_unhandled' => 'SUM(CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged = 0 AND ss.scheduled_downtime_depth = 0) THEN 1 ELSE 0 END)',
'services_warning_handled' => 'SUM(CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_critical_handled' => 'SUM(CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_unknown_handled' => 'SUM(CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_warning_unhandled' => 'SUM(CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)',
'services_critical_unhandled' => 'SUM(CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)',
'services_unknown_unhandled' => 'SUM(CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)',
),
);
protected $aggregateColumnIdx = array(

View File

@ -0,0 +1,85 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use \Zend_Db_Select;
class StatusSummaryQuery extends IdoQuery
{
protected $columnMap = array(
'hoststatussummary' => array(
'hosts_up' => 'SUM(CASE WHEN object_type = \'host\' AND state = 0 THEN 1 ELSE 0 END)',
'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime != 0 THEN 1 ELSE 0 END)',
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime != 0 THEN 1 ELSE 0 END)',
'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
'hosts_pending' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 THEN 1 ELSE 0 END)'
),
'servicestatussummary' => array(
'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)',
'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)',
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) > 0 THEN 1 ELSE 0 END)',
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) = 0 THEN 1 ELSE 0 END)',
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) = 0 THEN 1 ELSE 0 END)',
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND (acknowledged + in_downtime + COALESCE(host_state, 0)) = 0 THEN 1 ELSE 0 END)'
)
);
protected function joinBaseTables()
{
$hosts = $this->db->select()->from(
array('ho' => $this->prefix . 'objects'),
array()
)->join(
array('hs' => $this->prefix . 'hoststatus'),
'ho.object_id = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array(
''
)
)->join(
array('h' => $this->prefix . 'hosts'),
'hs.host_object_id = h.host_object_id',
array()
);
$services = clone $hosts;
$services->join(
array('s' => $this->prefix . 'services'),
's.host_object_id = h.host_object_id',
array()
)->join(
array('so' => $this->prefix . 'objects'),
'so.' . $this->object_id . ' = s.service_object_id AND so.is_active = 1',
array()
)->joinLeft(
array('ss' => $this->prefix . 'servicestatus'),
'so.' . $this->object_id . ' = ss.service_object_id',
array()
);
$hosts->columns(array(
'state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
'acknowledged' => 'hs.problem_has_been_acknowledged',
'in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
'object_type' => '(\'host\')'
));
$services->columns(array(
'state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END',
'acknowledged' => 'ss.problem_has_been_acknowledged',
'in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
'object_type' => '(\'service\')'
));
$union = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
$this->baseQuery = $this->db->select()->from(array('statussummary' => $union), array());
$this->joinedVirtualTables = array(
'servicestatussummary' => true,
'hoststatussummary' => true
);
}
}
// @codingStandardsIgnoreStop

View File

@ -5,25 +5,25 @@ namespace Icinga\Module\Monitoring\Backend\Statusdat\Query;
class GroupsummaryQuery extends StatusdatQuery
{
public static $mappedParameters = array(
'hostgroup_name' => 'hostgroup_name',
'servicegroup_name' => 'servicegroup_name'
'hostgroup' => 'hostgroup_name',
'servicegroup' => 'servicegroup_name'
);
public static $handlerParameters = array(
'cnt_hosts_up' => 'getHostUpSum',
'cnt_hosts_unreachable' => 'getHostUnreachableSum',
'cnt_hosts_unreachable_unhandled' => 'getHostUnreachableUnhandledSum',
'cnt_hosts_down' => 'getHostDownSum',
'cnt_hosts_down_unhandled' => 'getHostDownUnhandledSum',
'cnt_hosts_pending' => 'getHostPendingSum',
'cnt_services_ok' => 'getServiceOkSum',
'cnt_services_unknown' => 'getServiceUnknownSum',
'cnt_services_unknown_unhandled' => 'getServiceUnknownUnhandledSum',
'cnt_services_critical' => 'getServiceCriticalSum',
'cnt_services_critical_unhandled' => 'getServiceCriticalUnhandledSum',
'cnt_services_warning' => 'getServiceWarningSum',
'cnt_services_warning_unhandled' => 'getServiceWarningUnhandledSum',
'cnt_services_pending' => 'getServicePendingSum',
'hosts_up' => 'getHostUpSum',
'hosts_unreachable_handled' => 'getHostUnreachableSum',
'hosts_unreachable_unhandled' => 'getHostUnreachableUnhandledSum',
'hosts_down_handled' => 'getHostDownSum',
'hosts_down_unhandled' => 'getHostDownUnhandledSum',
'hosts_pending' => 'getHostPendingSum',
'services_ok' => 'getServiceOkSum',
'services_unknown_handled' => 'getServiceUnknownSum',
'services_unknown_unhandled' => 'getServiceUnknownUnhandledSum',
'services_critical_handled' => 'getServiceCriticalSum',
'services_critical_unhandled' => 'getServiceCriticalUnhandledSum',
'services_warning_handled' => 'getServiceWarningSum',
'services_warning_unhandled' => 'getServiceWarningUnhandledSum',
'services_pending' => 'getServicePendingSum',
);
@ -233,10 +233,10 @@ class GroupsummaryQuery extends StatusdatQuery
private function getTarget()
{
if (in_array('servicegroup_name', $this->getColumns())) {
if (in_array('servicegroup', $this->getColumns())) {
return 'servicegroups';
}
return "hostgroups";
return 'hostgroups';
}
public function selectBase()

View File

@ -122,8 +122,8 @@ class StatusQuery extends StatusdatQuery
'service_retry_check_interval' => 'service.status.retry_check_interval',
'service_check_timeperiod_object_id' => 'service.status.check_timeperiod_object_id',
'service_status_update_time' => 'service.status.status_update_time',
'hostgroups' => 'host.group',
'servicegroups' => 'service.group'
'hostgroup' => 'host.group',
'servicegroup' => 'service.group'
);
/**

View File

@ -0,0 +1,115 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Backend\Statusdat\Query;
class StatusSummaryQuery extends StatusdatQuery
{
public function selectBase()
{
$this->select()->from('hosts', array())->groupByFunction(
'groupByStatus',
$this
);
}
public function groupByStatus(&$indices)
{
$hostsPending = 0;
$hostsUp = 0;
$hostsDownHandled = 0;
$hostsDownUnhandled = 0;
$hostsUnreachableHandled = 0;
$hostsUnreachableUnhandled = 0;
$servicesPending = 0;
$servicesOk = 0;
$servicesCriticalHandled = 0;
$servicesCriticalUnhandled = 0;
$servicesWarningHandled = 0;
$servicesWarningUnhandled = 0;
$servicesUnknownHandled = 0;
$servicesUnknownUnhandled = 0;
foreach ($indices['host'] as $hostName) {
$host = $this->ds->getObjectByName('host', $hostName);
$hostStatus = $host->status;
if ($hostStatus->has_been_checked !== '1') {
++$hostsPending;
} elseif ($hostStatus->current_state === '0') {
++$hostsUp;
} elseif ($hostStatus->current_state === '2') {
if ($hostStatus->problem_has_been_acknowledged === '1'
|| $hostStatus->scheduled_downtime_depth === '1'
) {
++$hostsDownHandled;
} else {
++$hostsDownUnhandled;
}
} elseif ($hostStatus->current_state === '1') {
if ($hostStatus->problem_has_been_acknowledged === '1'
|| $hostStatus->scheduled_downtime_depth === '1'
) {
++$hostsUnreachableHandled;
} else {
++$hostsUnreachableUnhandled;
}
}
if ($host->services === null) {
// Host does not have any service associated
continue;
}
foreach ($host->services as $service) {
$serviceStatus = $service->status;
if ($serviceStatus->has_been_checked !== '1') {
++$servicesPending;
} elseif ($serviceStatus->current_state === '0') {
++$servicesOk;
} elseif ($serviceStatus->current_state === '2') {
if ($serviceStatus->problem_has_been_acknowledged === '1'
|| $serviceStatus->scheduled_downtime_depth === '1'
|| $hostStatus->current_state !== '0'
) {
++$servicesCriticalHandled;
} else {
++$servicesCriticalUnhandled;
}
} elseif ($serviceStatus->current_state === '1') {
if ($serviceStatus->problem_has_been_acknowledged === '1'
|| $serviceStatus->scheduled_downtime_depth === '1'
|| $hostStatus->current_state !== '0'
) {
++$servicesWarningHandled;
} else {
++$servicesWarningUnhandled;
}
} elseif ($serviceStatus->current_state === '3') {
if ($serviceStatus->problem_has_been_acknowledged === '1'
|| $serviceStatus->scheduled_downtime_depth === '1'
|| $hostStatus->current_state !== '0'
) {
++$servicesUnknownHandled;
} else {
++$servicesUnknownUnhandled;
}
}
}
}
$rs = array(
'hosts_up' => $hostsUp,
'hosts_unreachable_handled' => $hostsUnreachableHandled,
'hosts_unreachable_unhandled' => $hostsUnreachableUnhandled,
'hosts_down_handled' => $hostsDownHandled,
'hosts_down_unhandled' => $hostsDownUnhandled,
'hosts_pending' => $hostsPending,
'services_ok' => $servicesOk,
'services_unknown_handled' => $servicesUnknownHandled,
'services_unknown_unhandled' => $servicesUnknownUnhandled,
'services_critical_handled' => $servicesCriticalHandled,
'services_critical_unhandled' => $servicesCriticalUnhandled,
'services_warning_handled' => $servicesWarningHandled,
'services_warning_unhandled' => $servicesWarningUnhandled,
'services_pending' => $servicesPending
);
return array((object) array_intersect_key($rs, array_flip($this->getColumns())));
}
}

View File

@ -14,36 +14,36 @@ class Groupsummary extends DataView
public function getColumns()
{
return array(
'servicegroup_name',
'hostgroup_name',
'cnt_hosts_up',
'cnt_hosts_unreachable',
'cnt_hosts_unreachable_unhandled',
'cnt_hosts_down',
'cnt_hosts_down_unhandled',
'cnt_hosts_pending',
'cnt_services_ok',
'cnt_services_unknown',
'cnt_services_unknown_unhandled',
'cnt_services_critical',
'cnt_services_critical_unhandled',
'cnt_services_warning',
'cnt_services_warning_unhandled',
'cnt_services_pending'
'servicegroup',
'hostgroup',
'hosts_up',
'hosts_unreachable_handled',
'hosts_unreachable_unhandled',
'hosts_down_handled',
'hosts_down_unhandled',
'hosts_pending',
'services_ok',
'services_unknown_handled',
'services_unknown_unhandled',
'services_critical_handled',
'services_critical_unhandled',
'services_warning_handled',
'services_warning_unhandled',
'services_pending'
);
}
public function getSortRules()
{
if (in_array('servicegroup_name', $this->getQuery()->getColumns())) {
if (in_array('servicegroup', $this->getQuery()->getColumns())) {
return array(
'servicegroup_name' => array(
'servicegroup' => array(
'order' => self::SORT_ASC
)
);
}
return array(
'hostgroup_name' => array(
'hostgroup' => array(
'order' => self::SORT_ASC
)
);

View File

@ -30,9 +30,4 @@ class StatusSummary extends DataView
'services_pending'
);
}
public static function getTableName()
{
return 'hoststatus';
}
}