[icinga-checkins] icinga.org: icinga-api/cdoebler/default: * added ido-config-file parser to contributions

Christian Doebler christian.doebler at netways.de
Sat Oct 3 12:47:38 CEST 2009


Module: icinga-api
Branch: cdoebler/default
Commit: a0d9b4d8e9bdc446664d0dc7bb5951f2f977fd00
URL:    https://git.icinga.org/?p=icinga-api.git;a=commit;h=a0d9b4d8e9bdc446664d0dc7bb5951f2f977fd00

Author: Christian Doebler <christian.doebler at netways.de>
Date:   Sat Oct  3 12:40:40 2009 +0200

* added ido-config-file parser to contributions

---

 contrib/ido2dbparser/Ido2dbParser.php.in |   99 ++++++++++++++++++++++++++++++
 contrib/ido2dbparser/README              |   10 +++
 2 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/contrib/ido2dbparser/Ido2dbParser.php.in b/contrib/ido2dbparser/Ido2dbParser.php.in
new file mode 100644
index 0000000..928e133
--- /dev/null
+++ b/contrib/ido2dbparser/Ido2dbParser.php.in
@@ -0,0 +1,99 @@
+<?php
+/*
+* Class to parse the ido2db.cfg
+*
+* @author Michael Lübben <michael_luebben at web.de>
+*/
+class Ido2dbParser {
+
+	// Default path to ido2db.cfg
+	public $defaultPathToCfgFile = "@sysconfdir@/ido2db.cfg";
+	
+	// Temporary array for read in ido2db configuration file
+	public $arrTmpCfgFile = NULL;
+	public $arrCfgFile = NULL;
+	
+	// Array with allowed parameter in the configuration file
+	protected $allowedParameters = array(
+											"lock_file",
+											"ndo2db_user",
+											"ndo2db_group",
+											"socket_type",
+											"socket_name",
+											"tcp_port",
+											"db_servertype",
+											"db_host",
+											"db_port",
+											"db_name",
+											"db_prefix",
+											"db_user",
+											"db_pass",
+											"max_timedevents_age",
+											"max_systemcommands_age",
+											"max_servicechecks_age",
+											"max_hostchecks_age",
+											"max_eventhandlers_age",
+											"debug_level",
+											"debug_verbosity",
+											"debug_file",
+											"max_debug_file_size");
+
+
+	/*
+	* public function __constructor
+	*
+	* @author Michael Lübben <michael_luebben at web.de>
+	* @params string $setPathToCfgFile
+	*/
+	public function __construct($setPathToCfgFile = NULL) {
+		if ($setPathToCfgFile === NULL) {
+			$this->pathToCfgFile = $this->defaultPathToCfgFile;
+		} else {
+			$this->pathToCfgFile = $setPathToCfgFile;
+		}
+		$this->parseCfgFile();
+	}
+	
+	
+	/*
+	* protected function parseCfgFile
+	*
+	* @author Michael Lübben <michael_luebben at web.de>
+	*/
+	protected function parseCfgFile() {
+	
+		// Read cfg file
+		$this->arrTmpCfgFile = file($this->pathToCfgFile);
+		
+		// Remove comments and blank lines from array
+		foreach ($this->arrTmpCfgFile as $line) {
+			$line = trim($line);
+			if (strlen($line) != 0) {
+				if (substr($line,0,1) != "#") {
+					$arrTmpParam = explode("=",$line);
+					$this->arrCfgFile[$arrTmpParam[0]] = $arrTmpParam[1];
+				}
+			}
+		}
+	}
+	
+	
+	/*
+	* public function getConfigParameter
+	*
+	* @params string $param
+	* @author Michael Lübben <michael_luebben at web.de>
+	*/
+	public function getConfigParameter($parameter) {
+		if (!in_array($parameter, $this->allowedParameters)) {
+			throw new Exception('Undefined parameter '.$parameter);
+		} else {
+			return $this->arrCfgFile[$parameter];
+		}
+	}
+
+}
+
+// extend exceptions
+class parseIdo2dbException extends Exception {}
+?>
diff --git a/contrib/ido2dbparser/README b/contrib/ido2dbparser/README
new file mode 100644
index 0000000..2397464
--- /dev/null
+++ b/contrib/ido2dbparser/README
@@ -0,0 +1,10 @@
+In order to use the ido-config parser you have to apply some changes:
+
+1. Change @sysconfdir@ at line 11 of Ido2dbParser.php.in the directory where
+   your ido2db.cfg is located at.
+
+2. Rename Ido2dbParser.php.in to Ido2dbParser.php.
+
+Have fun!
+
+Christian Doebler





More information about the icinga-checkins mailing list