monitoring: Support restricting service groups of a service

refs #9009
This commit is contained in:
Eric Lippmann 2015-06-05 14:42:49 +02:00
parent bbcd6e3a2b
commit 80c80436cf
2 changed files with 119 additions and 32 deletions

View File

@ -5,21 +5,43 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
class ServicegroupQuery extends IdoQuery
{
/**
* {@inheritdoc}
*/
protected $allowCustomVars = true;
/**
* {@inheritdoc}
*/
protected $columnMap = array(
'hostgroups' => array(
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
'hostgroup_name' => 'hgo.name1'
),
'hosts' => array(
'host_alias' => 'h.alias',
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
),
'servicegroups' => array(
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
'servicegroup_name' => 'sgo.name1',
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci',
'servicegroup_name' => 'sgo.name1'
),
'serviceobjects' => array(
'host' => 'so.name1 COLLATE latin1_general_ci',
'host_name' => 'so.name1',
'service' => 'so.name2 COLLATE latin1_general_ci',
'service_description' => 'so.name2'
),
'services' => array(
'host' => 'so.name1 COLLATE latin1_general_ci',
'host_name' => 'so.name1',
'service' => 'so.name2 COLLATE latin1_general_ci',
'service_host_name' => 'so.name1',
'service_description' => 'so.name2'
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
)
);
/**
* {@inheritdoc}
*/
protected function joinBaseTables()
{
$this->select->from(
@ -27,15 +49,64 @@ class ServicegroupQuery extends IdoQuery
array()
)->join(
array('sgo' => $this->prefix . 'objects'),
'sg.servicegroup_object_id = sgo.' . $this->object_id
. ' AND sgo.is_active = 1',
'sg.servicegroup_object_id = sgo.object_id',
array()
)->where(
'sgo.is_active = ?',
1
)
->where(
'sgo.objecttype_id = ?',
4
);
$this->joinedVirtualTables = array('servicegroups' => true);
}
protected function joinServices()
/**
* Join host groups
*/
protected function joinHostgroups()
{
$this->requireVirtualTable('services');
$this->select->join(
array('hgm' => $this->prefix . 'hostgroup_members'),
'hgm.host_object_id = s.host_object_id',
array()
)->join(
array('hg' => $this->prefix . 'hostgroups'),
'hg.hostgroup_id = hgm.hostgroup_id',
array()
)->join(
array('hgo' => $this->prefix . 'objects'),
'hgo.object_id = hg.hostgroup_object_id',
array()
)->where(
'hgo.is_active = ?',
1
)
->where(
'hgo.objecttype_id = ?',
3
);
}
/**
* Join hosts
*/
protected function joinHosts()
{
$this->requireVirtualTable('services');
$this->select->join(
array('h' => $this->prefix . 'hosts'),
'h.host_object_id = s.host_object_id',
array()
);
}
/**
* Join service objects
*/
protected function joinServiceobjects()
{
$this->select->join(
array('sgm' => $this->prefix . 'servicegroup_members'),
@ -43,7 +114,21 @@ class ServicegroupQuery extends IdoQuery
array()
)->join(
array('so' => $this->prefix . 'objects'),
'sgm.service_object_id = so.' . $this->object_id . ' AND so.is_active = 1',
'sgm.service_object_id = so.object_id',
array()
);
$this->group('sgo.name1');
}
/**
* Join services
*/
protected function joinServices()
{
$this->requireVirtualTable('serviceobjects');
$this->select->join(
array('s' => $this->prefix . 'services'),
's.service_object_id = so.object_id',
array()
);
}

View File

@ -3,43 +3,45 @@
namespace Icinga\Module\Monitoring\DataView;
/**
* Service group view */
class Servicegroup extends DataView
{
/**
* Retrieve columns provided by this view
*
* @return array
* {@inheritdoc}
*/
public function getColumns()
{
return array(
'servicegroup_name',
'servicegroup_alias',
'host_name',
'service_host_name',
'service_description'
'servicegroup_name'
);
}
/**
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
*
* @return array
* {@inheritdoc}
*/
public function getSortRules()
public function getFilterColumns()
{
return array(
'servicegroup_name' => array(
'order' => self::SORT_ASC
),
'servicegroup_alias' => array(
'order' => self::SORT_ASC
)
'host', 'host_alias', 'host_display_name', 'host_name',
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
'service', 'service_description', 'service_display_name',
'servicegroup'
);
}
public function getFilterColumns()
/**
* {@inheritdoc}
*/
public function isValidFilterTarget($column)
{
return array('servicegroup', 'host', 'service');
if ($column[0] === '_'
&& preg_match('/^_(?:host|service)_/', $column)
) {
return true;
} else {
return parent::isValidFilterTarget($column);
}
}
}