monitoring: Remove ServicestatusQuery::getGroup()

refs #9956
This commit is contained in:
Eric Lippmann 2015-09-29 22:46:02 +02:00
parent d0f11e10f6
commit 6307af9e10
1 changed files with 23 additions and 62 deletions

View File

@ -3,8 +3,6 @@
namespace Icinga\Module\Monitoring\Backend\Ido\Query; namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Zend_Db_Expr;
/** /**
* Query for service status * Query for service status
*/ */
@ -15,6 +13,16 @@ class ServicestatusQuery extends IdoQuery
*/ */
protected $allowCustomVars = true; protected $allowCustomVars = true;
/**
* {@inheritdoc}
*/
protected $groupBase = array('services' => array('so.object_id', 's.service_id'));
/**
* {@inheritdoc}
*/
protected $groupOrigin = array('hostgroups', 'servicegroups');
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -401,69 +409,22 @@ class ServicestatusQuery extends IdoQuery
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getGroup() protected function handleGroupColumn($column, &$groupColumns, &$groupedTables)
{ {
$group = parent::getGroup() ?: array(); switch ($column) {
if (! is_array($group)) { case 'service_handled':
$group = array($group); case 'service_severity':
case 'service_unhandled':
if (! isset($groupedTables['hoststatus'])) {
$groupColumns[] = 'hs.hoststatus_id';
$groupedTables['hoststatus'] = true;
} }
$groupedTables = array(); if (! isset($groupedTables['servicestatus'])) {
if ($this->hasJoinedVirtualTable('servicegroups')) { $groupColumns[] = 'ss.servicestatus_id';
$group[] = 'so.object_id'; $groupedTables['servicestatus'] = true;
$group[] = 's.service_id'; }
$groupedTables['services'] = true; return true;
$serviceGroupColumns = array_keys($this->columnMap['servicegroups']); }
$selectedServiceGroupColumns = array_intersect($serviceGroupColumns, array_keys($this->columns)); return false;
if (! empty($selectedServiceGroupColumns)) {
$group[] = 'sgo.object_id';
$group[] = 'sg.servicegroup_id';
$groupedTables['servicegroups'] = true;
}
}
if ($this->hasJoinedVirtualTable('hostgroups')) {
if (! isset($groupedTables['services'])) {
$group[] = 'so.object_id';
$group[] = 's.service_id';
$groupedTables['services'] = true;
}
$hostGroupColumns = array_keys($this->columnMap['hostgroups']);
$selectedHostGroupColumns = array_intersect($hostGroupColumns, array_keys($this->columns));
if (! empty($selectedHostGroupColumns)) {
$group[] = 'hgo.object_id';
$group[] = 'hg.hostgroup_id';
$groupedTables['hostgroups'] = true;
}
}
if (! empty($groupedTables)) {
foreach ($this->columns as $alias => $column) {
if ($column instanceof Zend_Db_Expr || $column === '(NULL)') {
continue;
}
$tableName = $this->aliasToTableName(
$this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias)
);
if (isset($groupedTables[$tableName])) {
continue;
}
switch ($tableName) {
case 'hosts':
$group[] = 'h.host_id';
break;
case 'hoststatus':
$group[] = 'hs.hoststatus_id';
break;
case 'instances':
$group[] = 'i.instance_id';
break;
case 'servicestatus':
$group[] = 'ss.servicestatus_id';
break;
default:
continue 2;
}
$groupedTables[$tableName] = true;
}
}
return $group;
} }
} }