Module: nagvis
Branch: master
Commit: 93b05393b74aa79e1ab0f64939805065a627efe2
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/nagvis;a=commit;h=93b05393b74aa79e1ab0f64939805065a627efe2

Author: Roman Kyrylych <[email protected]>
Date:   Thu Sep  3 18:12:39 2009 +0300

geomap: Use new efficient backend calls in get{Host,Service}GroupState

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

---

 share/netmap/NagiosService.php |   68 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/share/netmap/NagiosService.php b/share/netmap/NagiosService.php
index 1d83c94..3fb0a5d 100644
--- a/share/netmap/NagiosService.php
+++ b/share/netmap/NagiosService.php
@@ -173,11 +173,37 @@ class NagiosService
         */
        public function getHostGroupState($hostgroup)
        {
-               $hosts = 
$this->backend->getHostsByHostgroupName($hostgroup->name);
-               $state = State::UNKNOWN;
+               if (($data = $this->backend->getHostgroupState($hostgroup, 0) 
=== false)
+                       return State::ERROR;
 
-               foreach ($hosts as $host)
-                       $state = max($state, $this->getHostState(new 
Host($host)));
+               $state = State::UNKNOWN;
+               foreach ($data as $host)
+               {
+                       switch ($host['state'])
+                       {
+                               case 'PENDING':
+                                       $host_state = State::UNKNOWN;
+                                       break;
+
+                               case 'UP':
+                                       $host_state = State::OK;
+                                       break;
+
+                               case 'DOWN':
+                                       $host_state = State::ERROR;
+                                       break;
+
+                               case 'UNREACHABLE':
+                                       $host_state = State::WARNING;
+                                       break;
+
+                               case 'UNKNOWN':
+                               default:
+                                       $host_state = State::UNKNOWN;
+                       }
+
+                       $state = max($state, $host_state);
+               }
 
                return $state;
        }
@@ -187,11 +213,37 @@ class NagiosService
         */
        public function getServiceGroupState($servicegroup)
        {
-               $services = 
$this->backend->getServicesByServicegroupName($servicegroup->name);
-               $state = State::UNKNOWN;
+               if (($data = 
$this->backend->getServicegroupState($servicegroup, 0) === false)
+                       return State::ERROR;
 
-               foreach ($services as $service)
-                       $state = max($state, $this->getServiceState(new 
Service($service['host_name'], $service['service_description'])));
+               $state = State::UNKNOWN;
+               foreach ($data as $service)
+               {
+                       switch ($service['state'])
+                       {
+                               case 'PENDING':
+                                       $service_state =  State::UNKNOWN;
+                                       break;
+
+                               case 'OK':
+                                       $service_state =  State::OK;
+                                       break;
+
+                               case 'WARNING':
+                                       $service_state =  State::WARNING;
+                                       break;
+
+                               case 'CRITICAL':
+                                       $service_state =  State::ERROR;
+                                       break;
+
+                               case 'UNKNOWN':
+                               default:
+                                       $service_state =  State::UNKNOWN;
+                       }
+
+                       $state = max($state, $service_state);
+               }
 
                return $state;
        }


------------------------------------------------------------------------------
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