Add yet hidden servicegroup summary w/ servicegroup overview rendered to detail

refs #4185
refs #4183
This commit is contained in:
Eric Lippmann 2013-10-15 12:49:58 +02:00
parent 8e2549febe
commit 1f571589de
4 changed files with 252 additions and 0 deletions

View File

@ -46,6 +46,7 @@ use Icinga\Module\Monitoring\DataView\Contact as ContactView;
use Icinga\Module\Monitoring\DataView\Contactgroup as ContactgroupView;
use Icinga\Module\Monitoring\DataView\HostAndServiceStatus as HostAndServiceStatusView;
use Icinga\Module\Monitoring\DataView\Comment as CommentView;
use Icinga\Module\Monitoring\DataView\Groupsummary as GroupsummaryView;
class Monitoring_ListController extends MonitoringController
{
@ -307,6 +308,32 @@ class Monitoring_ListController extends MonitoringController
$this->handleFormatRequest($query);
}
public function servicegroupsAction()
{
$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'
)
)->getQuery();
$this->view->servicegroups = $query->paginate();
$this->handleFormatRequest($query);
}
/**
* Handle the 'format' and 'view' parameter
*

View File

@ -0,0 +1,34 @@
<div data-icinga-component="app/mainDetailGrid">
<?= $this->paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?>
<table class="table table-condensed">
<tbody>
<?php foreach($servicegroups as $servicegroup): ?>
<tr>
<td>
<a href="<?= $this->href('monitoring/list/services', array('servicegroups' => $servicegroup->servicegroup_name)); ?>">
<?= $servicegroup->servicegroup_name; ?>
</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>
</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>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?= $this->paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?>
</div>

View File

@ -0,0 +1,144 @@
<?php
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
class GroupsummaryQuery extends AbstractQuery
{
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)'
),
'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'
)
);
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()
);
$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 ($this->hasJoinedVirtualTable('services')) {
return $this->joinServiceHostgroups();
} else {
return $this->joinHostHostgroups();
}
}
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()
);
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()
);
$this->baseQuery->group('sgo.name1');
return $this;
}
}

View File

@ -0,0 +1,47 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\DataView;
class Groupsummary extends DataView
{
/**
* Retrieve columns provided by this view
*
* @return array
*/
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'
);
}
public function getSortRules()
{
return array(
'servicegroup_name' => array(
'order' => self::SORT_DESC
),
'hostgroup_name' => array(
'order' => self::SORT_DESC
)
);
}
}