Feature #1107

add db socket as config option in ido2db.cfg for mysql and postgresql

Added by dnsmichi over 3 years ago. Updated about 3 years ago.

Status:ResolvedStart date:01/12/2011
Priority:LowDue date:
Assignee:dnsmichi% Done:

100%

Category:Configuration
Target version:Icinga 1.x - 1.4

Description

props to sven nierlein

evaluate if possible for libdbi/libpq/ocilib

diff --git a/include/db.h b/include/db.h
index 650b3a5..d82ef31 100644
--- a/include/db.h
+++ b/include/db.h
@@ -20,6 +20,7 @@ typedef struct ndo2db_dbconfig_struct{
  char *password;
  char *dbname;
  char *dbprefix;
+ char *dbsocket;
  unsigned long max_timedevents_age;
  unsigned long max_systemcommands_age;
  unsigned long max_servicechecks_age;
diff --git a/src/db.c b/src/db.c
index e06afc1..8fb74e5 100644
--- a/src/db.c
+++ b/src/db.c
@@ -206,7 +206,7 @@ int ndo2db_db_connect(ndo2db_idi *idi){
  switch(idi->dbinfo.server_type){
  case NDO2DB_DBSERVER_MYSQL:
 #ifdef USE_MYSQL
-   if(!mysql_real_connect(&idi->dbin-fo.mysql_conn,ndo2db_db_settings.host,ndo2db_db_settings.username,ndo2db_db_settings.password,ndo2db_db_settings.dbname,ndo2db_db_settings.port,NULL,0)){
+   if(!mysql_real_connect(&idi->dbin-fo.mysql_conn,ndo2db_db_settings.host,ndo2db_db_settings.username,ndo2db_db_settings.password,ndo2db_db_settings.dbname,ndo2db_db_settings.port,ndo2db_db_settings.dbsocket,0)){

      mysql_close(&idi->dbinfo.mysql_conn);
      syslog(LOG_USER|LOG_INFO,"Error: Could not connect to MySQL database: %s",mysql_error(&idi->dbinfo.mysql_conn));
diff --git a/src/ndo2db.c b/src/ndo2db.c
index f4c6499..dfd3151 100644
--- a/src/ndo2db.c
+++ b/src/ndo2db.c
@@ -417,6 +417,10 @@ int ndo2db_process_config_var(char *arg){
  else if(!strcmp(var,"db_port")){
    ndo2db_db_settings.port=atoi(val);
          }
+ else if(!strcmp(var,"db_socket")){
+   if((ndo2db_db_settings.dbsocket=strdup(val))==NULL)
+     return NDO_ERROR;
+         }
  else if(!strcmp(var,"db_user")){
    if((ndo2db_db_settings.username=strdup(val))==NULL)
      return NDO_ERROR;

Associated revisions

Revision b3422ee1
Added by dnsmichi about 3 years ago

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

fixes #1107

History

#1 Updated by dnsmichi over 3 years ago

  • Status changed from New to Assigned
  • Assignee set to dnsmichi

libdbi mysql

http://libdbi-drivers.sourceforge.net/docs/dbd_mysql.pdf

mysql_unix_socket

so this might be implemented against mysql only.

#2 Updated by dnsmichi about 3 years ago

  • Target version set to 1.4

#3 Updated by dnsmichi about 3 years ago

  • % Done changed from 0 to 50

added db_socket in cfg, commented out db_port. then changed in my.cnf the default socket to something else.

# service ido2db stop
# vim /etc/my.cnf
# service mysqld restart (only do that on a test system with all write processes stopped!!)
# service ido2db
Mar 23 14:11:17 xxx ido2db: Error: Could not connect to mysql database: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Mar 23 14:11:17 xxx ido2db: Error: database connection failed, forced client disconnect... 

give it the correct socket like from my.cnf

#socket=/var/lib/mysql/mysql.sock
socket=/var/run/mysql/mysql.sock


into ido2db.cfg
#db_port=3306

db_socket=/var/run/mysql/mysql.sock

looks good :)

Mar 23 14:26:17 xxx ido2db: Handling client connection... 
Mar 23 14:26:17 xxx ido2db: Successfully connected to mysql database

need to test that on pgsql too, where the port just gets overwritten.

http://libdbi-drivers.sourceforge.net/docs/dbd_pgsql/options.html

#4 Updated by dnsmichi about 3 years ago

  • % Done changed from 50 to 90

the default pgsql socket is in /tmp/ named .s.PGSQL.5432

as it seems you can't change the name, but the unix_socket_directory in /var/lib/pgsql/data/postgresql.conf and restart the server.

doing this, and using the db_socket directive with the appropriate value, it takes the socket and connects flawlessly.

#5 Updated by dnsmichi about 3 years ago

  • Subject changed from add db socket as config option to add db socket as config option in ido2db.cfg for mysql and postgresql
  • Category set to Configuration

#6 Updated by dnsmichi about 3 years ago

  • Status changed from Assigned to Resolved
  • % Done changed from 90 to 100

Applied in changeset commit:b3422ee126a44b73d977e6cfbd6aa411d7e4ac61.

Also available in: Atom PDF