diff --git a/server/modules/monitor/galeramon.c b/server/modules/monitor/galeramon.c index eb75c2160..a46df8f77 100644 --- a/server/modules/monitor/galeramon.c +++ b/server/modules/monitor/galeramon.c @@ -64,6 +64,7 @@ static void diagnostics(DCB *, void *); static MONITOR_SERVERS *get_candidate_master(MONITOR_SERVERS *); static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *, MONITOR_SERVERS *, int); static void disableMasterFailback(void *, int); +bool isGaleraEvent(monitor_event_t event); static MONITOR_OBJECT MyObject = { startMonitor, @@ -570,15 +571,19 @@ monitor_event_t evtype; { /** Execute monitor script if a server state has changed */ - if(mon_status_changed(ptr) && (evtype = mon_get_event_type(ptr)) != UNDEFINED_MONITOR_EVENT) + if(mon_status_changed(ptr)) { - skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s", - ptr->server->unique_name, - ptr->server->name,ptr->server->port, - mon_get_event_name(ptr)); - if(handle->script && handle->events[evtype]) + evtype = mon_get_event_type(ptr); + if(isGaleraEvent(evtype)) { - monitor_launch_script(mon,ptr,handle->script); + skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s", + ptr->server->unique_name, + ptr->server->name,ptr->server->port, + mon_get_event_name(ptr)); + if(handle->script && handle->events[evtype]) + { + monitor_launch_script(mon,ptr,handle->script); + } } } ptr = ptr->next; @@ -687,3 +692,40 @@ availableWhenDonor(void *arg, int disable) GALERA_MONITOR *handle = (GALERA_MONITOR *)arg; memcpy(&handle->availableWhenDonor, &disable, sizeof(int)); } + +static monitor_event_t galera_events[] = { + MASTER_DOWN_EVENT, + MASTER_UP_EVENT, + SLAVE_DOWN_EVENT, + SLAVE_UP_EVENT, + SERVER_DOWN_EVENT, + SERVER_UP_EVENT, + SYNCED_DOWN_EVENT, + SYNCED_UP_EVENT, + DONOR_DOWN_EVENT, + DONOR_UP_EVENT, + LOST_MASTER_EVENT, + LOST_SLAVE_EVENT, + LOST_SYNCED_EVENT, + LOST_DONOR_EVENT, + NEW_MASTER_EVENT, + NEW_SLAVE_EVENT, + NEW_SYNCED_EVENT, + NEW_DONOR_EVENT, + MAX_MONITOR_EVENT +}; +/** + * Check if the Galera monitor is monitoring this event type. + * @param event Event to check + * @return True if the event is monitored, false if it is not + * */ +bool isGaleraEvent(monitor_event_t event) +{ + int i; + for(i = 0;galera_events[i] != MAX_MONITOR_EVENT;i++) + { + if(event == galera_events[i]) + return true; + } + return false; +} \ No newline at end of file diff --git a/server/modules/monitor/mmmon.c b/server/modules/monitor/mmmon.c index 8188c40c9..0e54d5299 100644 --- a/server/modules/monitor/mmmon.c +++ b/server/modules/monitor/mmmon.c @@ -594,16 +594,19 @@ size_t nrounds = 0; monitor_event_t evtype; while(ptr) { - /** Execute monitor script if a server state has changed */ - if(mon_status_changed(ptr) && (evtype = mon_get_event_type(ptr)) != UNDEFINED_MONITOR_EVENT) + if(mon_status_changed(ptr)) { - skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s", - ptr->server->unique_name, - ptr->server->name,ptr->server->port, - mon_get_event_name(ptr)); - if(handle->script && handle->events[evtype]) + evtype = mon_get_event_type(ptr); + if(isMySQLEvent(evtype)) { - monitor_launch_script(mon,ptr,handle->script); + skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s", + ptr->server->unique_name, + ptr->server->name,ptr->server->port, + mon_get_event_name(ptr)); + if(handle->script && handle->events[evtype]) + { + monitor_launch_script(mon,ptr,handle->script); + } } } ptr = ptr->next; @@ -678,3 +681,32 @@ MONITOR_SERVERS *ptr; } } + +static monitor_event_t mysql_events[] = { + MASTER_DOWN_EVENT, + MASTER_UP_EVENT, + SLAVE_DOWN_EVENT, + SLAVE_UP_EVENT, + SERVER_DOWN_EVENT, + SERVER_UP_EVENT, + LOST_MASTER_EVENT, + LOST_SLAVE_EVENT, + NEW_MASTER_EVENT, + NEW_SLAVE_EVENT, + MAX_MONITOR_EVENT +}; +/** + * Check if the MM monitor is monitoring this event type. + * @param event Event to check + * @return True if the event is monitored, false if it is not + * */ +bool isMySQLEvent(monitor_event_t event) +{ + int i; + for(i = 0;mysql_events[i] != MAX_MONITOR_EVENT;i++) + { + if(event == mysql_events[i]) + return true; + } + return false; +} \ No newline at end of file diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index 3a6d22391..75f7027c4 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -80,7 +80,7 @@ static MONITOR_SERVERS *get_replication_tree(MONITOR *, int); static void set_master_heartbeat(MYSQL_MONITOR *, MONITOR_SERVERS *); static void set_slave_heartbeat(MONITOR *, MONITOR_SERVERS *); static int add_slave_to_master(long *, int, long); - +bool isMySQLEvent(monitor_event_t event); static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, @@ -693,15 +693,19 @@ int log_no_master = 1; while(ptr) { /** Execute monitor script if a server state has changed */ - if(mon_status_changed(ptr) && (evtype = mon_get_event_type(ptr)) != UNDEFINED_MONITOR_EVENT) + if(mon_status_changed(ptr)) { - skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s", - ptr->server->unique_name, - ptr->server->name,ptr->server->port, - mon_get_event_name(ptr)); - if(handle->script && handle->events[evtype]) + evtype = mon_get_event_type(ptr); + if(isMySQLEvent(evtype)) { - monitor_launch_script(mon,ptr,handle->script); + skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s", + ptr->server->unique_name, + ptr->server->name,ptr->server->port, + mon_get_event_name(ptr)); + if(handle->script && handle->events[evtype]) + { + monitor_launch_script(mon,ptr,handle->script); + } } } ptr = ptr->next; @@ -1193,3 +1197,32 @@ static int add_slave_to_master(long *slaves_list, int list_size, long node_id) { } return 0; } + +static monitor_event_t mysql_events[] = { + MASTER_DOWN_EVENT, + MASTER_UP_EVENT, + SLAVE_DOWN_EVENT, + SLAVE_UP_EVENT, + SERVER_DOWN_EVENT, + SERVER_UP_EVENT, + LOST_MASTER_EVENT, + LOST_SLAVE_EVENT, + NEW_MASTER_EVENT, + NEW_SLAVE_EVENT, + MAX_MONITOR_EVENT +}; +/** + * Check if the MySQL monitor is monitoring this event type. + * @param event Event to check + * @return True if the event is monitored, false if it is not + * */ +bool isMySQLEvent(monitor_event_t event) +{ + int i; + for(i = 0;mysql_events[i] != MAX_MONITOR_EVENT;i++) + { + if(event == mysql_events[i]) + return true; + } + return false; +} \ No newline at end of file diff --git a/server/modules/monitor/ndbclustermon.c b/server/modules/monitor/ndbclustermon.c index ad41ab1e8..88444aaaf 100644 --- a/server/modules/monitor/ndbclustermon.c +++ b/server/modules/monitor/ndbclustermon.c @@ -52,6 +52,7 @@ MODULE_INFO info = { static void *startMonitor(void *,void*); static void stopMonitor(void *); static void diagnostics(DCB *, void *); +bool isNdbEvent(monitor_event_t event); static MONITOR_OBJECT MyObject = { startMonitor, @@ -402,18 +403,57 @@ size_t nrounds = 0; while(ptr) { /** Execute monitor script if a server state has changed */ - if(mon_status_changed(ptr) && (evtype = mon_get_event_type(ptr)) != UNDEFINED_MONITOR_EVENT) + if(mon_status_changed(ptr)) { - skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s", - ptr->server->unique_name, - ptr->server->name,ptr->server->port, - mon_get_event_name(ptr)); - if(handle->script && handle->events[evtype]) + evtype = mon_get_event_type(ptr); + if(isNdbEvent(evtype)) { - monitor_launch_script(mon,ptr,handle->script); + skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s", + ptr->server->unique_name, + ptr->server->name,ptr->server->port, + mon_get_event_name(ptr)); + if(handle->script && handle->events[evtype]) + { + monitor_launch_script(mon,ptr,handle->script); + } } } ptr = ptr->next; } } } + + +static monitor_event_t ndb_events[] = { + MASTER_DOWN_EVENT, + MASTER_UP_EVENT, + SLAVE_DOWN_EVENT, + SLAVE_UP_EVENT, + SERVER_DOWN_EVENT, + SERVER_UP_EVENT, + NDB_UP_EVENT, + NDB_DOWN_EVENT, + LOST_MASTER_EVENT, + LOST_SLAVE_EVENT, + LOST_NDB_EVENT, + NEW_MASTER_EVENT, + NEW_SLAVE_EVENT, + NEW_NDB_EVENT, + MAX_MONITOR_EVENT +}; + +/** + * Check if the event type is one the ndbcustermonitor is interested in. + * @param event Event to check + * @return True if the event is monitored, false if it is not + */ +bool isNdbEvent(monitor_event_t event) +{ + int i; + for(i = 0;ndb_events[i] != MAX_MONITOR_EVENT;i++) + { + if(event == ndb_events[i]) + return true; + } + return false; +} \ No newline at end of file