diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php index d41a9e00b..a9b8ec815 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php @@ -3,21 +3,49 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +/** + * Query for host groups + */ class HostgroupQuery extends IdoQuery { + /** + * {@inheritdoc} + */ + protected $allowCustomVars = true; + + /** + * {@inheritdoc} + */ protected $columnMap = array( 'hostgroups' => array( - 'hostgroups' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1', - 'hostgroup_alias' => 'hg.alias', - 'hostgroup_id' => 'hg.hostgroup_id' + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hostobjects' => array( + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1' ), 'hosts' => array( - 'host' => 'ho.name1 COLLATE latin1_general_ci', - 'host_name' => 'ho.name1' + 'host_alias' => 'h.alias', + '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() { $this->select->from( @@ -25,13 +53,23 @@ class HostgroupQuery extends IdoQuery array() )->join( 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() + )->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( array('hgm' => $this->prefix . 'hostgroup_members'), @@ -39,8 +77,82 @@ class HostgroupQuery extends IdoQuery array() )->join( 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() ); } + + /** + * 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'); + } } diff --git a/modules/monitoring/library/Monitoring/DataView/Hostgroup.php b/modules/monitoring/library/Monitoring/DataView/Hostgroup.php index c139d8977..ed4a8bd96 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hostgroup.php +++ b/modules/monitoring/library/Monitoring/DataView/Hostgroup.php @@ -4,44 +4,45 @@ namespace Icinga\Module\Monitoring\DataView; /** - * View for hostgroups + * Host group data view */ class Hostgroup extends DataView { /** - * Retrieve columns provided by this view - * - * @return array + * {@inheritdoc} */ public function getColumns() { return array( - 'hostgroup_name', 'hostgroup_alias', - 'hostgroup_id', - 'host_name' + 'hostgroup_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( - 'hostgroup_name' => array( - 'order' => self::SORT_ASC - ), - 'hostgroup_alias' => array( - 'order' => self::SORT_ASC - ) + 'host', 'host_alias', 'host_display_name', 'host_name', + 'hostgroup', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } - 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); + } } }