[icinga-checkins] icinga.org: icingaweb2-module-director/feature/service-set-12891: CubeLinks: hook into the cube module

git at icinga.org git at icinga.org
Thu Oct 20 09:26:57 CEST 2016


Module: icingaweb2-module-director
Branch: feature/service-set-12891
Commit: 46a5b3cb2f599472b4325c2f01fed39d602034a4
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=46a5b3cb2f599472b4325c2f01fed39d602034a4

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Oct 14 21:14:04 2016 +0000

CubeLinks: hook into the cube module

---

 library/Director/ProvidedHook/CubeLinks.php |   49 +++++++++++++++++++++++++++
 run.php                                     |    2 ++
 2 files changed, 51 insertions(+)

diff --git a/library/Director/ProvidedHook/CubeLinks.php b/library/Director/ProvidedHook/CubeLinks.php
new file mode 100644
index 0000000..4cbdd9f
--- /dev/null
+++ b/library/Director/ProvidedHook/CubeLinks.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Icinga\Module\Director\ProvidedHook;
+
+use Icinga\Module\Cube\Hook\ActionLinksHook;
+use Icinga\Module\Cube\Cube;
+use Icinga\Module\Cube\Ido\IdoHostStatusCube;
+use Icinga\Data\Filter\Filter;
+use Icinga\Web\View;
+
+class CubeLinks extends ActionLinksHook
+{
+    public function getHtml(View $view, Cube $cube)
+    {
+        if (! $cube instanceof IdoHostStatusCube) {
+            return '';
+        }
+        $cube->finalizeInnerQuery();
+        $query = $cube->innerQuery()
+            ->reset('columns')
+            ->columns(array('host' => 'o.name1'))
+            ->reset('group');
+
+        $hosts = $cube->db()->fetchCol($query);
+
+        if (count($hosts) === 1) {
+            $url = 'director/host/edit';
+            $params = array('name' => $hosts[0]);
+        } else {
+            $params = null;
+
+            $filter = Filter::matchAny();
+            foreach($hosts as $host) {
+                $filter->addFilter(
+                    Filter::matchAny(Filter::expression('name', '=', $host))
+                );
+            }
+
+            $url = 'director/hosts/edit?' . $filter->toQueryString();
+        }
+
+        return $view->qlink(
+            $view->translate('Modify hosts'),
+            $url,
+            $params,
+            array('class' => 'icon-wrench')
+        );
+    }
+}
diff --git a/run.php b/run.php
index 9c2ae56..0ded6e4 100644
--- a/run.php
+++ b/run.php
@@ -42,3 +42,5 @@ $this->provideHook('director/Job', $prefix . 'Job\\HousekeepingJob');
 $this->provideHook('director/Job', $prefix . 'Job\\ConfigJob');
 $this->provideHook('director/Job', $prefix . 'Job\\ImportJob');
 $this->provideHook('director/Job', $prefix . 'Job\\SyncJob');
+
+$this->provideHook('cube/ActionLinks', 'CubeLinks');



More information about the icinga-checkins mailing list