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

Author: Lars Michelsen <[email protected]>
Date:   Wed Sep 23 22:16:43 2009 +0200

#92 Added code to count only stateful objects when trying to gather wether a 
map is empty or not

---

 share/server/core/classes/objects/NagVisMapObj.php |   55 +++++++++++++++++++-
 share/server/core/classes/objects/NagVisObject.php |    4 +-
 2 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/share/server/core/classes/objects/NagVisMapObj.php 
b/share/server/core/classes/objects/NagVisMapObj.php
index 75f6ff6..5a09788 100755
--- a/share/server/core/classes/objects/NagVisMapObj.php
+++ b/share/server/core/classes/objects/NagVisMapObj.php
@@ -91,6 +91,26 @@ class NagVisMapObj extends NagVisStatefulObject {
        }
        
        /**
+        * PUBLIC getNumiStatefulMembers()
+        *
+        * Returns the number of stateful objects on the map
+        *
+        * @return  Integer    Number of stateful objects on the map
+        * @author  Lars Michelsen <[email protected]>
+        */
+       public function getNumStatefulMembers() {
+               $i = 0;
+               // Loop all objects except the stateless ones and count them
+               foreach($this->members AS $OBJ) {
+                       if($OBJ->getType() != 'textbox' && $OBJ->getType() != 
'shape') {
+                               $i++;
+                       }
+               }
+
+               return $i;
+       }
+       
+       /**
         * PUBLIC hasObjects()
         *
         * The fastest way I can expect to check if the map has objects
@@ -101,6 +121,27 @@ class NagVisMapObj extends NagVisStatefulObject {
        public function hasObjects() {
                return isset($this->members[0]);
        }
+
+       /**
+        * PUBLIC hasStatefulObjects()
+        *
+        * Check if the map has a stateful object on it
+        *
+        * @return      Boolean
+        * @author      Lars Michelsen <[email protected]>
+        */
+       public function hasStatefulObjects() {
+               // Loop all objects on the map
+               foreach($this->members AS $OBJ) {
+                       if($OBJ->getType() != 'textbox' && $OBJ->getType() != 
'shape') {
+                               // Exit on first result
+                               return true;
+                       }
+               }
+
+               // No stateful object found
+               return false;
+       }
        
        /**
         * PUBLIC fetchMembers()
@@ -231,7 +272,7 @@ class NagVisMapObj extends NagVisStatefulObject {
         * @author      Lars Michelsen <[email protected]>
         */
        private function fetchSummaryOutput() {
-               if($this->hasObjects()) {
+               if($this->hasObjects() && $this->hasStatefulObjects()) {
                        $arrStates = Array('UNREACHABLE' => 0, 'CRITICAL' => 
0,'DOWN' => 0,'WARNING' => 0,'UNKNOWN' => 0,'UP' => 0,'OK' => 0,'ERROR' => 
0,'ACK' => 0,'PENDING' => 0);
                        
                        foreach($this->getMembers() AS $OBJ) {
@@ -239,6 +280,11 @@ class NagVisMapObj extends NagVisStatefulObject {
                                if($OBJ->getType() == 'map' && 
$OBJ->is_summary_object) {
                                        continue;
                                }
+
+                               // Don't recognize textboxes and shapes
+                               if($OBJ->getType() == 'textbox' || 
$OBJ->getType() == 'shape') {
+                                       continue;
+                               }
                                
                                if(method_exists($OBJ,'getSummaryState')) {
                                        $sState = $OBJ->getSummaryState();
@@ -376,7 +422,7 @@ class NagVisMapObj extends NagVisStatefulObject {
         * @author      Lars Michelsen <[email protected]>
         */
        private function fetchSummaryState() {
-               if($this->hasObjects()) {
+               if($this->hasObjects() && $this->hasStatefulObjects()) {
                        // Get summary state member objects
                        foreach($this->getMembers() AS $OBJ) {
                                // Don't reconize summarize map objects
@@ -384,6 +430,11 @@ class NagVisMapObj extends NagVisStatefulObject {
                                        continue;
                                }
                                
+                               // Don't recognize textboxes and shapes
+                               if($OBJ->getType() == 'textbox' || 
$OBJ->getType() == 'shape') {
+                                       continue;
+                               }
+                               
                                if(method_exists($OBJ,'getSummaryState')) {
                                        $this->wrapChildState($OBJ);
                                }
diff --git a/share/server/core/classes/objects/NagVisObject.php 
b/share/server/core/classes/objects/NagVisObject.php
index d2e048b..a25135d 100755
--- a/share/server/core/classes/objects/NagVisObject.php
+++ b/share/server/core/classes/objects/NagVisObject.php
@@ -218,11 +218,13 @@ class NagVisObject {
                // Save the number of members
                switch($this->getType()) {
                        case 'host':
-                       case 'map':
                        case 'hostgroup':
                        case 'servicegroup':
                                $arr['num_members'] = $this->getNumMembers();
                        break;
+                       case 'map':
+                               $arr['num_members'] = 
$this->getNumStatefulMembers();
+                       break;
                }
                
                /**


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to