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

Author: Roman Kyrylych <[email protected]>
Date:   Thu Sep  3 17:14:27 2009 +0300

Added getHostgroupState()

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

---

 .../includes/classes/GlobalBackendInterface.php    |    1 +
 .../includes/classes/GlobalBackendmerlinmy.php     |   78 ++++++++++++++++++++
 .../includes/classes/GlobalBackendndo2fs.php       |   17 ++++
 .../nagvis/includes/classes/GlobalBackendndomy.php |   17 ++++
 4 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/share/nagvis/includes/classes/GlobalBackendInterface.php 
b/share/nagvis/includes/classes/GlobalBackendInterface.php
index 4414f52..99ec737 100644
--- a/share/nagvis/includes/classes/GlobalBackendInterface.php
+++ b/share/nagvis/includes/classes/GlobalBackendInterface.php
@@ -33,6 +33,7 @@ interface GlobalBackendInterface {
        public function getObjectsEx($type);
        public function getHostState($hostName, $onlyHardstates);
        public function getServiceState($hostName, $serviceName, 
$onlyHardstates);
+       public function getHostgroupState($hostgroupName, $onlyHardstates);
        public function getHostNamesWithNoParent();
        public function getDirectChildNamesByHostName($hostName);
        public function getHostsByHostgroupName($hostgroupName);
diff --git a/share/nagvis/includes/classes/GlobalBackendmerlinmy.php 
b/share/nagvis/includes/classes/GlobalBackendmerlinmy.php
index 9796408..9fe3856 100755
--- a/share/nagvis/includes/classes/GlobalBackendmerlinmy.php
+++ b/share/nagvis/includes/classes/GlobalBackendmerlinmy.php
@@ -578,6 +578,84 @@ class GlobalBackendmerlinmy implements 
GlobalBackendInterface {
        }
        
        /**
+        * PUBLIC getHostgroupState()
+        *
+        * Returns the Nagios state and additional information for the 
requested hostgroup
+        *
+        * @param       String          $hostgroupName
+        * @param       Boolean         $onlyHardstates
+        * @return      array           $state
+        * @author      Roman Kyrylych <[email protected]>
+        */
+       public function getHostgroupState($hostgroupName, $onlyHardstates)
+       {
+               $arrReturn = Array();
+               
+               $QUERYHANDLE = $this->mysqlQuery('SELECT host_name, 
last_hard_state, current_state, state_type'
+                       .' FROM host LEFT JOIN scheduled_downtime AS sdt ON 
sdt.host_name = host.host_name'
+                       .' AND NOW() > sdt.start_time AND NOW() < sdt.end_time'
+                       .' LEFT JOIN host_hostgroup AS hhg ON hhg.host = 
host.id'
+                       .' LEFT JOIN hostgroup AS hg ON hg.id = hhg.hostgroup'
+                       ." WHERE hg.hostgroup_name = '$hostgroupName'");
+               
+               if(mysql_num_rows($QUERYHANDLE) == 0) {
+                       $arrReturn['state'] = 'ERROR';
+               } else {
+                       while($data = mysql_fetch_array($QUERYHANDLE))
+                       {
+                               $arrRow = Array('name' => $data['host_name']);
+                               
+                               /**
+                                * Only recognize hard states. There was a 
discussion about the implementation
+                                * This is a new handling of only_hard_states. 
For more details, see: 
+                                * 
http://www.nagios-portal.de/wbb/index.php?page=Thread&threadID=8524
+                                *
+                                * Thanks to Andurin and fredy82
+                                */
+                               if($onlyHardstates == 1) {
+                                       if($data['state_type'] != '0') {
+                                               $data['current_state'] = 
$data['current_state'];
+                                       } else {
+                                               $data['current_state'] = 
$data['last_hard_state'];
+                                       }
+                               }
+                               
+                               if($data['current_state'] == '') {
+                                       $arrRow['state'] = 'PENDING';
+                               } elseif($data['current_state'] == '0') {
+                                       // Host is UP
+                                       $arrRow['state'] = 'UP';
+                               } else {
+                                       // Host is DOWN/UNREACHABLE/UNKNOWN
+                                       
+                                       // Store state and output in array
+                                       switch($data['current_state']) {
+                                               case '1': 
+                                                       $arrRow['state'] = 
'DOWN';
+                                               break;
+                                               case '2':
+                                                       $arrRow['state'] = 
'UNREACHABLE';
+                                               break;
+                                               case '3':
+                                                       $arrRow['state'] = 
'UNKNOWN';
+                                               break;
+                                               default:
+                                                       $arrRow['state'] = 
'UNKNOWN';
+                                               break;
+                                       }
+                               }
+                               
+                               $arrReturn[] = $arrRow;
+                       }
+                       
+                       // Free memory
+                       mysql_free_result($QUERYHANDLE);                        
        
+               }
+               
+               return $arrReturn;
+       }
+       
+       /**
         * PUBLIC Method getHostNamesWithNoParent
         *
         * Gets all hosts with no parent host. This method is needed by the 
automap 
diff --git a/share/nagvis/includes/classes/GlobalBackendndo2fs.php 
b/share/nagvis/includes/classes/GlobalBackendndo2fs.php
index 7ff229a..93271ac 100644
--- a/share/nagvis/includes/classes/GlobalBackendndo2fs.php
+++ b/share/nagvis/includes/classes/GlobalBackendndo2fs.php
@@ -596,6 +596,23 @@ class GlobalBackendndo2fs implements 
GlobalBackendInterface {
        }
        
        /**
+        * PUBLIC getHostgroupState()
+        *
+        * Returns the Nagios state and additional information for the 
requested hostgroup
+        *
+        * @param       String          $hostgroupName
+        * @param       Boolean         $onlyHardstates
+        * @return      array           $state
+        * @author      Roman Kyrylych <[email protected]>
+        */
+       public function getHostgroupState($hostgroupName, $onlyHardstates)
+       {
+               $arrReturn = Array();
+               
+               return $arrReturn;
+       }
+       
+       /**
         * PUBLIC Method getHostNamesWithNoParent
         *
         * Gets all hosts with no parent host. This method is needed by the 
automap 
diff --git a/share/nagvis/includes/classes/GlobalBackendndomy.php 
b/share/nagvis/includes/classes/GlobalBackendndomy.php
index a374655..f0fbb9b 100755
--- a/share/nagvis/includes/classes/GlobalBackendndomy.php
+++ b/share/nagvis/includes/classes/GlobalBackendndomy.php
@@ -778,6 +778,23 @@ class GlobalBackendndomy implements GlobalBackendInterface 
{
        }
        
        /**
+        * PUBLIC getHostgroupState()
+        *
+        * Returns the Nagios state and additional information for the 
requested hostgroup
+        *
+        * @param       String          $hostgroupName
+        * @param       Boolean         $onlyHardstates
+        * @return      array           $state
+        * @author      Roman Kyrylych <[email protected]>
+        */
+       public function getHostgroupState($hostgroupName, $onlyHardstates)
+       {
+               $arrReturn = Array();
+               
+               return $arrReturn;
+       }
+       
+       /**
         * PUBLIC Method getHostNamesWithNoParent
         *
         * Gets all hosts with no parent host. This method is needed by the 
automap 


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