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

Author: Roman Kyrylych <[email protected]>
Date:   Thu Jul 30 11:59:40 2009 +0300

gmap: Initial work on saving nagios objects in locations,xml

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

---

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

diff --git a/share/netmap/Location.php b/share/netmap/Location.php
index 3947dd8..ff024eb 100644
--- a/share/netmap/Location.php
+++ b/share/netmap/Location.php
@@ -105,7 +105,7 @@ class Location
         * @param  string $description
         * @return Location
         */
-       public function add($point, $label, $address, $description)
+       public function add($point, $label, $address, $description, $object, 
$objectType)
        {
                if (($xml = @simplexml_load_file('locations.xml')) === FALSE)
                        throw new Exception('Could not read locations.xml');
@@ -119,7 +119,36 @@ class Location
                @$node->addAttribute('description', $description);
                // Note: @ prevents warnings when attribute value is an empty 
string
 
-               $location = new Location($id, $point, $label, $address, 
$description);
+               $object_node = $node->addChild($objectType);
+               switch ($object_type)
+               {
+                       case 'host':
+                               $object_node->addAttribute('name', 
$object['name']);
+                               @$object_node->addAttribute('address', 
$object['address']);
+                               @$object_node->addAttribute('alias', 
$object['alias']);
+                               break;
+
+                       case 'hostgroup':
+                               $object_node->addAttribute('name', 
$object['name']);
+                               @$object_node->addAttribute('alias', 
$object['alias']);
+                               break;
+
+                       case 'service':
+                               $object_node->addAttribute('host', 
$object['host']);
+                               @$object_node->addAttribute('description', 
$object['description']);
+                               break;
+
+                       case 'servicegroup':
+                               $object_node->addAttribute('name', 
$object['name']);
+                               @$object_node->addAttribute('alias', 
$object['alias']);
+                               break;
+
+                       default:
+                               throw new Exception('Cannot save unknown object 
type');
+               }
+       }
+
+               $location = new Location($id, $point, $label, $address, 
$description, $object, $objectType);
 
                if (file_put_contents('locations.xml', $xml->asXML()) !== FALSE)
                        return $location;
@@ -135,7 +164,7 @@ class Location
         * @param  string $description
         * @return Location
         */
-       public function edit($id, $point, $label, $address, $description)
+       public function edit($id, $point, $label, $address, $description, 
$object, $objectType)
        {
                if (($xml = @simplexml_load_file('locations.xml')) === FALSE)
                        throw new Exception('Could not read locations.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