[icinga-checkins] icinga.org: icinga-core/rbartels/cgi-current: idoutils: add db socket as config option in ido2db. cfg for mysql and postgresql #1107

git at icinga.org git at icinga.org
Fri Mar 25 16:06:48 CET 2011


Module: icinga-core
Branch: rbartels/cgi-current
Commit: b3422ee126a44b73d977e6cfbd6aa411d7e4ac61
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=b3422ee126a44b73d977e6cfbd6aa411d7e4ac61

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed Mar 23 15:09:30 2011 +0100

idoutils: add db socket as config option in ido2db.cfg for mysql and postgresql #1107

fixes #1107

---

 Changelog                                   |    2 ++
 module/idoutils/config/ido2db.cfg-sample.in |   10 ++++++++++
 module/idoutils/include/db.h                |    1 +
 module/idoutils/src/db.c                    |   17 +++++++++++++++++
 module/idoutils/src/ido2db.c                |    9 +++++++++
 5 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/Changelog b/Changelog
index 568c8f3..6e5beea 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,8 @@ ENHANCEMENTS
 * classic ui: enforce a need for comment for action taken in cmd.cgi #610
 * classic ui: Add config option to set start of week (sunday/monday) #1269
 
+* idoutils: add db socket as config option in ido2db.cfg for mysql and postgresql #1107
+
 FIXES
 * core: fix flexible downtime on service hard state change doesn't get triggered/activated #1128
 
diff --git a/module/idoutils/config/ido2db.cfg-sample.in b/module/idoutils/config/ido2db.cfg-sample.in
index ffef2d3..f8348e0 100644
--- a/module/idoutils/config/ido2db.cfg-sample.in
+++ b/module/idoutils/config/ido2db.cfg-sample.in
@@ -109,6 +109,16 @@ db_host=localhost
 db_port=3306
 
 
+# DATABASE SOCKET
+# Optional db_socket allows to specify a different socket location.
+# This will be passed to libdbi MySQL as mysql_unix_socket, while
+# PostgeSQL overrides the port, ocilib Oracle ignores this setting.
+#
+# Note: This setting overrules db_port, making it useless!
+
+#db_socket=/var/lib/mysql/mysql.sock
+
+
 
 # DATABASE NAME
 # This option specifies the name of the database that should be used.
diff --git a/module/idoutils/include/db.h b/module/idoutils/include/db.h
index 99dc0d0..c16c9f2 100644
--- a/module/idoutils/include/db.h
+++ b/module/idoutils/include/db.h
@@ -21,6 +21,7 @@ typedef struct ido2db_dbconfig_struct{
 	char *dbname;
 	char *dbprefix;
 	char *dbserver;
+	char *dbsocket;
 	unsigned long max_timedevents_age;
 	unsigned long max_systemcommands_age;
 	unsigned long max_servicechecks_age;
diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index b5f073b..d088869 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -445,6 +445,23 @@ int ido2db_db_connect(ido2db_idi *idi) {
 	dbi_conn_set_option(idi->dbinfo.dbi_conn, "dbname", ido2db_db_settings.dbname);
 	dbi_conn_set_option(idi->dbinfo.dbi_conn, "encoding", "auto");
 
+	if(ido2db_db_settings.dbsocket!=NULL){
+		/* a local db socket was desired, drop db_port settings in case */
+		dbi_conn_clear_option(idi->dbinfo.dbi_conn, "port");
+
+	        switch (idi->dbinfo.server_type) {
+	        case IDO2DB_DBSERVER_MYSQL:
+	                dbi_conn_set_option(idi->dbinfo.dbi_conn, "mysql_unix_socket", ido2db_db_settings.dbsocket);
+			break;
+		case IDO2DB_DBSERVER_PGSQL:
+			/* override the port as stated in libdbi-driver docs */
+	                dbi_conn_set_option(idi->dbinfo.dbi_conn, "port", ido2db_db_settings.dbsocket);
+			break;
+		default:
+			break;
+		}
+	}
+
 	if (dbi_conn_connect(idi->dbinfo.dbi_conn) != 0) {
 		dbi_conn_error(idi->dbinfo.dbi_conn, &dbi_error);
 		syslog(LOG_USER | LOG_INFO, "Error: Could not connect to %s database: %s", ido2db_db_settings.dbserver, dbi_error);
diff --git a/module/idoutils/src/ido2db.c b/module/idoutils/src/ido2db.c
index d3d728c..af392de 100644
--- a/module/idoutils/src/ido2db.c
+++ b/module/idoutils/src/ido2db.c
@@ -521,6 +521,10 @@ int ido2db_process_config_var(char *arg){
 		if((ido2db_db_settings.dbprefix=strdup(val))==NULL)
 			return IDO_ERROR;
 	        }
+	else if(!strcmp(var,"db_socket")){
+		if((ido2db_db_settings.dbsocket=strdup(val))==NULL)
+			return IDO_ERROR;
+	        }
 	else if(!strcmp(var,"max_timedevents_age"))
 		ido2db_db_settings.max_timedevents_age=strtoul(val,NULL,0)*60;
 	else if(!strcmp(var,"max_systemcommands_age"))
@@ -602,6 +606,7 @@ int ido2db_initialize_variables(void){
 	ido2db_db_settings.password=NULL;
 	ido2db_db_settings.dbname=NULL;
 	ido2db_db_settings.dbprefix=NULL;
+	ido2db_db_settings.dbsocket=NULL;
 	ido2db_db_settings.max_timedevents_age=0L;
 	ido2db_db_settings.max_systemcommands_age=0L;
 	ido2db_db_settings.max_servicechecks_age=0L;
@@ -667,6 +672,10 @@ int ido2db_free_program_memory(void){
 		free(ido2db_db_settings.dbprefix);
 		ido2db_db_settings.dbprefix=NULL;
 		}
+	if(ido2db_db_settings.dbsocket){
+		free(ido2db_db_settings.dbsocket);
+		ido2db_db_settings.dbsocket=NULL;
+		}
 	if(ido2db_debug_file){
 		free(ido2db_debug_file);
 		ido2db_debug_file=NULL;





More information about the icinga-checkins mailing list