Module: nagvis
Branch: master
Commit: 363b7b98b80c2799df062f00325e263997fd8de5
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=363b7b98b80c2799df062f00325e263997fd8de5

Author: Lars Michelsen <[email protected]>
Date:   Wed May  5 23:06:22 2010 +0200

Recoded wrapChildState method from recursive calls to one call per object with 
loop in the method

---

 share/server/core/classes/objects/NagVisMapObj.php |   16 +---
 .../core/classes/objects/NagVisStatefulObject.php  |   86 +++++++++-----------
 share/server/core/classes/objects/NagiosHost.php   |   11 +--
 .../core/classes/objects/NagiosHostgroup.php       |   11 +--
 .../core/classes/objects/NagiosServicegroup.php    |   11 +--
 5 files changed, 52 insertions(+), 83 deletions(-)

diff --git a/share/server/core/classes/objects/NagVisMapObj.php 
b/share/server/core/classes/objects/NagVisMapObj.php
index 468d195..333a671 100644
--- a/share/server/core/classes/objects/NagVisMapObj.php
+++ b/share/server/core/classes/objects/NagVisMapObj.php
@@ -491,19 +491,11 @@ class NagVisMapObj extends NagVisStatefulObject {
         * @author      Lars Michelsen <[email protected]>
         */
        private function fetchSummaryState() {
-               if($this->hasObjects() && $this->hasStatefulObjects()) {
-                       // Get summary state member objects
-                       foreach($this->getStateRelevantMembers() AS $OBJ) {
-                               //try {
-                                       $this->wrapChildState($OBJ);
-                               /*} catch(NagVisException $e) {
-                                       $OBJ->summary_state = 'ERROR';
-                                       $OBJ->summary_output = $e->getMessage();
-                               }*/
-                       }
-               } else {
+               // Get summary state of this object from single objects
+               if($this->hasObjects() && $this->hasStatefulObjects())
+                       $this->wrapChildState($this->getStateRelevantMembers());
+               else
                        $this->summary_state = 'UNKNOWN';
-               }
        }
 }
 ?>
diff --git a/share/server/core/classes/objects/NagVisStatefulObject.php 
b/share/server/core/classes/objects/NagVisStatefulObject.php
index e2ef538..c3509e4 100644
--- a/share/server/core/classes/objects/NagVisStatefulObject.php
+++ b/share/server/core/classes/objects/NagVisStatefulObject.php
@@ -849,64 +849,52 @@ class NagVisStatefulObject extends NagVisObject {
        /**
         * PROTECTED wrapChildState()
         *
-        * Wraps the state of the current object with the given child object
+        * Loops all given object so gather the summary state of the current 
object
         *
-        * @param               Object          Object with a state
-        * @author      Lars Michelsen <[email protected]>
+        * @param   Array   List of objects to gather the summary state from
+        * @author  Lars Michelsen <[email protected]>
         */
-       protected function wrapChildState($OBJ) {
-               $sSummaryState = $this->summary_state;
-               $sObjSummaryState = $OBJ->summary_state;
-       
+       protected function wrapChildState($OBJS) {
                if(NagVisObject::$stateWeight === null)
                        NagVisObject::$stateWeight = 
$this->CORE->getMainCfg()->getStateWeight();
-               
-               if(isset(NagVisObject::$stateWeight[$sObjSummaryState])) {
-                       $objAck = $OBJ->summary_problem_has_been_acknowledged;
-                       $objDowntime = $OBJ->summary_in_downtime;
+
+               // Initialize empty or with current object state
+               $currentStateWeight = null;
+               if($this->summary_state != '') {
+                       $sType = 'normal';
+                       if($this->summary_problem_has_been_acknowledged == 1 && 
isset(NagVisObject::$stateWeight[$this->summary_state]['ack']))
+                               $sType = 'ack';
+                       elseif($this->summary_in_downtime == 1 && 
isset(NagVisObject::$stateWeight[$this->summary_state]['downtime']))
+                               $sType = 'downtime';
                        
-                       if($sSummaryState != '') {
-                               /* When the state of the current child is not 
as good as the current
-                                * summary state or the state is equal and the 
sub-state differs.
-                                */
-                               
-                               // Gather the current summary state type
-                               $sType = 'normal';
-                               if($this->summary_problem_has_been_acknowledged 
== 1 && isset(NagVisObject::$stateWeight[$sSummaryState]['ack'])) {
-                                       $sType = 'ack';
-                               } elseif($this->summary_in_downtime == 1 && 
isset(NagVisObject::$stateWeight[$sSummaryState]['downtime'])) {
-                                       $sType = 'downtime';
-                               }
+                       $currentStateWeight = 
NagVisObject::$stateWeight[$this->summary_state][$sType];
+               }
 
+               // Loop all object to gather the worst state and set it as 
summary
+               // state of the current object
+               foreach($OBJS AS $OBJ) {
+                       $objSummaryState = $OBJ->summary_state;
+                       $objAck          = 
$OBJ->summary_problem_has_been_acknowledged;
+                       $objDowntime     = $OBJ->summary_in_downtime;
+               
+                       if(isset(NagVisObject::$stateWeight[$objSummaryState])) 
{
                                // Gather the object summary state type
-                               $sObjType = 'normal';
-                               if($objAck == 1 && 
isset(NagVisObject::$stateWeight[$sObjSummaryState]['ack'])) {
-                                       $sObjType = 'ack';
-                               } elseif($objDowntime == 1 && 
isset(NagVisObject::$stateWeight[$sObjSummaryState]['downtime'])) {
-                                       $sObjType = 'downtime';
-                               }
+                               $objType = 'normal';
+                               if($objAck == 1 && 
isset(NagVisObject::$stateWeight[$objSummaryState]['ack']))
+                                       $objType = 'ack';
+                               elseif($objDowntime == 1 && 
isset(NagVisObject::$stateWeight[$objSummaryState]['downtime']))
+                                       $objType = 'downtime';
                                
-                               
if(NagVisObject::$stateWeight[$sSummaryState][$sType] < 
NagVisObject::$stateWeight[$sObjSummaryState][$sObjType]) { 
-                                       $this->summary_state = 
$sObjSummaryState;
-                                       
-                                       if($objAck == 1) {
-                                               
$this->summary_problem_has_been_acknowledged = 1;
-                                       } else {
-                                               
$this->summary_problem_has_been_acknowledged = 0;
-                                       }
-                                       
-                                       if($objDowntime == 1) {
-                                               $this->summary_in_downtime = 1;
-                                       } else {
-                                               $this->summary_in_downtime = 0;
-                                       }
+                               
if(isset(NagVisObject::$stateWeight[$objSummaryState][$objType]) && 
($currentStateWeight === null || 
NagVisObject::$stateWeight[$objSummaryState][$objType] >= $currentStateWeight)) 
{
+                                       $this->summary_state                    
     = $objSummaryState;
+                                       
$this->summary_problem_has_been_acknowledged = $objAck;
+                                       $this->summary_in_downtime              
     = $objDowntime;
+                                       $currentStateWeight                     
     = NagVisObject::$stateWeight[$objSummaryState][$objType];
                                }
-                       } else {
-                               $this->summary_state = $sObjSummaryState;
-                               $this->summary_problem_has_been_acknowledged = 
$objAck;
-                               $this->summary_in_downtime = $objDowntime;
                        }
-               } else {
+               }
+
+               /* else {
                        if($OBJ->getType() == 'service')
                                $service = '/'.$OBJ->getServiceDescription();
                        else
@@ -914,7 +902,7 @@ class NagVisStatefulObject extends NagVisObject {
                        
                        // Error no valid state
                        throw new 
NagVisException(GlobalCore::getInstance()->getLang()->getText('The object 
[TYPE]/[NAME][SERVICE] as child of [PTYPE]/[PNAME] has an invalid state 
"[STATE]".', Array('PTYPE' => $this->getType(), 'PNAME' => $this->getName(), 
'TYPE' => $OBJ->getType(), 'NAME' => $OBJ->getName(), 'STATE' => 
$sObjSummaryState, 'SERVICE' => $service)));
-               }
+               }*/
        }
 }
 ?>
diff --git a/share/server/core/classes/objects/NagiosHost.php 
b/share/server/core/classes/objects/NagiosHost.php
index 7e54da5..28668c6 100644
--- a/share/server/core/classes/objects/NagiosHost.php
+++ b/share/server/core/classes/objects/NagiosHost.php
@@ -563,14 +563,9 @@ class NagiosHost extends NagVisStatefulObject {
                $this->summary_problem_has_been_acknowledged = 
$this->problem_has_been_acknowledged;
                $this->summary_in_downtime = $this->in_downtime;
                
-               // Only merge host state with service state when 
recognize_services is set 
-               // to 1
-               if($this->recognize_services) {
-                       // Get states of services and merge with host state
-                       foreach($this->getMembers() AS $SERVICE) {
-                               $this->wrapChildState($SERVICE);
-                       }
-               }
+               // Only merge host state with service state when 
recognize_services is set to 1
+               if($this->recognize_services)
+                       $this->wrapChildState($this->getMembers());
        }
                
        /**
diff --git a/share/server/core/classes/objects/NagiosHostgroup.php 
b/share/server/core/classes/objects/NagiosHostgroup.php
index 8b8ba9b..5f62f6c 100644
--- a/share/server/core/classes/objects/NagiosHostgroup.php
+++ b/share/server/core/classes/objects/NagiosHostgroup.php
@@ -207,14 +207,11 @@ class NagiosHostgroup extends NagVisStatefulObject {
         * @author      Lars Michelsen <[email protected]>
         */
        private function fetchSummaryState() {
-               if($this->hasMembers()) {
-                       // Get summary state member objects
-                       foreach($this->members AS &$MEMBER) {
-                               $this->wrapChildState($MEMBER);
-                       }
-               } else {
+               // Get summary state from member objects
+               if($this->hasMembers())
+                       $this->wrapChildState($this->members);
+               else
                        $this->summary_state = 'ERROR';
-               }
        }
        
        /**
diff --git a/share/server/core/classes/objects/NagiosServicegroup.php 
b/share/server/core/classes/objects/NagiosServicegroup.php
index c430bf4..8222061 100644
--- a/share/server/core/classes/objects/NagiosServicegroup.php
+++ b/share/server/core/classes/objects/NagiosServicegroup.php
@@ -156,14 +156,11 @@ class NagiosServicegroup extends NagVisStatefulObject {
         * @author      Lars Michelsen <[email protected]>
         */
        private function fetchSummaryState() {
-               if($this->getNumMembers() > 0) {
-                       // Get summary state member objects
-                       foreach($this->members AS &$MEMBER) {
-                               $this->wrapChildState($MEMBER);
-                       }
-               } else {
+               // Get summary state from member objects
+               if($this->getNumMembers() > 0)
+                       $this->wrapChildState($this->members);
+               else
                        $this->summary_state = 'ERROR';
-               }
        }
        
        /**


------------------------------------------------------------------------------
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to