From aaba85fe00ab9efeb7ad1da4a15ea62c91ea6d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 11 Jan 2015 02:50:02 +0000 Subject: [PATCH] Implemented feature in issue #131 Adding support for Monitor Interface (issue #130) --- include/mysql_session.h | 1 + lib/Standard_ProxySQL_Admin.cpp | 35 ++++++++++++++++++++++++++++++--- lib/mysql_session.cpp | 6 ++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/include/mysql_session.h b/include/mysql_session.h index bcf001da5..3c31ad095 100644 --- a/include/mysql_session.h +++ b/include/mysql_session.h @@ -26,6 +26,7 @@ class MySQL_Session QP_out_t *qpo; int healthy; bool admin; + bool monitor; void (*admin_func) (MySQL_Session *arg, ProxySQL_Admin *, PtrSize_t *pkt); int client_fd; int server_fd; diff --git a/lib/Standard_ProxySQL_Admin.cpp b/lib/Standard_ProxySQL_Admin.cpp index 500427a4d..70b2acd01 100644 --- a/lib/Standard_ProxySQL_Admin.cpp +++ b/lib/Standard_ProxySQL_Admin.cpp @@ -779,7 +779,11 @@ void admin_session_handler(MySQL_Session *sess, ProxySQL_Admin *pa, PtrSize_t *p __run_query: if (run_query) { Standard_ProxySQL_Admin *SPA=(Standard_ProxySQL_Admin *)pa; - SPA->admindb->execute_statement(query, &error , &cols , &affected_rows , &resultset); + if (sess->monitor==false) { + SPA->admindb->execute_statement(query, &error , &cols , &affected_rows , &resultset); + } else { + SPA->monitordb->execute_statement(query, &error , &cols , &affected_rows , &resultset); + } SPA->SQLite3_to_MySQL(resultset, error, affected_rows, &sess->myprot_client); } l_free(pkt->size-sizeof(mysql_hdr),query_no_space); // it is always freed here @@ -1495,9 +1499,34 @@ bool Standard_ProxySQL_Admin::set_variable(char *name, char *value) { // this i variables.admin_credentials=strdup(value); if (update_creds && variables.admin_credentials) { #ifdef DEBUG - add_credentials((char *)"admin",variables.admin_credentials, -2); + add_credentials((char *)"admin",variables.admin_credentials, ADMIN_HOSTGROUP); +#else + add_credentials(variables.admin_credentials, ADMIN_HOSTGROUP); +#endif /* DEBUG */ + } + return true; + } else { + return false; + } + } + if (!strcmp(name,"monitor_credentials")) { + if (vallen) { + bool update_creds=false; + if ((variables.monitor_credentials==NULL) || strcmp(variables.monitor_credentials,value) ) update_creds=true; + if (update_creds && variables.monitor_credentials) { +#ifdef DEBUG + delete_credentials((char *)"monitor",variables.monitor_credentials); +#else + delete_credentials(variables.monitor_credentials); +#endif /* DEBUG */ + } + free(variables.monitor_credentials); + variables.monitor_credentials=strdup(value); + if (update_creds && variables.monitor_credentials) { +#ifdef DEBUG + add_credentials((char *)"admin",variables.monitor_credentials, MONITOR_HOSTGROUP); #else - add_credentials(variables.admin_credentials, -2); + add_credentials(variables.monitor_credentials, MONITOR_HOSTGROUP); #endif /* DEBUG */ } return true; diff --git a/lib/mysql_session.cpp b/lib/mysql_session.cpp index ff83e206f..71c338382 100644 --- a/lib/mysql_session.cpp +++ b/lib/mysql_session.cpp @@ -76,6 +76,7 @@ MySQL_Session::MySQL_Session() { qpo=NULL; healthy=1; admin=false; + monitor=false; admin_func=NULL; client_fd=0; server_fd=0; @@ -278,6 +279,11 @@ int MySQL_Session::handler() { && ( (default_hostgroup<0 && admin==true) || (default_hostgroup>=0 && admin==false) ) ) { + if (default_hostgroup<0 && admin==true) { + if (default_hostgroup==MONITOR_HOSTGROUP) { + monitor=true; + } + } l_free(pkt.size,pkt.ptr); if (client_myds->encrypted==false) { myprot_client.generate_pkt_OK(true,NULL,NULL,2,0,0,0,0,NULL);