Author: Lars Michelsen <[email protected]>
Date: Wed Feb 1 19:40:09 2012 +0100
Committer: Lars Michelsen <[email protected]>
Commit-Date: Wed Feb 1 19:40:09 2012 +0100
Improved livestatus connection timeout handling
* Livestatus Backend: Added 'timeout' parameter to be able to configure the
socket timeout while connecting to the livestatus socket
* Livestatus Backend: Only try to connect to livestatus once per page load
---
ChangeLog | 3 ++
docs/en_US/backend_mklivestatus.html | 12 ++++++-
.../core/classes/GlobalBackendmklivestatus.php | 34 ++++++++++++++-----
3 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5c56377..1ad7145 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
Core
* Made template objects work again. Added doc note which does not recommend
usage of templates and the webbased editor at the same time.
+ * Livestatus Backend: Added 'timeout' parameter to be able to configure the
+ socket timeout while connecting to the livestatus socket
+ * Livestatus Backend: Only try to connect to livestatus once per page load
* FIX: Fixed wrong computed shape urls which broke all shapes
1.6.3
diff --git a/docs/en_US/backend_mklivestatus.html
b/docs/en_US/backend_mklivestatus.html
index 198fda7..6aeabb2 100644
--- a/docs/en_US/backend_mklivestatus.html
+++ b/docs/en_US/backend_mklivestatus.html
@@ -24,7 +24,17 @@
<th width="200">Value</th><th
width="150">Default</th><th>Description</th>
</tr>
<tr>
- <td>socket</td><td>unix:/usr/local/nagios/var/rw/live</td><td><p>The
socket to connect to can be a local unix socket or a tcp socket. You have to
define the type at the beginning of the string. Set "unix:" for unix
sockets or "tcp:" for tcp sockets.</p> <p>In case of the unix socket
you need to put the path of the livestatus unix socket to connect to.</p>
<p>When using a tcp socket you have to enter a hostaddress and a tcp port using
the following scheme: <host>:<port>. The host address can be an
IP-address or an FQDN.</p></td>
+ <td>socket</td>
+ <td>unix:/usr/local/nagios/var/rw/live</td>
+ <td><p>The socket to connect to can be a local unix socket or a
tcp socket. You have to define the type at the beginning of the string. Set
"unix:" for unix sockets or "tcp:" for tcp sockets.</p>
<p>In case of the unix socket you need to put the path of the livestatus unix
socket to connect to.</p> <p>When using a tcp socket you have to enter a
hostaddress and a tcp port using the following scheme: <host>:<port>. The
host address can be an IP-address or an FQDN.</p></td>
+ </tr><tr>
+ <td>timeout</td>
+ <td>5</td>
+ <td>
+ <font color="#f00">New in 1.6.4</font>: This option controls
the connect timeout of the livestatus socket.
+ This is just a fallback. To prevent timeouts when accessing
remote sites you really should configure a statushost for the backend.
+ For details take a look at the general backend parameters
documented in the <a
href="nagvis_config_format_description.html#backend">backend section</a>
+ of the main configuration format description.</a></td>
</tr>
</table>
<p>There are also some general parameters. You can read about them in
<a href="nagvis_config_format_description.html#backend">main configuration
format description</a>.</p>
diff --git a/share/server/core/classes/GlobalBackendmklivestatus.php
b/share/server/core/classes/GlobalBackendmklivestatus.php
index 7748034..6adcbb0 100644
--- a/share/server/core/classes/GlobalBackendmklivestatus.php
+++ b/share/server/core/classes/GlobalBackendmklivestatus.php
@@ -37,6 +37,7 @@
class GlobalBackendmklivestatus implements GlobalBackendInterface {
private $backendId = '';
+ private $CONNECT_EXC = null;
private $SOCKET = null;
private $socketType = '';
private $socketPath = '';
@@ -45,10 +46,19 @@ class GlobalBackendmklivestatus implements
GlobalBackendInterface {
// These are the backend local configuration options
private static $validConfig = Array(
- 'socket' => Array('must' => 1,
- 'editable' => 1,
- 'default' => 'unix:/usr/local/nagios/var/rw/live',
- 'match' => MATCH_SOCKET));
+ 'socket' => Array(
+ 'must' => 1,
+ 'editable' => 1,
+ 'default' => 'unix:/usr/local/nagios/var/rw/live',
+ 'match' => MATCH_SOCKET,
+ ),
+ 'timeout' => Array(
+ 'must' => 1,
+ 'editable' => 1,
+ 'default' => 5,
+ 'match' => MATCH_INTEGER,
+ ),
+ );
/**
* PUBLIC class constructor
@@ -156,27 +166,33 @@ class GlobalBackendmklivestatus implements
GlobalBackendInterface {
* @author Lars Michelsen <[email protected]>
*/
private function connectSocket() {
+ // Only try to connect once per page. Re-raise the connection
exception on
+ // later tries to connect
+ if($this->CONNECT_EXC != null)
+ throw $this->CONNECT_EXC;
+
// Connect to the socket
// don't want to see the connection error messages - want to handle the
// errors later with an own error message
// FIXME: Maybe use pfsockopen in the future to use persistent
connections
if($this->socketType === 'unix') {
$oldLevel = error_reporting(0);
- $this->SOCKET = fsockopen('unix://'.$this->socketPath, NULL,
$errno, $errstr);
+ $this->SOCKET = fsockopen('unix://'.$this->socketPath, NULL,
$errno, $errstr, (float) cfg('backend_'.$this->backendId, 'timeout'));
error_reporting($oldLevel);
} elseif($this->socketType === 'tcp') {
$oldLevel = error_reporting(0);
- $this->SOCKET = fsockopen($this->socketAddress, $this->socketPort,
$errno, $errstr);
+ $this->SOCKET = fsockopen($this->socketAddress, $this->socketPort,
$errno, $errstr, (float) cfg('backend_'.$this->backendId, 'timeout'));
error_reporting($oldLevel);
}
if(!$this->SOCKET) {
- $socketError = $errstr;
$this->SOCKET = null;
- throw new BackendConnectionProblem(l('Unable to connect to the
[SOCKET] in backend [BACKENDID]: [MSG]',
+ $this->CONNECT_EXC = new BackendConnectionProblem(
+ l('Unable to connect to the [SOCKET] in
backend [BACKENDID]: [MSG]',
Array('BACKENDID' =>
$this->backendId,
'SOCKET' =>
$this->socketPath,
- 'MSG' =>
$socketError)));
+ 'MSG' => $errstr)));
+ throw $this->CONNECT_EXC;
}
}
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins