From 422c0afd40606e7f22304ea11086ea9e56da2579 Mon Sep 17 00:00:00 2001 From: Mirko Buffoni Date: Wed, 29 Oct 2008 12:24:04 +0100 Subject: [PATCH] mysql plugin: Allow configuration of `Port' and `Socket'. Hi, I have a patch for mysql collectd library. The patch allow to specify also Port and Socket parameters for those who have a non-standard configuration of mysql. It's very straightforward. If accepted, there is only to change documentation and config file to reflect the new parameters. Enjoy Mirko Signed-off-by: Florian Forster --- src/mysql.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mysql.c b/src/mysql.c index 4e72b5bf..08df3fa8 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -38,14 +38,18 @@ static const char *config_keys[] = "User", "Password", "Database", + "Port", + "Socket", NULL }; -static int config_keys_num = 4; +static int config_keys_num = 6; static char *host = "localhost"; static char *user; static char *pass; static char *db = NULL; +static char *socket = NULL; +static int port = 0; static MYSQL *getconnection (void) { @@ -88,7 +92,7 @@ static MYSQL *getconnection (void) return (NULL); } - if (mysql_real_connect (con, host, user, pass, db, 0, NULL, 0) == NULL) + if (mysql_real_connect (con, host, user, pass, db, port, socket, 0) == NULL) { ERROR ("mysql_real_connect failed: %s", mysql_error (con)); state = 0; @@ -113,6 +117,10 @@ static int config (const char *key, const char *value) return ((pass = strdup (value)) == NULL ? 1 : 0); else if (strcasecmp (key, "database") == 0) return ((db = strdup (value)) == NULL ? 1 : 0); + else if (strcasecmp (key, "socket") == 0) + return ((socket = strdup (value)) == NULL ? 1 : 0); + else if (strcasecmp (key, "port") == 0) + return ((port = atoi (value)) == NULL ? 1 : 0); else return (-1); } -- 2.11.0