Module: nagvis Branch: master Commit: 0ed141819bd83632edb07a0d109d3f20f5d98585 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=0ed141819bd83632edb07a0d109d3f20f5d98585
Author: Roman Kyrylych <[email protected]> Date: Tue Aug 11 15:43:16 2009 +0300 gmap: Location::checkAll() returns the status of Nagios objects from a database Signed-off-by: Roman Kyrylych <[email protected]> --- share/netmap/Database.php | 88 +++++++++++++++++++++++++++++++++++++++++++++ share/netmap/Location.php | 24 +++++++++++- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/share/netmap/Database.php b/share/netmap/Database.php index d68a3ef..a238a53 100644 --- a/share/netmap/Database.php +++ b/share/netmap/Database.php @@ -112,6 +112,94 @@ class Database return $servicegroups; } + + /** + * @return integer + */ + public function getHostState($host) + { + $data = $this->backend->getHostState($host->name, 0); + + switch ($data['state']) + { + case 'ERROR': + return Location::STATE_ERROR; + + case 'PENDING': + return Location::STATE_WARNING; + + case 'UP': + return Location::STATE_OK; + + case 'DOWN': + return Location::STATE_ERROR; + + case 'UNREACHABLE': + return Location::STATE_ERROR; + + case 'UNKNOWN': + case default: + return Location::STATE_UNKNOWN; + } + } + + /** + * @return integer + */ + public function getServiceState($service) + { + $data = $this->backend->getServiceState($service->host, $service->description, 0); + + switch ($data['state']) + { + case 'ERROR': + return Location::STATE_ERROR; + + case 'PENDING': + return Location::STATE_WARNING; + + case 'OK': + return Location::STATE_OK; + + case 'WARNING': + return Location::STATE_WARNING; + + case 'CRITICAL': + return Location::STATE_ERROR; + + case 'UNKNOWN': + case default: + return Location::STATE_UNKNOWN; + } + } + + /** + * @return integer + */ + public function getHostGroupState($hostgroup) + { + $hosts = $this->backend->getHostsByHostgroupName($hostgroup->name); + $state = Location::STATE_UNKNOWN; + + foreach ($hosts as $host) + $state = max($state, getHostState($host)); + + return $state; + } + + /** + * @return integer + */ + public function getServiceGroupState($servicegroup) + { + $services = $this->backend->getServicesByServicegroupName($servicegroup->name); + $state = Location::STATE_UNKNOWN; + + foreach ($services as $service) + $state = max($state, getServiceState($service['host_name'], $service['service_description'])); + + return $state; + } } ?> diff --git a/share/netmap/Location.php b/share/netmap/Location.php index e01671f..f069838 100644 --- a/share/netmap/Location.php +++ b/share/netmap/Location.php @@ -214,8 +214,28 @@ class Location foreach ($xml->location as $node) { $location = Location::fromXML($node); - // TODO: check status of $location->children() here - $location->state = self::STATE_OK; + + switch ($location->object->get_class()) + { + case 'Host': + $location->state = Database::getHostState($location->object); + break; + + case 'HostGroup': + $location->state = Database::getHostGroupState($location->object); + break; + + case 'Service': + $location->state = Database::getServiceState($location->object); + break; + + case 'ServiceGroup': + $location->state = Database::getServiceGroupState($location->object); + break; + + default: + throw new Exception('Unknown object type in locations.xml'); + } $locations[] = $location; } ------------------------------------------------------------------------------ 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
