diff --git a/core/Makefile b/core/Makefile index b80bdf641..79cf3dcb0 100644 --- a/core/Makefile +++ b/core/Makefile @@ -32,8 +32,6 @@ # are behind SS_DEBUG macros. # 29/06/13 Vilho Raatikka Reverted Query classifier changes because # gateway needs mysql client lib, not qc. -# 03/07/13 Vilho Raatikka Added target 'links' which creates links -# to libraries needed by gateway. include ../../build_gateway.inc @@ -93,21 +91,4 @@ install: maxscale @mkdir -p $(DEST)/bin install -D $< $(DEST)/bin -links: - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/routing/libdebugcli.so \ - ./libdebugcli.so - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/routing/libreadconnroute.so \ - libreadconnroute.so - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/routing/readwritesplit/libreadwritesplit.so \ - libreadwritesplit.so - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/protocol/libMySQLClient.so \ - libMySQLClient.so - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/protocol/libMySQLBackend.so \ - libMySQLBackend.so - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/protocol/libtelnetd.so \ - libtelnetd.so - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/protocol/libHTTPD.so libHTTPD.so - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/routing/libtestroute.so libtestroute.so - - ln -s $(ROOT_PATH)/epoll_v1.0/modules/monitor/libmysqlmon.so libmysqlmon.so - include depend.mk diff --git a/core/config.c b/core/config.c index 0c80b6ce5..267009439 100644 --- a/core/config.c +++ b/core/config.c @@ -24,7 +24,8 @@ * * Date Who Description * 21/06/13 Mark Riddoch Initial implementation - * 08/07/13 mark Riddoch Addition on monitor module support + * 08/07/13 Mark Riddoch Addition on monitor module support + * 23/07/13 Mark Riddoch Addition on default monitor password * * @endverbatim */ @@ -256,6 +257,8 @@ CONFIG_CONTEXT *obj; { char *module = config_get_value(obj->parameters, "module"); char *servers = config_get_value(obj->parameters, "servers"); + char *user = config_get_value(obj->parameters, "user"); + char *passwd = config_get_value(obj->parameters, "passwd"); if (module) { obj->element = monitor_alloc(obj->object, module); @@ -274,6 +277,10 @@ CONFIG_CONTEXT *obj; s = strtok(NULL, ","); } } + if (obj->element && user && passwd) + { + monitorAddUser(obj->element, user, passwd); + } } } diff --git a/core/monitor.c b/core/monitor.c index e90eac94c..1ba454a10 100644 --- a/core/monitor.c +++ b/core/monitor.c @@ -114,3 +114,17 @@ monitorAddServer(MONITOR *mon, SERVER *server) { mon->module->registerServer(mon->handle, server); } + +/** + * Add a default user to the monitor. This user is used to connect to the + * monitored databases but may be overriden on a per server basis. + * + * @param mon The monitor instance + * @param user The default username to use when connecting + * @param passwd The default password associated to the default user. + */ +void +monitorAddUser(MONITOR *mon, char *user, char *passwd) +{ + mon->module->defaultUser(mon->handle, user, passwd); +} diff --git a/core/server.c b/core/server.c index 5d1698edf..30c51411a 100644 --- a/core/server.c +++ b/core/server.c @@ -63,6 +63,8 @@ SERVER *server; memset(&server->stats, 0, sizeof(SERVER_STATS)); server->status = SERVER_RUNNING; server->nextdb = NULL; + server->monuser = NULL; + server->monpw = NULL; spinlock_acquire(&server_spin); server->next = allServers; diff --git a/include/monitor.h b/include/monitor.h index eaed0a912..8b9a0b5c8 100644 --- a/include/monitor.h +++ b/include/monitor.h @@ -61,6 +61,7 @@ typedef struct { void (*stopMonitor)(void *); void (*registerServer)(void *, SERVER *); void (*unregisterServer)(void *, SERVER *); + void (*defaultUser)(void *, char *, char *); } MONITOR_OBJECT; /** @@ -76,4 +77,5 @@ typedef struct monitor { extern MONITOR *monitor_alloc(char *, char *); extern void monitor_free(MONITOR *); extern void monitorAddServer(MONITOR *, SERVER *); +extern void monitorAddUser(MONITOR *, char *, char *); #endif diff --git a/modules/monitor/galera_mon.c b/modules/monitor/galera_mon.c index 294f54afd..b4cbedb79 100644 --- a/modules/monitor/galera_mon.c +++ b/modules/monitor/galera_mon.c @@ -47,8 +47,9 @@ static void *startMonitor(); static void stopMonitor(void *); static void registerServer(void *, SERVER *); static void unregisterServer(void *, SERVER *); +static void defaultUsers(void *, char *, char *); -static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer }; +static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUser }; /** * Implementation of the mandatory version entry point @@ -101,6 +102,8 @@ MYSQL_MONITOR *handle; return NULL; handle->databases = NULL; handle->shutdown = 0; + handle->defaultUser = NULL; + handle->deaultPasswd = NULL; spinlock_init(&handle->lock); thread_start(monitorMain, handle); return handle; @@ -189,25 +192,54 @@ MONITOR_SERVERS *ptr, *lptr; spinlock_release(&handle->lock); } +/** + * Set the default username and password to use to monitor if the server does not + * override this. + * + * @param arg The handle allocated by startMonitor + * @param uname The default user name + * @param passwd The default password + */ +static void +defaultUser(void *arg, char *uname, char *passwd) +{ +MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; + + if (handle->defaultUser) + free(handle->defaultUser); + if (handle->defaultPasswd) + free(handle->defaultPasswd); + handle->defaultUser = strdup(uname); + handle->defaultPasswd = strdup(passwd); +} + /** * Monitor an individual server * * @param database The database to probe */ static void -monitorDatabase(MONITOR_SERVERS *database) +monitorDatabase(MONITOR_SERVERS *database, char *defaultUser, char *defaultPasswd) { MYSQL_ROW row; MYSQL_RES *result; int num_fields; int isjoined = 0; +char *uname = defaultUser, *passwd = defaultPasswd; + + if (database->server->monuser != NULL) + { + uname = database->server->monuser; + passwd = database->server->monpw; + } + if (uname == NULL) + return; if (database->con == NULL || mysql_ping(database->con) != 0) { database->con = mysql_init(NULL); if (mysql_real_connect(database->con, database->server->name, - database->server->monuser, database->server->monpw, - NULL, database->server->port, NULL, 0) == NULL) + uname, passwd, NULL, database->server->port, NULL, 0) == NULL) { server_clear_status(database->server, SERVER_RUNNING); return; @@ -265,7 +297,7 @@ MONITOR_SERVERS *ptr; ptr = handle->databases; while (ptr) { - monitorDatabase(ptr); + monitorDatabase(ptr, handle->defaultUser, handle->defaultPasswd); ptr = ptr->next; } thread_millisleep(10000); diff --git a/modules/monitor/mysql_mon.c b/modules/monitor/mysql_mon.c index 9de17356b..0fb326888 100644 --- a/modules/monitor/mysql_mon.c +++ b/modules/monitor/mysql_mon.c @@ -49,8 +49,9 @@ static void *startMonitor(); static void stopMonitor(void *); static void registerServer(void *, SERVER *); static void unregisterServer(void *, SERVER *); +static void defaultUser(void *, char *, char *); -static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer }; +static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUser }; /** * Implementation of the mandatory version entry point @@ -103,6 +104,8 @@ MYSQL_MONITOR *handle; return NULL; handle->databases = NULL; handle->shutdown = 0; + handle->defaultUser = NULL; + handle->defaultPasswd = NULL; spinlock_init(&handle->lock); thread_start(monitorMain, handle); return handle; @@ -191,25 +194,55 @@ MONITOR_SERVERS *ptr, *lptr; spinlock_release(&handle->lock); } +/** + * Set the default username and password to use to monitor if the server does not + * override this. + * + * @param arg The handle allocated by startMonitor + * @param uname The default user name + * @param passwd The default password + */ +static void +defaultUser(void *arg, char *uname, char *passwd) +{ +MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; + + if (handle->defaultUser) + free(handle->defaultUser); + if (handle->defaultPasswd) + free(handle->defaultPasswd); + handle->defaultUser = strdup(uname); + handle->defaultPasswd = strdup(passwd); +} + /** * Monitor an individual server * * @param database The database to probe + * @param defaultUser Default username for the monitor + * @param defaultPasswd Default password for the monitor */ static void -monitorDatabase(MONITOR_SERVERS *database) +monitorDatabase(MONITOR_SERVERS *database, char *defaultUser, char *defaultPasswd) { MYSQL_ROW row; MYSQL_RES *result; int num_fields; int ismaster = 0, isslave = 0; +char *uname = defaultUser, *passwd = defaultPasswd; + if (database->server->monuser != NULL) + { + uname = database->server->monuser; + passwd = database->server->monpw; + } + if (uname == NULL) + return; if (database->con == NULL || mysql_ping(database->con) != 0) { database->con = mysql_init(NULL); if (mysql_real_connect(database->con, database->server->name, - database->server->monuser, database->server->monpw, - NULL, database->server->port, NULL, 0) == NULL) + uname, passwd, NULL, database->server->port, NULL, 0) == NULL) { server_clear_status(database->server, SERVER_RUNNING); return; @@ -300,7 +333,7 @@ MONITOR_SERVERS *ptr; ptr = handle->databases; while (ptr) { - monitorDatabase(ptr); + monitorDatabase(ptr, handle->defaultUser, handle->defaultPasswd); ptr = ptr->next; } thread_millisleep(10000); diff --git a/modules/monitor/mysqlmon.h b/modules/monitor/mysqlmon.h index da8d42960..28678ef71 100644 --- a/modules/monitor/mysqlmon.h +++ b/modules/monitor/mysqlmon.h @@ -50,6 +50,8 @@ typedef struct monitor_servers { typedef struct { SPINLOCK lock; /**< The monitor spinlock */ int shutdown; /**< Flag to shutdown the monitor thread */ + char *defaultUser; /**< Default username for monitoring */ + char *defaultPasswd; /**< Default password for monitoring */ MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */ } MYSQL_MONITOR; #endif