Module: nagvis Branch: master Commit: 11148d58b7dda627aa67adfc48096f472219b5c6 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=11148d58b7dda627aa67adfc48096f472219b5c6
Author: Lars Michelsen <[email protected]> Date: Wed Jul 21 15:31:32 2010 +0200 #331 Added alivehost parameter to backends for checking wether a backend is reachable using a local backend --- docs/en_US/nagvis_config_format_description.html | 14 +++++++ etc/nagvis.ini.php-sample | 24 +++++++++++ share/server/core/classes/CoreBackendMgmt.php | 45 +++++++++++++++++++++- share/server/core/classes/GlobalMainCfg.php | 4 ++ 4 files changed, 86 insertions(+), 1 deletions(-) diff --git a/docs/en_US/nagvis_config_format_description.html b/docs/en_US/nagvis_config_format_description.html index 26a70be..8e33b68 100644 --- a/docs/en_US/nagvis_config_format_description.html +++ b/docs/en_US/nagvis_config_format_description.html @@ -384,6 +384,20 @@ socket="unix:/usr/local/nagios/var/rw/live" <td> backendtype </td><td>mklivestatus</td><td> type of backend - MUST be set </td> </tr> <tr> + <td>alivehost</td><td> </td> + <td><p>The alive host can be used to prevent annoying timeouts when a backend is not + reachable. This is only useful in multi backend setups.</p> + <p>It works as follows: The assumption is that there is a "local" backend which + monitors the host of the "remote" backend. When the remote backend host is + reported as UP the backend is queried as normal.</p> + <p>When the remote backend host is reported as "DOWN" or "UNREACHABLE" NagVis won't + try to connect to the backend anymore until the backend host gets available again.</p> + <p>The alivehost needs to be given in the following format: "<backend_id>:<hostname>" + -> e.g. "live_2:nagios"</p> + <p>The host needs to be in another backend than the current one to work correctly.</p> + </td> + </tr> + <tr> <td> htmlcgi </td><td> /nagios/cgi-bin </td><td> Path to the cgi-bin directory of this backend (interesting for multiple backends) </td> </tr> <tr> diff --git a/etc/nagvis.ini.php-sample b/etc/nagvis.ini.php-sample index a6865f6..492ea26 100644 --- a/etc/nagvis.ini.php-sample +++ b/etc/nagvis.ini.php-sample @@ -263,6 +263,18 @@ ; The path /usr/local/nagios/var/rw has to exist [backend_live_1] backendtype="mklivestatus" +; The alive host can be used to prevent annoying timeouts when a backend is not +; reachable. This is only useful in multi backend setups. +; +; It works as follows: The assumption is that there is a "local" backend which +; monitors the host of the "remote" backend. When the remote backend host is +; reported as UP the backend is queried as normal. +; When the remote backend host is reported as "DOWN" or "UNREACHABLE" NagVis won't +; try to connect to the backend anymore until the backend host gets available again. +; +; The alivehost needs to be given in the following format: +; "<backend_id>:<hostname>" -> e.g. "live_2:nagios" +;alivehost="" ;socket="unix:/usr/local/nagios/var/rw/live" ; Example definition for a MySQL backend @@ -270,6 +282,18 @@ backendtype="mklivestatus" [backend_ndomy_1] ; type of backend - MUST be set backendtype="ndomy" +; The alive host can be used to prevent annoying timeouts when a backend is not +; reachable. This is only useful in multi backend setups. +; +; It works as follows: The assumption is that there is a "local" backend which +; monitors the host of the "remote" backend. When the remote backend host is +; reported as UP the backend is queried as normal. +; When the remote backend host is reported as "DOWN" or "UNREACHABLE" NagVis won't +; try to connect to the backend anymore until the backend host gets available again. +; +; The alivehost needs to be given in the following format: +; "<backend_id>:<hostname>" -> e.g. "live_2:nagios" +;alivehost="" ; hostname for NDO-db ;dbhost="localhost" ; portname for NDO-db diff --git a/share/server/core/classes/CoreBackendMgmt.php b/share/server/core/classes/CoreBackendMgmt.php index a73308d..58b6976 100644 --- a/share/server/core/classes/CoreBackendMgmt.php +++ b/share/server/core/classes/CoreBackendMgmt.php @@ -49,7 +49,8 @@ class CoreBackendMgmt { } public function getBackend($id) { - if(!isset($this->aInitialized[$id])) + // Only try to initialize once per request + if(!isset($this->aInitialized[$id]) && !isset($this->aError[$id])) $this->initializeBackend($id); // Re-throw the stored backend exception for this request @@ -375,6 +376,32 @@ class CoreBackendMgmt { new GlobalMessage('ERROR', $this->CORE->getLang()->getText('backendNotExists','BACKENDID~'.$backendId.',BACKENDTYPE~'.$this->CORE->getMainCfg()->getValue('backend_'.$backendId,'backendtype'))); return false; } + + /** + * Checks if a backend host is alive using status + * information from another backend + * + * @author Lars Michelsen <[email protected]> + */ + private function backendAlive($backendId, $aliveHost) { + list($aliveBackend, $aliveHost) = explode(':', $aliveHost, 2); + + if($aliveBackend == $backendId) + $this->aError[$backendId] = new BackendConnectionProblem($this->CORE->getLang()->getText('Configuration Error: The aliveHost ([ALIVEHOST]) is in same backend as the one to check.', Array('ALIVEHOST' => $aliveHost))); + + try { + $filters = Array(Array('key' => 'host_name', 'op' => '=', 'val' => 'name')); + $aObjs = Array($aliveHost => Array(new NagVisHost($this->CORE, $this, $aliveBackend, $aliveHost))); + $aCounts = $this->getBackend($aliveBackend)->getHostState($aObjs, 1, $filters); + } catch(BackendException $e) { + return true; + } + + if($aCounts[$aliveHost]['state'] == 'UP') + return true; + else + return false; + } /** * Initializes a backend @@ -384,6 +411,22 @@ class CoreBackendMgmt { */ private function initializeBackend($backendId) { if($this->checkBackendExists($backendId, true)) { + /** + * The alive host can be used to prevent annoying timeouts when a backend is not + * reachable. This is only useful in multi backend setups. + * + * It works as follows: The assumption is that there is a "local" backend which + * monitors the host of the "remote" backend. When the remote backend host is + * reported as UP the backend is queried as normal. + * When the remote backend host is reported as "DOWN" or "UNREACHABLE" NagVis won't + * try to connect to the backend anymore until the backend host gets available again. + */ + $aliveHost = $this->CORE->getMainCfg()->getValue('backend_' . $backendId, 'alivehost'); + if($aliveHost != '' && !$this->backendAlive($backendId, $aliveHost)) { + $this->aError[$backendId] = new BackendConnectionProblem($this->CORE->getLang()->getText('The backend is reported as dead by the aliveHost ([ALIVEHOST]).', Array('ALIVEHOST' => $aliveHost))); + return false; + } + try { $backendClass = 'GlobalBackend' . $this->CORE->getMainCfg()->getValue('backend_' . $backendId, 'backendtype'); $this->BACKENDS[$backendId] = new $backendClass($this->CORE, $backendId); diff --git a/share/server/core/classes/GlobalMainCfg.php b/share/server/core/classes/GlobalMainCfg.php index 925794f..7dc1cb6 100644 --- a/share/server/core/classes/GlobalMainCfg.php +++ b/share/server/core/classes/GlobalMainCfg.php @@ -527,6 +527,10 @@ class GlobalMainCfg { 'editable' => 0, 'default' => '', 'match' => MATCH_STRING_NO_SPACE), + 'alivehost' => Array('must' => 0, + 'editable' => 1, + 'default' => '', + 'match' => MATCH_STRING_NO_SPACE_EMPTY), 'htmlcgi' => Array('must' => 0, 'editable' => 1, 'default' => '', ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
