Module: nagvis Branch: master Commit: c44f278b7857e5f6269f0e35364c9f632ed88d57 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=c44f278b7857e5f6269f0e35364c9f632ed88d57
Author: LaMi <[email protected]> Date: Sun Nov 8 16:49:48 2009 +0100 Changed socket parameter of mklivestatus backend to "socket"; Parameter and backend can now handle unix and tcp sockets --- etc/nagvis.ini.php-sample | 2 +- .../core/classes/GlobalBackendmklivestatus.php | 62 +++++++++++++++++--- share/server/core/defines/matches.php | 1 + 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/etc/nagvis.ini.php-sample b/etc/nagvis.ini.php-sample index 13f7371..3871cf4 100644 --- a/etc/nagvis.ini.php-sample +++ b/etc/nagvis.ini.php-sample @@ -225,7 +225,7 @@ ; Example definition of a livestatus backend. In this case the backend_id is live_1 [backend_live_1] backendtype="mklivestatus" -;socket_path="/usr/local/nagios/var/rw/live" +;socket_path="unix:/usr/local/nagios/var/rw/live" ; in this example the ID of the Backend is "ndomy_1" you can define another ID. [backend_ndomy_1] diff --git a/share/server/core/classes/GlobalBackendmklivestatus.php b/share/server/core/classes/GlobalBackendmklivestatus.php index acb10c8..6bf9e5a 100644 --- a/share/server/core/classes/GlobalBackendmklivestatus.php +++ b/share/server/core/classes/GlobalBackendmklivestatus.php @@ -36,14 +36,18 @@ */ class GlobalBackendmklivestatus implements GlobalBackendInterface { private $backendId = ''; + + private $socketType = ''; private $socketPath = ''; + private $socketAddress = ''; + private $socketPort = 0; // These are the backend local configuration options private static $validConfig = Array( - 'socket_path' => Array('must' => 1, + 'socket' => Array('must' => 1, 'editable' => 1, - 'default' => '/usr/local/nagios/var/rw/live', - 'match' => MATCH_STRING_PATH)); + 'default' => 'unix:/usr/local/nagios/var/rw/live', + 'match' => MATCH_SOCKET)); /** * PUBLIC class constructor @@ -56,12 +60,14 @@ class GlobalBackendmklivestatus implements GlobalBackendInterface { public function __construct($CORE, $backendId) { $this->backendId = $backendId; - $this->socketPath = GlobalCore::getInstance()->getMainCfg()->getValue('backend_'.$backendId, 'socket_path'); + // Parse the socket params + $this->parseSocket(GlobalCore::getInstance()->getMainCfg()->getValue('backend_'.$backendId, 'socket')); // Run preflight checks - if(!$this->checkSocketExists()) { - new GlobalMessage('ERROR', GlobalCore::getInstance()->getLang()->getText('The livestatus socket [SOCKET] in backend [BACKENDID] does not exist', Array('BACKENDID' => $this->backendId, 'SOCKET' => $this->socketPath))); + if($this->socketType == 'unix' && !$this->checkSocketExists()) { + new GlobalMessage('ERROR', GlobalCore::getInstance()->getLang()->getText('Unable to connect to livestatus socket. The socket [SOCKET] in backend [BACKENDID] does not exist', Array('BACKENDID' => $this->backendId, 'SOCKET' => $this->socketPath))); } + if(!function_exists('socket_create')) { new GlobalFrontendMessage('ERROR', GlobalCore::getInstance()->getLang()->getText('The PHP function socket_create is not available. Maybe the sockets module is missing in your PHP installation. Needed by backend [BACKENDID].', Array('BACKENDID' => $this->backendId, 'SOCKET' => $this->socketPath))); } @@ -71,6 +77,36 @@ class GlobalBackendmklivestatus implements GlobalBackendInterface { } /** + * PRIVATE parseSocket + * + * Parses and sets the socket options + * + * @return String Parses the socket + * @author Lars Michelsen <[email protected]> + */ + private function parseSocket($socket) { + // Explode the given socket definition + list($type, $address) = explode(':', $socket, 2); + + + + if($type === 'unix') { + $this->socketType = $type; + $this->socketPath = $address; + } elseif($type === 'tcp') { + $this->socketType = $type; + + // Extract address and port + list($address, $port) = explode(':', $address, 2); + + $this->socketAddress = $address; + $this->socketPort = $port; + } else { + new GlobalFrontendMessage('ERROR', GlobalCore::getInstance()->getLang()->getText('Unknown socket type given in backend [BACKENDID]', Array('BACKENDID' => $this->backendId))); + } + } + + /** * PUBLIC getValidConfig * * Returns the valid config for this backend @@ -109,8 +145,14 @@ class GlobalBackendmklivestatus implements GlobalBackendInterface { * @author Lars Michelsen <[email protected]> */ private function queryLivestatus($query) { + $sock = false; + // Create socket connection - $sock = socket_create(AF_UNIX, SOCK_STREAM, 0); + if($this->socketType === 'unix') { + $sock = socket_create(AF_UNIX, SOCK_STREAM, 0); + } elseif($this->socketType === 'tcp') { + $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + } if($sock == false) { new GlobalMessage('ERROR', GlobalCore::getInstance()->getLang()->getText('Could not create livestatus socket [SOCKET] in backend [BACKENDID].', Array('BACKENDID' => $this->backendId, 'SOCKET' => $this->socketPath))); @@ -118,7 +160,11 @@ class GlobalBackendmklivestatus implements GlobalBackendInterface { } // Connect to the socket - $result = socket_connect($sock, $this->socketPath); + if($this->socketType === 'unix') { + $result = socket_connect($sock, $this->socketPath); + } elseif($this->socketType === 'tcp') { + $result = socket_connect($sock, $this->socketAddress, $this->socketPort); + } if($result == false) { new GlobalMessage('ERROR', GlobalCore::getInstance()->getLang()->getText('Unable to connect to the [SOCKET] in backend [BACKENDID]: [MSG]', Array('BACKENDID' => $this->backendId, 'SOCKET' => $this->socketPath, 'MSG' => socket_strerror(socket_last_error($sock))))); diff --git a/share/server/core/defines/matches.php b/share/server/core/defines/matches.php index b3e59ab..391d81e 100644 --- a/share/server/core/defines/matches.php +++ b/share/server/core/defines/matches.php @@ -48,6 +48,7 @@ define('MATCH_PNG_GIF_JPG_FILE_OR_NONE', '/^((.+)\.(png|gif|jpg)|none)$/i'); define('MATCH_PNG_GIF_JPG_FILE_OR_URL', '/^((.+)\.(png|gif|jpg)|\[[0-9a-z\s\:\+\[\]\(\)\=\%\?\&\_\.\-...@\=\/\\\]+\])$/i'); define('MATCH_ROTATION_STEP_TYPES_EMPTY', '/^(?:map|automap|url)?$/'); define('MATCH_LANGUAGE_EMPTY', '/^[a-zA-Z0-9-_]*$/'); +define('MATCH_SOCKET', '/^(unix:[a-zA-Z0-9-_\.\/]+|tcp:[a-zA-Z0-9\.]+:[0-9]{1,5})$/'); define('MATCH_MAP_NAME', '/^[0-9A-Za-z_-]+$/'); define('MATCH_MAP_NAME_EMPTY', '/^[0-9A-Za-z_-]*$/'); ------------------------------------------------------------------------------ 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
