[icinga-checkins] icinga.org: icinga-web/r1.5: * Added use_retained to database config

git at icinga.org git at icinga.org
Fri Aug 26 16:28:47 CEST 2011


Module: icinga-web
Branch: r1.5
Commit: b8037f4e0133ff5e4dd60c4abf9b221bba39946f
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=b8037f4e0133ff5e4dd60c4abf9b221bba39946f

Author: Jannis Moßhammer <jannis.mosshammer at netways.de>
Date:   Thu Aug 25 16:43:02 2011 +0200

* Added use_retained to database config

---

 app/config/databases.xml.in                        |    4 ++-
 app/modules/Api/config/autoload.xml                |    1 +
 .../lib/database/IcingaDoctrineDatabase.class.php  |   18 +++++++++++++++
 .../LegacyLayer/TargetModifierModel.class.php      |   23 +++++++++++++------
 etc/sitecfg/databases.xml                          |    5 +++-
 5 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/app/config/databases.xml.in b/app/config/databases.xml.in
index 4b03cf5..6d42521 100755
--- a/app/config/databases.xml.in
+++ b/app/config/databases.xml.in
@@ -56,13 +56,15 @@
 
 			</database>
 	
-	        <database xmlns="http://agavi.org/agavi/config/parts/databases/1.0" name="icinga" class="AppKitDoctrineDatabase">
+	        <database xmlns="http://agavi.org/agavi/config/parts/databases/1.0" name="icinga" class="IcingaDoctrineDatabase">
 		        <ae:parameter name="dsn">@api_subtype@://@api_db_user@:@api_db_pass@@@api_host@:@api_port@/@api_db_name@</ae:parameter>
                 <ae:parameter name="prefix">@api_db_prefix@</ae:parameter>
                 <ae:parameter name="charset">utf8</ae:parameter>
                 <ae:parameter name="manager_attributes">
                     <ae:parameter name="Doctrine_Core::ATTR_MODEL_LOADING">CONSERVATIVE</ae:parameter>
                 </ae:parameter>
+                <ae:parameter name="use_retained">true</ae:parameter>
+
                 <ae:parameter name="load_models">%core.module_dir%/Api/lib/database/models/generated</ae:parameter>
                 <ae:parameter name="models_directory">%core.module_dir%/Api/lib/database/models</ae:parameter>				
                 <ae:parameter name="caching">
diff --git a/app/modules/Api/config/autoload.xml b/app/modules/Api/config/autoload.xml
index 67d25ae..4fd8ff9 100755
--- a/app/modules/Api/config/autoload.xml
+++ b/app/modules/Api/config/autoload.xml
@@ -8,6 +8,7 @@
 
         <autoload name="AccessConfig">%core.module_dir%/Api/lib/config/AccessConfig.class.php</autoload>		
         <autoload name="AccessConfigHandler">%core.module_dir%/Api/lib/config/AccessConfigHandler.class.php</autoload>		
+		<autoload name="IcingaDoctrineDatabase">%core.module_dir%/Api/lib/database/IcingaDoctrineDatabase.class.php</autoload>
 
 		<autoload name="IcingaDoctrine_Query">%core.module_dir%/Api/lib/database/IcingaDoctrine_Query.class.php</autoload>
 		<autoload name="Icinga_Doctrine_Table">%core.module_dir%/Api/lib/database/IcingaDoctrineTable.class.php</autoload>
diff --git a/app/modules/Api/lib/database/IcingaDoctrineDatabase.class.php b/app/modules/Api/lib/database/IcingaDoctrineDatabase.class.php
new file mode 100644
index 0000000..3d9a58a
--- /dev/null
+++ b/app/modules/Api/lib/database/IcingaDoctrineDatabase.class.php
@@ -0,0 +1,18 @@
+<?php
+
+class IcingaDoctrineDatabase extends AppKitDoctrineDatabase {
+    private $use_retained = false;
+    public function initialize(AgaviDatabaseManager $databaseManager, array $parameters = array()) {
+        parent::initialize($databaseManager, $parameters);
+        
+        if ($this->getParameter('use_retained')) {
+            $this->use_retained = true;
+        }
+    }
+    
+    public function useRetained() {
+        return $this->use_retained;
+    }
+}
+
+?>
diff --git a/app/modules/Api/models/Store/LegacyLayer/TargetModifierModel.class.php b/app/modules/Api/models/Store/LegacyLayer/TargetModifierModel.class.php
index d50f568..0215227 100644
--- a/app/modules/Api/models/Store/LegacyLayer/TargetModifierModel.class.php
+++ b/app/modules/Api/models/Store/LegacyLayer/TargetModifierModel.class.php
@@ -10,7 +10,7 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
     }
     
     protected $ignoreIds = false;
-    
+    protected $retainedAlias = false;
     public $columns = array(
                           'PROBLEMS_OBJECT_ID'           =>        'op.object_id',
                           // Program information
@@ -339,7 +339,7 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
     **/
     protected function setupApiTargetFor($target) {
         $this->reset();
-
+        $this->retainedAlias = false;
         switch ($target) {
             case IcingaApiConstants::TARGET_INSTANCE:
                 $this->mainAlias = "i";
@@ -349,7 +349,7 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
             case IcingaApiConstants::TARGET_HOST:
                 $this->mainAlias = "oh";
                 $this->setTarget("IcingaObjects");
-
+                $this->retainedAlias = "h";
                 $this->aliasDefs = array(
                                        "h"  => array("src" => "oh", "relation" => "host", "alwaysJoin" => true),
                                        "hs"  => array("src" => "h", "relation" => "status","alwaysJoin" => true),
@@ -371,7 +371,7 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
             case IcingaApiConstants::TARGET_SERVICE:
                 $this->mainAlias = "os";
                 $this->setTarget("IcingaObjects");
-
+                $this->retainedAlias = "s";
                 $this->aliasDefs = array(
                                        "s"  => array("src" => "os", "relation" => "service", "alwaysJoin" => true),
                                        "i"  => array("src" => "s", "relation" => "instance"),
@@ -412,7 +412,7 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
             case IcingaApiConstants::TARGET_HOSTGROUP:
                 $this->mainAlias = "hg";
                 $this->setTarget("IcingaHostgroups");
-
+               
                 $this->aliasDefs = array(
                                        "ohg"   => array("src" => "hg", "relation" => "object"),
                                        "hgm"   => array("src" => "hg", "relation" => "members"),
@@ -492,6 +492,7 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
                 $this->additionalSelects["COUNT"] = "count(DISTINCT hs.host_object_id)";
                 $this->ignoreIds = true;
                 $this->forceGroup[] = "hs.current_state";
+                $this->retainedAlias = "h";
                 $this->aliasDefs = array(
                                        "h"  => array("src" => "oh", "relation" => "host"),
                                        "s"  => array("src" => "h", "relation" => "services"),
@@ -515,7 +516,7 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
                 $this->setTarget("IcingaServicestatus");
                 $this->additionalSelects["SERVICE_STATE"] = "ss.current_state";
                 $this->additionalSelects["COUNT"] = "count(DISTINCT ss.service_object_id)";
-
+                $this->retainedAlias = "s";
                 $this->forceGroup[] = "ss.current_state";
                 $this->aliasDefs = array(
                                        "s"  => array("src" => "os", "relation" => "service", "alwaysJoin" => true),
@@ -711,6 +712,8 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
             case IcingaApiConstants::TARGET_HOST_SERVICE:
                 $this->mainAlias = "op";
                 $this->setTarget("IcingaObjects");
+                $this->retainedAlias = "h";
+
                 $this->aliasDefs = array(
 
                                        "os"  => array(
@@ -892,7 +895,13 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
             $o->addSelect($select.(is_numeric($alias) ? "" : " AS ".$alias));
 
         }
-
+        $db = $this->getContext()->getDatabaseManager()->getDatabase('icinga');
+        if(method_exists($db,"useRetained")) {
+            if($this->retainedAlias) {
+                $o->andWhere($this->retainedAlias.".config_type= ?",$db->useRetained() ? "0" : "1");
+                                       
+            }
+        }
         foreach($this->forceGroup as $group) {
             $o->addGroupBy($group);
         }
diff --git a/etc/sitecfg/databases.xml b/etc/sitecfg/databases.xml
index 98e0bd6..43e5884 100644
--- a/etc/sitecfg/databases.xml
+++ b/etc/sitecfg/databases.xml
@@ -35,10 +35,13 @@
 
     <!-- 
         Overwrite the default database conneciton for icinga data retrieval
-    <db:database xmlns="http://agavi.org/agavi/config/parts/databases/1.0" name="icinga" class="AppKitDoctrineDatabase">
+        Make sure to use IcingaDoctrineDatabase, otherwise the use_retained parameter will be ignored
+       
+    <db:database xmlns="http://agavi.org/agavi/config/parts/databases/1.0" name="icinga" class="IcingaDoctrineDatabase">
         <ae:parameter name="dsn">mysql://icinga_test:test@localhost:3306/icinga_test</ae:parameter>
         <ae:parameter name="prefix">icinga_</ae:parameter>
         <ae:parameter name="charset">utf8</ae:parameter>
+         <ae:parameter name="use_retained">true</ae:parameter>
         <ae:parameter name="manager_attributes">
             <ae:parameter name="Doctrine_Core::ATTR_MODEL_LOADING">CONSERVATIVE</ae:parameter>
         </ae:parameter>





More information about the icinga-checkins mailing list