Module: nagvis
Branch: nagvis-1.4
Commit: 4e46e21beb30a53f38fc77b32dbe87302fb38a56
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/nagvis;a=commit;h=4e46e21beb30a53f38fc77b32dbe87302fb38a56

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

---

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

diff --git a/nagvis/nagvis/includes/classes/objects/NagVisMapObj.php 
b/nagvis/nagvis/includes/classes/objects/NagVisMapObj.php
index 223ce07..2e41f18 100644
--- a/nagvis/nagvis/includes/classes/objects/NagVisMapObj.php
+++ b/nagvis/nagvis/includes/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();
@@ -370,7 +416,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
@@ -378,6 +424,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/nagvis/nagvis/includes/classes/objects/NagVisObject.php 
b/nagvis/nagvis/includes/classes/objects/NagVisObject.php
index 7eb8ecc..5459c18 100644
--- a/nagvis/nagvis/includes/classes/objects/NagVisObject.php
+++ b/nagvis/nagvis/includes/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