[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * Added logging for queries

git at icinga.org git at icinga.org
Fri Jul 29 18:58:40 CEST 2011


Module: icinga-web
Branch: jmosshammer/default
Commit: d64ada4a77f391b5af86de2826cd70a8a3f024e1
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=d64ada4a77f391b5af86de2826cd70a8a3f024e1

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Fri Jul 29 18:58:02 2011 +0200

* Added logging for queries

---

 .../Store/LegacyLayer/IcingaApiModel.class.php     |   65 +++++++++++++-------
 1 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/app/modules/Api/models/Store/LegacyLayer/IcingaApiModel.class.php b/app/modules/Api/models/Store/LegacyLayer/IcingaApiModel.class.php
index 37df317..cb8c693 100644
--- a/app/modules/Api/models/Store/LegacyLayer/IcingaApiModel.class.php
+++ b/app/modules/Api/models/Store/LegacyLayer/IcingaApiModel.class.php
@@ -107,31 +107,44 @@ class Api_Store_LegacyLayer_IcingaApiModel extends IcingaApiDataStoreModel imple
     private $result = null;
     
     public function fetch() {
-        if($this->result)
-            return $this->result;   
-        $resultCols =  $this->getResultColumns();
-        $data =  $this->execRead();     
-        if($this->isCount) {
-            $fields = $this->getFields();
-            $_data = array(array());
-            foreach($fields as $field) {
-                $countField = explode(".",$field,2);
-                if(count($countField) > 1)
-                    $countField = $countField[1];
-                
-                $_data[0]["COUNT_".strtoupper($countField)] = $data;  
-                $resultCols[] = "COUNT_".strtoupper($countField);
+        try {
+            if($this->result)
+                return $this->result;   
+            $resultCols =  $this->getResultColumns();
+            $data =  $this->execRead();     
+            if($this->isCount) {
+                $fields = $this->getFields();
+                $_data = array(array());
+                foreach($fields as $field) {
+                    $countField = explode(".",$field,2);
+                    if(count($countField) > 1)
+                        $countField = $countField[1];
+        
+                    $_data[0]["COUNT_".strtoupper($countField)] = $data;  
+                    $resultCols[] = "COUNT_".strtoupper($countField);
+                }
+                $data = $_data;  
+            }
+            $this->result = $this->getContext()->getModel(
+                "Store.LegacyLayer.LegacyApiResult","Api",array(
+                    "result" => $data,
+                    "columns" => $resultCols 
+                )
+            );
+
+            return $this->result;
+        } catch(Exception $e) {
+            $sql = "";
+            try {
+                $sql = $this->getSqlQuery(); 
+            } catch(Exception $esub) {
+                $sql = "(No query created)";
             }
-            $data = $_data;  
+            AgaviContext::getInstance()->getLoggerManager()
+                ->log("Fetch failed with message ".$e->getMessage()."\n Query: ".$sql." \nTargetStore info (IcingaApiModel): ".$this->toString(), AgaviLogger::ERROR);
+        
+            throw $e; 
         }
-        $this->result = $this->getContext()->getModel(
-            "Store.LegacyLayer.LegacyApiResult","Api",array(
-                "result" => $data,
-                "columns" => $resultCols 
-            )
-        );
-
-        return $this->result;
     }
   
     public function resolveFilterFields(IcingaApiSearchFilterInterface &$filter) {
@@ -247,6 +260,12 @@ class Api_Store_LegacyLayer_IcingaApiModel extends IcingaApiDataStoreModel imple
     public function getSearchType() {
         return $this->searchType;
     }
+
+    public function toString() {
+        return "
+        \t - Store target: ".$this->getTarget()."
+        \t - Searchtype: ".$this->getSearchType();       
+    }
 } 
 
 





More information about the icinga-checkins mailing list