Module: nagvis Branch: master Commit: e537ccbbc547c4da2de2470a5173dca81b497f2c URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/nagvis;a=commit;h=e537ccbbc547c4da2de2470a5173dca81b497f2c
Author: Roman Kyrylych <[email protected]> Date: Thu Sep 3 17:33:17 2009 +0300 Added getServicegroupState() Signed-off-by: Roman Kyrylych <[email protected]> --- .../includes/classes/GlobalBackendInterface.php | 1 + .../includes/classes/GlobalBackendmerlinmy.php | 79 ++++++++++++++++++++ .../includes/classes/GlobalBackendndo2fs.php | 17 ++++ .../nagvis/includes/classes/GlobalBackendndomy.php | 17 ++++ 4 files changed, 114 insertions(+), 0 deletions(-) diff --git a/share/nagvis/includes/classes/GlobalBackendInterface.php b/share/nagvis/includes/classes/GlobalBackendInterface.php index 99ec737..c93d4a8 100644 --- a/share/nagvis/includes/classes/GlobalBackendInterface.php +++ b/share/nagvis/includes/classes/GlobalBackendInterface.php @@ -34,6 +34,7 @@ interface GlobalBackendInterface { public function getHostState($hostName, $onlyHardstates); public function getServiceState($hostName, $serviceName, $onlyHardstates); public function getHostgroupState($hostgroupName, $onlyHardstates); + public function getServicegroupState($servicegroupName, $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 9fe3856..c2d75b7 100755 --- a/share/nagvis/includes/classes/GlobalBackendmerlinmy.php +++ b/share/nagvis/includes/classes/GlobalBackendmerlinmy.php @@ -656,6 +656,85 @@ class GlobalBackendmerlinmy implements GlobalBackendInterface { } /** + * PUBLIC getServicegroupState() + * + * Returns the Nagios state and additional information for the requested servicegroup + * + * @param String $servicegroupName + * @param Boolean $onlyHardstates + * @return array $state + * @author Roman Kyrylych <[email protected]> + */ + public function getServicegroupState($servicegroupName, $onlyHardstates) + { + $arrReturn = Array(); + + $QUERYHANDLE = $this->mysqlQuery('SELECT s.host_name, s.service_description,' + .' s.last_hard_state, s.current_state, s.state_type' + .' FROM host AS h, service AS s LEFT JOIN scheduled_downtime AS sdt ON sdt.host_name = s.host_name' + .' AND sdt.service_description = s.service_description AND NOW() > sdt.start_time AND NOW() < sdt.end_time' + .' LEFT JOIN service_servicegroup AS ssg ON ssg.service = service.id' + .' LEFT JOIN servicegroup AS sg ON sg.id = ssg.servicegroup' + ." WHERE sg.servicegroup_name = '$servicegroupName'"); + + if(mysql_num_rows($QUERYHANDLE) == 0) { + $arrReturn['state'] = 'ERROR'; + } else { + while($data = mysql_fetch_array($QUERYHANDLE)) { + $arrRow = Array('host'] => $data['host_name'], + 'description' => $data['service_description']); + + /** + * 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'] = 'OK'; + } else { + // Host is DOWN/UNREACHABLE/UNKNOWN + + // Store state and output in array + switch($data['current_state']) { + case '1': + $arrRow['state'] = 'WARNING'; + break; + case '2': + $arrRow['state'] = 'CRITICAL'; + 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 93271ac..74fe3bb 100644 --- a/share/nagvis/includes/classes/GlobalBackendndo2fs.php +++ b/share/nagvis/includes/classes/GlobalBackendndo2fs.php @@ -613,6 +613,23 @@ class GlobalBackendndo2fs implements GlobalBackendInterface { } /** + * PUBLIC getServicegroupState() + * + * Returns the Nagios state and additional information for the requested servicegroup + * + * @param String $servicegroupName + * @param Boolean $onlyHardstates + * @return array $state + * @author Roman Kyrylych <[email protected]> + */ + public function getServicegroupState($servicegroupName, $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 f0fbb9b..8c42d5f 100755 --- a/share/nagvis/includes/classes/GlobalBackendndomy.php +++ b/share/nagvis/includes/classes/GlobalBackendndomy.php @@ -795,6 +795,23 @@ class GlobalBackendndomy implements GlobalBackendInterface { } /** + * PUBLIC getServicegroupState() + * + * Returns the Nagios state and additional information for the requested servicegroup + * + * @param String $servicegroupName + * @param Boolean $onlyHardstates + * @return array $state + * @author Roman Kyrylych <[email protected]> + */ + public function getServicegroupState($servicegroupName, $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
