mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 09:14:08 +02:00
parent
c735ee799c
commit
bbcd6e3a2b
@ -3,21 +3,49 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query for host groups
|
||||||
|
*/
|
||||||
class HostgroupQuery extends IdoQuery
|
class HostgroupQuery extends IdoQuery
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $allowCustomVars = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected $columnMap = array(
|
protected $columnMap = array(
|
||||||
'hostgroups' => array(
|
'hostgroups' => array(
|
||||||
'hostgroups' => 'hgo.name1 COLLATE latin1_general_ci',
|
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||||
'hostgroup_name' => 'hgo.name1',
|
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||||
'hostgroup_alias' => 'hg.alias',
|
'hostgroup_name' => 'hgo.name1'
|
||||||
'hostgroup_id' => 'hg.hostgroup_id'
|
),
|
||||||
|
'hostobjects' => array(
|
||||||
|
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||||
|
'host_name' => 'ho.name1'
|
||||||
),
|
),
|
||||||
'hosts' => array(
|
'hosts' => array(
|
||||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
'host_alias' => 'h.alias',
|
||||||
'host_name' => 'ho.name1'
|
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
|
||||||
|
),
|
||||||
|
'servicegroups' => array(
|
||||||
|
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||||
|
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci',
|
||||||
|
'servicegroup_name' => 'sgo.name1'
|
||||||
|
),
|
||||||
|
'services' => array(
|
||||||
|
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||||
|
'service_description' => 'so.name2',
|
||||||
|
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
@ -25,13 +53,23 @@ class HostgroupQuery extends IdoQuery
|
|||||||
array()
|
array()
|
||||||
)->join(
|
)->join(
|
||||||
array('hgo' => $this->prefix . 'objects'),
|
array('hgo' => $this->prefix . 'objects'),
|
||||||
'hg.hostgroup_object_id = hgo.' . $this->object_id . ' AND hgo.is_active = 1',
|
'hgo.object_id = hg.hostgroup_object_id',
|
||||||
array()
|
array()
|
||||||
|
)->where(
|
||||||
|
'hgo.is_active = ?',
|
||||||
|
1
|
||||||
|
)
|
||||||
|
->where(
|
||||||
|
'hgo.objecttype_id = ?',
|
||||||
|
3
|
||||||
);
|
);
|
||||||
$this->joinedVirtualTables = array('hostgroups' => true);
|
$this->joinedVirtualTables['hostgroups'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function joinHosts()
|
/**
|
||||||
|
* Join host objects
|
||||||
|
*/
|
||||||
|
protected function joinHostobjects()
|
||||||
{
|
{
|
||||||
$this->select->join(
|
$this->select->join(
|
||||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||||
@ -39,8 +77,82 @@ class HostgroupQuery extends IdoQuery
|
|||||||
array()
|
array()
|
||||||
)->join(
|
)->join(
|
||||||
array('ho' => $this->prefix . 'objects'),
|
array('ho' => $this->prefix . 'objects'),
|
||||||
'hgm.host_object_id = ho.object_id AND ho.is_active = 1',
|
'hgm.host_object_id = ho.object_id',
|
||||||
|
array()
|
||||||
|
)->where(
|
||||||
|
'ho.is_active = ?',
|
||||||
|
1
|
||||||
|
)
|
||||||
|
->where(
|
||||||
|
'ho.objecttype_id = ?',
|
||||||
|
1
|
||||||
|
);
|
||||||
|
$this->group('hgo.name1');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join hosts
|
||||||
|
*/
|
||||||
|
protected function joinHosts()
|
||||||
|
{
|
||||||
|
$this->requireVirtualTable('hostobjects');
|
||||||
|
$this->select->join(
|
||||||
|
array('h' => $this->prefix . 'hosts'),
|
||||||
|
'h.host_object_id = ho.object_id',
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join service groups
|
||||||
|
*/
|
||||||
|
protected function joinServicegroups()
|
||||||
|
{
|
||||||
|
$this->requireVirtualTable('services');
|
||||||
|
$this->select->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.object_id = sg.servicegroup_object_id',
|
||||||
|
array()
|
||||||
|
)->where(
|
||||||
|
'sgo.is_active = ?',
|
||||||
|
1
|
||||||
|
)
|
||||||
|
->where(
|
||||||
|
'sgo.objecttype_id = ?',
|
||||||
|
4
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join services
|
||||||
|
*/
|
||||||
|
protected function joinServices()
|
||||||
|
{
|
||||||
|
$this->requireVirtualTable('hosts');
|
||||||
|
$this->select->join(
|
||||||
|
array('s' => $this->prefix . 'services'),
|
||||||
|
's.host_object_id = h.host_object_id',
|
||||||
|
array()
|
||||||
|
)->join(
|
||||||
|
array('so' => $this->prefix . 'objects'),
|
||||||
|
'so.object_id = s.service_object_id AND so.is_active = 1',
|
||||||
|
array()
|
||||||
|
)->where(
|
||||||
|
'so.is_active = ?',
|
||||||
|
1
|
||||||
|
)
|
||||||
|
->where(
|
||||||
|
'so.objecttype_id = ?',
|
||||||
|
2
|
||||||
|
);
|
||||||
|
$this->group('hgo.name1');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,44 +4,45 @@
|
|||||||
namespace Icinga\Module\Monitoring\DataView;
|
namespace Icinga\Module\Monitoring\DataView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View for hostgroups
|
* Host group data view
|
||||||
*/
|
*/
|
||||||
class Hostgroup extends DataView
|
class Hostgroup extends DataView
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Retrieve columns provided by this view
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function getColumns()
|
public function getColumns()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'hostgroup_name',
|
|
||||||
'hostgroup_alias',
|
'hostgroup_alias',
|
||||||
'hostgroup_id',
|
'hostgroup_name'
|
||||||
'host_name'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function getSortRules()
|
public function getFilterColumns()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'hostgroup_name' => array(
|
'host', 'host_alias', 'host_display_name', 'host_name',
|
||||||
'order' => self::SORT_ASC
|
'hostgroup',
|
||||||
),
|
'service', 'service_description', 'service_display_name',
|
||||||
'hostgroup_alias' => array(
|
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||||
'order' => self::SORT_ASC
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilterColumns()
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function isValidFilterTarget($column)
|
||||||
{
|
{
|
||||||
return array('hostgroup', 'host');
|
if ($column[0] === '_'
|
||||||
|
&& preg_match('/^_(?:host|service)_/', $column)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return parent::isValidFilterTarget($column);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user