Added filtering of monitor events.
This commit is contained in:
@ -110,6 +110,8 @@ startMonitor(void *arg,void* opt)
|
||||
MONITOR* mon = (MONITOR*)arg;
|
||||
MYSQL_MONITOR *handle = mon->handle;
|
||||
CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
|
||||
bool have_events = false;
|
||||
|
||||
if (handle != NULL)
|
||||
{
|
||||
handle->shutdown = 0;
|
||||
@ -120,6 +122,7 @@ startMonitor(void *arg,void* opt)
|
||||
return NULL;
|
||||
handle->shutdown = 0;
|
||||
handle->id = MONITOR_DEFAULT_ID;
|
||||
memset(handle->events,false,sizeof(handle->events));
|
||||
spinlock_init(&handle->lock);
|
||||
}
|
||||
while(params)
|
||||
@ -130,6 +133,17 @@ startMonitor(void *arg,void* opt)
|
||||
free(handle->script);
|
||||
handle->script = strdup(params->value);
|
||||
}
|
||||
else if(!strcmp(params->name,"events"))
|
||||
{
|
||||
mon_parse_event_string(&handle->events,sizeof(handle->events),params->value);
|
||||
have_events = true;
|
||||
}
|
||||
params = params->next;
|
||||
}
|
||||
/** If no specific events are given, enable them all */
|
||||
if(!have_events)
|
||||
{
|
||||
memset(handle->events,true,sizeof(handle->events));
|
||||
}
|
||||
handle->tid = (THREAD)thread_start(monitorMain, mon);
|
||||
return handle;
|
||||
@ -383,17 +397,18 @@ size_t nrounds = 0;
|
||||
}
|
||||
|
||||
ptr = mon->databases;
|
||||
monitor_event_t evtype;
|
||||
|
||||
while(ptr)
|
||||
{
|
||||
/** Execute monitor script if a server state has changed */
|
||||
if(mon_status_changed(ptr) && mon_get_event_type(ptr) != UNDEFINED_MONITOR_EVENT)
|
||||
if(mon_status_changed(ptr) && (evtype = mon_get_event_type(ptr)) != UNDEFINED_MONITOR_EVENT)
|
||||
{
|
||||
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)
|
||||
if(handle->script && handle->events[evtype])
|
||||
{
|
||||
monitor_launch_script(mon,ptr,handle->script);
|
||||
}
|
||||
|
Reference in New Issue
Block a user