[icinga-checkins] icinga.org: icinga-web/master: * Added field reset for api queries for correct cout results (fixes #2192)

git at icinga.org git at icinga.org
Wed Dec 14 10:46:21 CET 2011


Module: icinga-web
Branch: master
Commit: 2ecebbaad7ef85fed5fe6d8d734e45bdfc46fb67
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=2ecebbaad7ef85fed5fe6d8d734e45bdfc46fb67

Author: Marius Hein <marius.hein at netways.de>
Date:   Wed Dec 14 10:43:14 2011 +0100

* Added field reset for api queries for correct cout results (fixes #2192)

---

 .../IcingaStoreTargetModifierModel.class.php       |    5 ++++-
 .../Store/LegacyLayer/IcingaApiModel.class.php     |    6 +++---
 .../LegacyLayer/TargetModifierModel.class.php      |   10 +++++++---
 .../xml/grid/icinga-hostgroup-summary-template.xml |    4 +++-
 .../grid/icinga-servicegroup-summary-template.xml  |    7 ++++---
 .../lib/template/CronkGridTemplateWorker.class.php |   11 +++++++++--
 6 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/app/modules/Api/lib/datastore/IcingaStoreTargetModifierModel.class.php b/app/modules/Api/lib/datastore/IcingaStoreTargetModifierModel.class.php
index debb222..1428bdd 100644
--- a/app/modules/Api/lib/datastore/IcingaStoreTargetModifierModel.class.php
+++ b/app/modules/Api/lib/datastore/IcingaStoreTargetModifierModel.class.php
@@ -191,7 +191,10 @@ class IcingaStoreTargetModifierModel extends IcingaBaseModel implements IDataSto
     * @param Boolean Whether to check if an column alias with this name exists
     * @author Jannis Moßhammer <jannis.mosshammer at netways.de>
     **/
-    public function setFields($fields, $useColumnAlias = false) {
+    public function setFields($fields, $useColumnAlias = false, $reset = false) {
+	if ($reset === true) {
+		$this->fields = array ();
+	}
         if (!is_array($fields)) {
             $fields = array($fields);
         }
diff --git a/app/modules/Api/models/Store/LegacyLayer/IcingaApiModel.class.php b/app/modules/Api/models/Store/LegacyLayer/IcingaApiModel.class.php
index 120a279..dd7b7a0 100644
--- a/app/modules/Api/models/Store/LegacyLayer/IcingaApiModel.class.php
+++ b/app/modules/Api/models/Store/LegacyLayer/IcingaApiModel.class.php
@@ -87,9 +87,9 @@ class Api_Store_LegacyLayer_IcingaApiModel extends IcingaApiDataStoreModel imple
         return $this;
     }
 
-    public function setResultColumns($target) {
+    public function setResultColumns($target, $replace = false) {
         $this->result = null;
-        parent::setResultColumns($target);
+        parent::setResultColumns($target, $replace);
         return $this;
     }
 
@@ -119,7 +119,7 @@ class Api_Store_LegacyLayer_IcingaApiModel extends IcingaApiDataStoreModel imple
 
             $resultCols =  $this->getResultColumns();
             $data =  $this->execRead();
-
+            
             if ($this->isCount) {
                 $fields = $this->getFields();
                 $_data = array(array());
diff --git a/app/modules/Api/models/Store/LegacyLayer/TargetModifierModel.class.php b/app/modules/Api/models/Store/LegacyLayer/TargetModifierModel.class.php
index 3846fea..ea4fc5c 100644
--- a/app/modules/Api/models/Store/LegacyLayer/TargetModifierModel.class.php
+++ b/app/modules/Api/models/Store/LegacyLayer/TargetModifierModel.class.php
@@ -1073,15 +1073,19 @@ class Api_Store_LegacyLayer_TargetModifierModel extends IcingaStoreTargetModifie
         }
     }
 
-    public function setResultColumns($cols) {
+    public function setResultColumns($cols, $replace=false) {
         $this->checkForPending($cols);
         if (is_array($cols)) {
-            $this->resultColumns = array_merge($this->resultColumns,$cols);
+            if ($replace === true) {
+                $this->resultColumns = $cols;
+            } else {
+             $this->resultColumns = array_merge($this->resultColumns,$cols);
+            }
         } else {
             $this->resultColumns[] = $cols;
         }
 
-        $this->setFields($cols,true);
+        $this->setFields($cols,true,$replace);
     }
 
     public function setSearchTarget($target) {
diff --git a/app/modules/Cronks/data/xml/grid/icinga-hostgroup-summary-template.xml b/app/modules/Cronks/data/xml/grid/icinga-hostgroup-summary-template.xml
index c79d350..3be2958 100644
--- a/app/modules/Cronks/data/xml/grid/icinga-hostgroup-summary-template.xml
+++ b/app/modules/Cronks/data/xml/grid/icinga-hostgroup-summary-template.xml
@@ -162,12 +162,14 @@
         	If the countmode is 'simple' countfields will be ignored always! To use with a pager
         	you have to use the 'field' mode to count all data independent from data
         -->
-		<parameter name="countmode">simple</parameter>
+		<parameter name="countmode">field</parameter>
 		
 		<!-- 
 			If the counting differs from data result you can specify a field to count
 		-->
         <parameter name="countfields">
+            <parameter>HOSTGROUP_NAME</parameter>
+            <parameter>HOST_CURRENT_STATE</parameter>
         </parameter>
         
         <!-- Database group by -->
diff --git a/app/modules/Cronks/data/xml/grid/icinga-servicegroup-summary-template.xml b/app/modules/Cronks/data/xml/grid/icinga-servicegroup-summary-template.xml
index 8d836c5..f803818 100644
--- a/app/modules/Cronks/data/xml/grid/icinga-servicegroup-summary-template.xml
+++ b/app/modules/Cronks/data/xml/grid/icinga-servicegroup-summary-template.xml
@@ -128,12 +128,14 @@
         	If the countmode is 'simple' countfields will be ignored always! To use with a pager
         	you have to use the 'field' mode to count all data independent from data
         -->
-		<parameter name="countmode">simple</parameter>
+		<parameter name="countmode">field</parameter>
 		
 		<!-- 
 			If the counting differs from data result you can specify a field to count
 		-->
         <parameter name="countfields">
+            <parameter>SERVICEGROUP_ID</parameter>
+            <parameter>SERVICE_CURRENT_STATE</parameter>
         </parameter>
         
         <!-- Database group by -->
@@ -150,8 +152,7 @@
     	Paging record on its result
     -->
     <pager>
-    	<parameter name="enabled">false</parameter>
-    
+    	<parameter name="enabled">true</parameter>
     	<parameter name="start">0</parameter>
     </pager>
     
diff --git a/app/modules/Cronks/lib/template/CronkGridTemplateWorker.class.php b/app/modules/Cronks/lib/template/CronkGridTemplateWorker.class.php
index 3a19cb9..46efcc7 100644
--- a/app/modules/Cronks/lib/template/CronkGridTemplateWorker.class.php
+++ b/app/modules/Cronks/lib/template/CronkGridTemplateWorker.class.php
@@ -111,12 +111,19 @@ class CronkGridTemplateWorker {
                 $this->api_count->setSearchType(IcingaApiConstants::SEARCH_TYPE_COUNT);
 
                 if (is_array(($fields = $params->getParameter('countfields'))) && count($fields)) {
-                    $this->api_count->setResultColumns($fields);
+                    
+                    /**
+                     * We need to reset the columns here. Count columns differs 
+                     * from result set columns
+                     */
+                    $this->api_count->setResultColumns($fields, true);
+                    
                     $this->api_count->setResultType(IcingaApiConstants::RESULT_ARRAY);
+                    
                     $result  = $this->api_count->fetch();
+                    
                     // Try to determine the fields
                     $row = $result->getRow();
-
                     if ($row !== false) {
                         $fields = array_keys($row);
                         $field = array_shift($fields);





More information about the icinga-checkins mailing list