[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaObjectGroup: provide groups for assign rules

git at icinga.org git at icinga.org
Tue Oct 25 04:39:59 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: 6e83a4fd5b6b56dd84c5e364285abf153d89591f
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=6e83a4fd5b6b56dd84c5e364285abf153d89591f

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Oct 24 21:55:02 2016 +0000

IcingaObjectGroup: provide groups for assign rules

---

 library/Director/Objects/IcingaHost.php        |    2 ++
 library/Director/Objects/IcingaObjectGroup.php |   31 ++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php
index 81633e2..8b8765d 100644
--- a/library/Director/Objects/IcingaHost.php
+++ b/library/Director/Objects/IcingaHost.php
@@ -139,6 +139,8 @@ class IcingaHost extends IcingaObject
             $properties[$props] = $hostProperties;
         }
 
+        $properties['groups'] = 'Groups';
+
         if (!empty($hostVars)) {
             $properties[$vars] = $hostVars;
         }
diff --git a/library/Director/Objects/IcingaObjectGroup.php b/library/Director/Objects/IcingaObjectGroup.php
index a8a9226..b92a31e 100644
--- a/library/Director/Objects/IcingaObjectGroup.php
+++ b/library/Director/Objects/IcingaObjectGroup.php
@@ -2,6 +2,9 @@
 
 namespace Icinga\Module\Director\Objects;
 
+use Icinga\Application\Config;
+use Icinga\Exception\IcingaException;
+use Icinga\Module\Director\Db;
 use Icinga\Module\Director\IcingaConfig\IcingaConfig;
 
 abstract class IcingaObjectGroup extends IcingaObject
@@ -21,4 +24,32 @@ abstract class IcingaObjectGroup extends IcingaObject
     {
         return $this->connection->getDefaultGlobalZoneName();
     }
+
+    public static function enumForType($type, Db $connection = null)
+    {
+        if ($connection === null) {
+            // TODO: not nice :(
+            $connection = Db::fromResourceName(
+                Config::module('director')->get('db', 'resource')
+            );
+        }
+
+        // Last resort defense against potentiall lousy checks:
+        if (! ctype_alpha($type)) {
+            throw new IcingaException(
+                'Holy shit, you should never have reached this'
+            );
+        }
+
+        $db = $connection->getDbAdapter();
+        $select = $db->select()->from(
+            'icinga_' . $type . 'group',
+            array(
+                'name'    => 'object_name',
+                'display' => 'COALESCE(display_name, object_name)'
+            )
+        )->where('object_type = ?', 'object')->order('display');
+
+        return $db->fetchPairs($select);
+    }
 }



More information about the icinga-checkins mailing list