[icinga-checkins] icinga.org: icingaweb2-module-director/master: Db: add deployment settings helper methods

git at icinga.org git at icinga.org
Tue Feb 9 21:45:28 CET 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Feb  9 20:38:16 2016 +0100

Db: add deployment settings helper methods

---

 library/Director/Db.php |   41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/library/Director/Db.php b/library/Director/Db.php
index 341cf5d..a2fd967 100644
--- a/library/Director/Db.php
+++ b/library/Director/Db.php
@@ -4,6 +4,8 @@ namespace Icinga\Module\Director;
 
 use Icinga\Data\Db\DbConnection;
 use Icinga\Module\Director\Objects\DirectorDeploymentLog;
+use Icinga\Module\Director\Objects\IcingaEndpoint;
+use Icinga\Exception\ConfigurationError;
 use Zend_Db_Expr;
 use Zend_Db_Select;
 
@@ -22,6 +24,45 @@ class Db extends DbConnection
         return $this->getDbAdapter();
     }
 
+    public function getMasterZoneName()
+    {
+        return $this->getSetting('master_zone', 'master');
+    }
+
+    public function getDefaultGlobalZoneName()
+    {
+        return $this->getSetting('default_global_zone', 'director-global');
+    }
+
+    public function getDeploymentEndpointName()
+    {
+        $db = $this->db();
+        $query = $db->select()->from(
+            array('e' => 'icinga_endpoint'),
+            array('object_name' => 'e.object_name')
+        )->join(
+            array('z' => 'icinga_zone'),
+            array(),
+            'e.zone_id = z.id'
+        )->where('z.object_name = ?', $this->getMasterZoneName())
+         ->order('e.object_name ASC')
+         ->limit(1);
+
+        $name = $db->fetchOne($query);
+        if (! $name) {
+            throw new ConfigurationError(
+                'Unable to detect deployment your endpoint'
+            );
+        }
+
+        return $name;
+    }
+
+    public function getDeploymentEndpoint()
+    {
+        return IcingaEndpoint::load($this->getDeploymentEndpointName(), $this);
+    }
+
     public function getSetting($name, $default = null)
     {
         if ($this->settings === null) {



More information about the icinga-checkins mailing list