[icinga-checkins] icinga.org: icingaweb2-module-director/bugfix/loop-templateresolver-11803: Host: show a related service set list

git at icinga.org git at icinga.org
Mon Oct 31 13:31:43 CET 2016


Module: icingaweb2-module-director
Branch: bugfix/loop-templateresolver-11803
Commit: 4929f6b228841c0f5e613111eef5260652ca4cef
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=4929f6b228841c0f5e613111eef5260652ca4cef

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Oct 20 07:15:42 2016 +0000

Host: show a related service set list

---

 application/controllers/HostController.php       |   13 ++++
 application/tables/IcingaHostServiceSetTable.php |   79 ++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php
index 997b46d..bc6368a 100644
--- a/application/controllers/HostController.php
+++ b/application/controllers/HostController.php
@@ -69,6 +69,11 @@ class HostController extends ObjectController
             'director/service/add',
             array('host' => $host->object_name),
             array('class' => 'icon-plus')
+        ) . ' ' .  $this->view->qlink(
+            $this->translate('Add service set'),
+            'director/serviceset/add',
+            array('host' => $host->object_name),
+            array('class' => 'icon-plus')
         );
 
         $this->getTabs()->activate('services');
@@ -120,6 +125,14 @@ class HostController extends ObjectController
             $tables[$title] = $table->setTitle($title);
         }
 
+        $title = $this->translate('Service sets');
+        $table = $this->loadTable('IcingaHostServiceSet')
+            ->setHost($host)
+            ->setTitle($title)
+           ->setConnection($db);
+
+        $tables[$title] = $table;
+
         $this->view->tables = $tables;
     }
 
diff --git a/application/tables/IcingaHostServiceSetTable.php b/application/tables/IcingaHostServiceSetTable.php
new file mode 100644
index 0000000..6019709
--- /dev/null
+++ b/application/tables/IcingaHostServiceSetTable.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Icinga\Module\Director\Tables;
+
+use Icinga\Module\Director\Objects\IcingaHost;
+use Icinga\Module\Director\Web\Table\IcingaObjectTable;
+
+class IcingaHostServiceSetTable extends IcingaObjectTable
+{
+    protected $title;
+
+    protected $host;
+
+    public function getColumns()
+    {
+        return array(
+            'id'          => 'sset.id',
+            'name'        => 'sset.object_name',
+            'object_type' => 'sset.object_type',
+            'description' => 'sset.description',
+            'host_name'   => 'h.object_name',
+        );
+    }
+
+    public function getTitles()
+    {
+        $view = $this->view();
+        return array(
+            'name'    => $view->translate('Service set'),
+        );
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+        return $this;
+    }
+
+    public function setHost(IcingaHost $host)
+    {
+        $this->host = $host;
+        return $this;
+    }
+
+    protected function getActionUrl($row)
+    {
+        // TODO: Remove once we got a separate apply table
+        if ($row->object_type === 'apply') {
+            $params['id'] = $row->id;
+        } else {
+            $params = array('name' => $row->name);
+            if ($row->host_name) {
+                $params['host'] = $row->host_name;
+            }
+        }
+
+        return $this->url('director/serviceset', $params);
+    }
+
+    protected function getUnfilteredQuery()
+    {
+        $db = $this->connection()->getConnection();
+        $query = $db->select()->from(
+            array('sset' => 'icinga_service_set'),
+            array()
+        )->joinLeft(
+            array('h' => 'icinga_host'),
+            'h.id = sset.host_id',
+            array()
+        )->where('sset.host_id = ?', $this->host->id)->order('sset.object_name');
+
+        return $query;
+    }
+
+    public function getBaseQuery()
+    {
+        return $this->getUnfilteredQuery();
+    }
+}



More information about the icinga-checkins mailing list