Implement socket_path attribute for the IdoMysqlConnection class

fixes #7901
This commit is contained in:
Gunnar Beutner 2014-12-02 08:42:21 +01:00
parent 6c1ec9e8c0
commit 078125bdec
3 changed files with 7 additions and 3 deletions

View File

@ -1409,6 +1409,7 @@ Attributes:
----------------|----------------
host |**Optional.** MySQL database host address. Defaults to "localhost".
port |**Optional.** MySQL database port. Defaults to 3306.
socket_path |**Optional.** MySQL socket path.
user |**Optional.** MySQL database user with read/write permission to the icinga database. Defaults to "icinga".
password |**Optional.** MySQL database user's password. Defaults to "icinga".
database |**Optional.** MySQL database name. Defaults to "icinga".

View File

@ -179,17 +179,19 @@ void IdoMysqlConnection::Reconnect(void)
ClearIDCache();
String ihost, iuser, ipasswd, idb;
const char *host, *user , *passwd, *db;
String ihost, isocket_path, iuser, ipasswd, idb;
const char *host, *socket_path, *user , *passwd, *db;
long port;
ihost = GetHost();
isocket_path = GetSocketPath();
iuser = GetUser();
ipasswd = GetPassword();
idb = GetDatabase();
host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL;
port = GetPort();
socket_path = (!isocket_path.IsEmpty()) ? isocket_path.CStr() : NULL;
user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL;
passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL;
db = (!idb.IsEmpty()) ? idb.CStr() : NULL;
@ -202,7 +204,7 @@ void IdoMysqlConnection::Reconnect(void)
BOOST_THROW_EXCEPTION(std::bad_alloc());
}
if (!mysql_real_connect(&m_Connection, host, user, passwd, db, port, NULL, CLIENT_FOUND_ROWS)) {
if (!mysql_real_connect(&m_Connection, host, user, passwd, db, port, socket_path, CLIENT_FOUND_ROWS)) {
Log(LogCritical, "IdoMysqlConnection")
<< "Connection to database '" << db << "' with user '" << user << "' on '" << host << ":" << port
<< "' failed: \"" << mysql_error(&m_Connection) << "\"";

View File

@ -30,6 +30,7 @@ class IdoMysqlConnection : DbConnection
[config] int port {
default {{{ return 3306; }}}
};
[config] String socket_path;
[config] String user {
default {{{ return "icinga"; }}}
};