[icinga-checkins] icinga.org: icingaweb2-module-director/master: ServicesetController: Add hosts view to serviceSets
git at icinga.org
git at icinga.org
Fri Nov 11 15:33:26 CET 2016
Module: icingaweb2-module-director
Branch: master
Commit: cc34de9b4d9d279356b94d220e3c4bae8ceeca63
URL: https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=cc34de9b4d9d279356b94d220e3c4bae8ceeca63
Author: Markus Frosch <markus.frosch at icinga.com>
Date: Fri Nov 11 15:33:11 2016 +0100
ServicesetController: Add hosts view to serviceSets
So you can see and access hosts the serviceset is added to.
refs #12891
---
application/controllers/ServicesetController.php | 25 ++++++++
application/tables/IcingaServiceSetHostTable.php | 71 ++++++++++++++++++++++
2 files changed, 96 insertions(+)
diff --git a/application/controllers/ServicesetController.php b/application/controllers/ServicesetController.php
index 88c2a65..394f6d0 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 0000000..8c79737
--- /dev/null
+++ b/application/tables/IcingaServiceSetHostTable.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace Icinga\Module\Director\Tables;
+
+use Icinga\Module\Director\Objects\IcingaServiceSet;
+use Icinga\Module\Director\Web\Table\QuickTable;
+
+class IcingaServiceSetHostTable extends QuickTable
+{
+ protected $set;
+
+ protected $searchColumns = array(
+ 'host',
+ );
+
+ public function getColumns()
+ {
+ return array(
+ 'id' => '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
+ );
+ }
+}
More information about the icinga-checkins
mailing list