diff --git a/application/controllers/ServicesetController.php b/application/controllers/ServicesetController.php index 88c2a65d..394f6d09 100644 --- a/application/controllers/ServicesetController.php +++ b/application/controllers/ServicesetController.php @@ -24,6 +24,11 @@ class ServicesetController extends ObjectController 'urlParams' => array('name' => $this->object->object_name), 'label' => 'Services' )); + $tabs->add('hosts', array( + 'url' => 'director/serviceset/hosts', + 'urlParams' => array('name' => $this->object->object_name), + 'label' => 'Hosts' + )); } } @@ -74,6 +79,26 @@ class ServicesetController extends ObjectController $this->setViewScript('objects/table'); } + public function hostsAction() + { + $db = $this->db(); + $set = $this->object; + + $this->view->stayHere = true; + + $this->getTabs()->activate('hosts'); + $this->view->title = sprintf( + $this->translate('Hosts using this set: %s'), + $set->object_name + ); + + $this->view->table = $table = $this->loadTable('IcingaServiceSetHost') + ->setServiceSet($set) + ->setConnection($db); + + $this->setViewScript('objects/table'); + } + protected function loadObject() { if ($this->object === null) { diff --git a/application/tables/IcingaServiceSetHostTable.php b/application/tables/IcingaServiceSetHostTable.php new file mode 100644 index 00000000..8c79737f --- /dev/null +++ b/application/tables/IcingaServiceSetHostTable.php @@ -0,0 +1,71 @@ + 'h.id', + 'host' => 'h.object_name', + 'object_type' => 'h.object_type', + ); + } + + public function setServiceSet(IcingaServiceSet $set) + { + $this->set = $set; + return $this; + } + + protected function getActionUrl($row) + { + $params = array( + 'name' => $row->host + ); + + return $this->url('director/host/services', $params); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'host' => $view->translate('Hostname'), + ); + } + + public function getUnfilteredQuery() + { + return $this->db()->select()->from( + array('h' => 'icinga_host'), + array() + )->joinLeft( + array('ssh' => 'icinga_service_set'), + 'ssh.host_id = h.id', + array() + )->joinLeft( + array('ssih' => 'icinga_service_set_inheritance'), + 'ssih.service_set_id = ssh.id', + array() + )->order('h.object_name'); + } + + public function getBaseQuery() + { + return $this->getUnfilteredQuery()->where( + 'ssih.parent_service_set_id = ?', + $this->set->id + ); + } +}