From 3fb1213dee9ffc9759ecc3430109ea76323eb931 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 10 Jun 2015 06:09:42 +0300 Subject: [PATCH] Added more error logging when monitor scripts fail. --- server/modules/monitor/galeramon.c | 18 +++++++++++++----- server/modules/monitor/mmmon.c | 16 +++++++++++++--- server/modules/monitor/monitor_common.c | 3 +++ server/modules/monitor/mysql_mon.c | 16 +++++++++++++--- server/modules/monitor/ndbclustermon.c | 16 +++++++++++++--- 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/server/modules/monitor/galeramon.c b/server/modules/monitor/galeramon.c index 6a842b8c1..07d9fd848 100644 --- a/server/modules/monitor/galeramon.c +++ b/server/modules/monitor/galeramon.c @@ -123,7 +123,7 @@ startMonitor(void *arg,void* opt) MONITOR* mon = arg; GALERA_MONITOR *handle = mon->handle; CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; - bool have_events = false; + bool have_events = false,script_error = false; if (handle != NULL) { handle->shutdown = 0; @@ -163,6 +163,7 @@ startMonitor(void *arg,void* opt) } else { + script_error = true; if(access(params->value,F_OK) == 0) { skygw_log_write(LE, @@ -175,17 +176,24 @@ startMonitor(void *arg,void* opt) "Error: The file cannot be found: %s", params->value); } - handle->script = NULL; } } else if(!strcmp(params->name,"events")) { - mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value); - have_events = true; + if(mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value) != 0) + script_error = true; + else + have_events = true; } params = params->next; } - + if(script_error) + { + skygw_log_write(LE,"Error: Errors were found in the script configuration parameters " + "for the monitor '%s'. The script will not be used.",mon->name); + free(handle->script); + handle->script = NULL; + } /** If no specific events are given, enable them all */ if(!have_events) { diff --git a/server/modules/monitor/mmmon.c b/server/modules/monitor/mmmon.c index 130cdb279..c0d54595d 100644 --- a/server/modules/monitor/mmmon.c +++ b/server/modules/monitor/mmmon.c @@ -113,7 +113,7 @@ startMonitor(void *arg,void* opt) MONITOR* mon = (MONITOR*)arg; MM_MONITOR *handle = mon->handle; CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; - bool have_events = false; + bool have_events = false,script_error = false; if (handle) { @@ -148,6 +148,7 @@ startMonitor(void *arg,void* opt) } else { + script_error = true; if(access(params->value,F_OK) == 0) { skygw_log_write(LE, @@ -165,11 +166,20 @@ startMonitor(void *arg,void* opt) } else if(!strcmp(params->name,"events")) { - mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value); - have_events = true; + if(mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value) != 0) + script_error = true; + else + have_events = true; } params = params->next; } + if(script_error) + { + skygw_log_write(LE,"Error: Errors were found in the script configuration parameters " + "for the monitor '%s'. The script will not be used.",mon->name); + free(handle->script); + handle->script = NULL; + } /** If no specific events are given, enable them all */ if(!have_events) { diff --git a/server/modules/monitor/monitor_common.c b/server/modules/monitor/monitor_common.c index e4b8e7dac..f4566c35a 100644 --- a/server/modules/monitor/monitor_common.c +++ b/server/modules/monitor/monitor_common.c @@ -343,7 +343,10 @@ int mon_parse_event_string(bool* events, size_t count,char* string) { event = mon_name_to_event(tok); if(event == UNDEFINED_MONITOR_EVENT) + { + skygw_log_write(LE,"Error: Invalid event name %s",tok); return -1; + } events[event] = true; tok = strtok_r(NULL,",| ",&saved); } diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index 6f10b0ac8..2e16afc7b 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -140,7 +140,7 @@ startMonitor(void *arg, void* opt) MONITOR* monitor = (MONITOR*)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR*)monitor->handle; CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; - bool have_events = false; + bool have_events = false,script_error = false; if (handle) { @@ -176,6 +176,7 @@ startMonitor(void *arg, void* opt) } else { + script_error = true; if(access(params->value,F_OK) == 0) { skygw_log_write(LE, @@ -193,11 +194,20 @@ startMonitor(void *arg, void* opt) } else if(!strcmp(params->name,"events")) { - mon_parse_event_string(handle->events,sizeof(handle->events),params->value); - have_events = true; + if(mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value) != 0) + script_error = true; + else + have_events = true; } params = params->next; } + if(script_error) + { + skygw_log_write(LE,"Error: Errors were found in the script configuration parameters " + "for the monitor '%s'. The script will not be used.",monitor->name); + free(handle->script); + handle->script = NULL; + } /** If no specific events are given, enable them all */ if(!have_events) { diff --git a/server/modules/monitor/ndbclustermon.c b/server/modules/monitor/ndbclustermon.c index c8790be59..9561e275e 100644 --- a/server/modules/monitor/ndbclustermon.c +++ b/server/modules/monitor/ndbclustermon.c @@ -111,7 +111,7 @@ startMonitor(void *arg,void* opt) MONITOR* mon = (MONITOR*)arg; MYSQL_MONITOR *handle = mon->handle; CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; - bool have_events = false; + bool have_events = false,script_error = false; if (handle != NULL) { @@ -140,6 +140,7 @@ startMonitor(void *arg,void* opt) } else { + script_error = true; if(access(params->value,F_OK) == 0) { skygw_log_write(LE, @@ -157,10 +158,19 @@ startMonitor(void *arg,void* opt) } else if(!strcmp(params->name,"events")) { - mon_parse_event_string(&handle->events,sizeof(handle->events),params->value); - have_events = true; + if(mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value) != 0) + script_error = true; + else + have_events = true; } params = params->next; + } + if(script_error) + { + skygw_log_write(LE,"Error: Errors were found in the script configuration parameters " + "for the monitor '%s'. The script will not be used.",mon->name); + free(handle->script); + handle->script = NULL; } /** If no specific events are given, enable them all */ if(!have_events)