Module: nagvis
Branch: master
Commit: b13408e23c4d2b021ac3908e5d4762a9bf585e00
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=b13408e23c4d2b021ac3908e5d4762a9bf585e00

Author: Roman Kyrylych <[email protected]>
Date:   Wed Aug 12 17:23:47 2009 +0300

gmap: Display current state of new/edited locations immediately

Signed-off-by: Roman Kyrylych <[email protected]>

---

 share/netmap/Location.php |   60 ++++++++++++++++++++++++++------------------
 1 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/share/netmap/Location.php b/share/netmap/Location.php
index e377dba..e562102 100644
--- a/share/netmap/Location.php
+++ b/share/netmap/Location.php
@@ -101,6 +101,36 @@ class Location
                return $node;
        }
 
+       private function updateState()
+       {
+               $db = new Database();
+
+               if (isset($this->object))
+                       switch (get_class($this->object))
+                       {
+                               case 'Host':
+                                       $this->state = 
$db->getHostState($this->object);
+                                       break;
+
+                               case 'HostGroup':
+                                       $this->state = 
$db->getHostGroupState($this->object);
+                                       break;
+
+                               case 'Service':
+                                       $this->state = 
$db->getServiceState($this->object);
+                                       break;
+
+                               case 'ServiceGroup':
+                                       $this->state = 
$db->getServiceGroupState($this->object);
+                                       break;
+
+                               default:
+                                       throw new Exception('Unknown object 
type in locations.xml');
+                       }
+               else
+                       $this->state = self::STATE_UNKNOWN;
+       }
+
        /**
         * @param  boolean $problemonly
         * @return array of Location
@@ -110,35 +140,12 @@ class Location
                if (($xml = @simplexml_load_file('locations.xml')) === FALSE)
                        throw new Exception('Could not read locations.xml');
 
-               $db = new Database();
-
                $locations = array();
                foreach ($xml->location as $node)
                {
                        $location = Location::fromXML($node);
 
-                       if (isset($location->object))
-                               switch (get_class($location->object))
-                               {
-                                       case 'Host':
-                                               $location->state = 
$db->getHostState($location->object);
-                                               break;
-
-                                       case 'HostGroup':
-                                               $location->state = 
$db->getHostGroupState($location->object);
-                                               break;
-
-                                       case 'Service':
-                                               $location->state = 
$db->getServiceState($location->object);
-                                               break;
-
-                                       case 'ServiceGroup':
-                                               $location->state = 
$db->getServiceGroupState($location->object);
-                                               break;
-
-                                       default:
-                                               throw new Exception('Unknown 
object type in locations.xml');
-                               }
+                       $location->updateState();
 
                        if (!$problemonly || $location->state != self::STATE_OK)
                                $locations[] = $location;
@@ -157,6 +164,7 @@ class Location
                        throw new Exception('Could not read locations.xml');
 
                $location->id = uniqid('', true);
+               $location->updateState();
                $node = $location->toXML($xml);
 
                if (file_put_contents('locations.xml', $xml->asXML()) !== FALSE)
@@ -165,7 +173,7 @@ class Location
                        throw new Exception('Could not write locations.xml');
     }
 
-       protected function removeNode(&$xml, $id)
+       private function removeNode(&$xml, $id)
        {
                $index = 0;
                foreach ($xml->location as $node)
@@ -192,6 +200,8 @@ class Location
                if (($xml = @simplexml_load_file('locations.xml')) === FALSE)
                        throw new Exception('Could not read locations.xml');
 
+               $location->updateState();
+
                Location::removeNode($xml, $location->id);
 
                $location->toXML($xml);


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to