Module: nagvis Branch: master Commit: c4754e98624c3c4ca7836dedef45ab4d38f6691f URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=c4754e98624c3c4ca7836dedef45ab4d38f6691f
Author: unknown <[email protected]> Date: Fri Jul 31 12:18:19 2009 +0300 gmap: Refactored XML loading/storing code for Nagios objects Signed-off-by: unknown <[email protected]> --- share/netmap/Host.php | 17 +++++++++++++++++ share/netmap/HostGroup.php | 15 +++++++++++++++ share/netmap/Location.php | 41 +++++------------------------------------ share/netmap/Service.php | 15 +++++++++++++++ share/netmap/ServiceGroup.php | 15 +++++++++++++++ 5 files changed, 67 insertions(+), 36 deletions(-) diff --git a/share/netmap/Host.php b/share/netmap/Host.php index 20da689..70a7c0a 100644 --- a/share/netmap/Host.php +++ b/share/netmap/Host.php @@ -33,6 +33,23 @@ class Host $this->address = $address; $this->alias = $alias; } + + public static function fromXML($node) + { + return new Host((string)$node['name'], + (string)$node['address'], + (string)$node['alias']); + } + + public function toXML($parent) + { + $node = $parent->addChild('host'); + $node->addAttribute('name', $this->name); + @$node->addAttribute('address', $this->address); + @$node->addAttribute('alias', $this->alias); + + return $node; + } } ?> diff --git a/share/netmap/HostGroup.php b/share/netmap/HostGroup.php index d80ee34..98e3ada 100644 --- a/share/netmap/HostGroup.php +++ b/share/netmap/HostGroup.php @@ -31,6 +31,21 @@ class HostGroup $this->name = $name; $this->alias = $alias; } + + public static function fromXML($node) + { + return new HostGroup((string)$node['name'], + (string)$node['alias']); + } + + public function toXML($parent) + { + $node = $parent->addChild('hostgroup'); + $node->addAttribute('name', $this->name); + @$node->addAttribute('alias', $this->alias); + + return $node; + } } ?> diff --git a/share/netmap/Location.php b/share/netmap/Location.php index f1c8729..ed63d5f 100644 --- a/share/netmap/Location.php +++ b/share/netmap/Location.php @@ -64,24 +64,19 @@ class Location switch ($object_type) { case 'host': - $object = new Host((string)$object_node['name'], - (string)$object_node['address'], - (string)$object_node['alias']); + $object = Host::fromXML($object_node); break; case 'hostgroup': - $object = new HostGroup((string)$object_node['name'], - (string)$object_node['alias']); + $object = HostGroup::fromXML($object_node); break; case 'service': - $object = new Service((string)$object_node['host'], - (string)$object_node['description']); + $object = Service::fromXML($object_node); break; case 'servicegroup': - $object = new ServiceGroup((string)$object_node['name'], - (string)$object_node['alias']); + $object = ServiceGroup::fromXML($object_node); break; default: @@ -119,33 +114,7 @@ class Location @$node->addAttribute('description', $description); // Note: @ prevents warnings when attribute value is an empty string - $object_node = $node->addChild($objectType); - switch ($objectType) - { - 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'); - } + $object->toXML($node); $location = new Location($id, $point, $label, $address, $description, $object, $objectType); diff --git a/share/netmap/Service.php b/share/netmap/Service.php index 666e21d..509abed 100644 --- a/share/netmap/Service.php +++ b/share/netmap/Service.php @@ -31,6 +31,21 @@ class Service $this->host = $host; $this->description= $description; } + + public static function fromXML($node) + { + return new Service((string)$node['host'], + (string)$node['description']); + } + + public function toXML($parent) + { + $node = $parent->addChild('service'); + $node->addAttribute('host', $this->host); + @$node->addAttribute('description', $this->description); + + return $node; + } } ?> diff --git a/share/netmap/ServiceGroup.php b/share/netmap/ServiceGroup.php index c2f5a24..028bee5 100644 --- a/share/netmap/ServiceGroup.php +++ b/share/netmap/ServiceGroup.php @@ -31,6 +31,21 @@ class ServiceGroup $this->name = $name; $this->alias = $alias; } + + public static function fromXML($node) + { + return new ServiceGroup((string)$node['name'], + (string)$node['alias']); + } + + public function toXML($parent) + { + $node = $parent->addChild('servicegroup'); + $node->addAttribute('name', $this->name); + @$node->addAttribute('alias', $this->alias); + + return $node; + } } ?> ------------------------------------------------------------------------------ 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
