From b358c46413cb7b2355bc93dc66fd07edd69f3b86 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 7 Dec 2012 10:58:58 +0100 Subject: [PATCH] added support for negative regexp in alarm-log --- core/alarm.c | 10 +++++++--- core/uwsgi.c | 8 +++++++- uwsgi.h | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/alarm.c b/core/alarm.c index 0fba913e..ec76287d 100644 --- a/core/alarm.c +++ b/core/alarm.c @@ -136,7 +136,7 @@ static struct uwsgi_alarm_instance *uwsgi_alarm_get_instance(char *name) { } -static int uwsgi_alarm_log_add(char *alarms, char *regexp) { +static int uwsgi_alarm_log_add(char *alarms, char *regexp, int negate) { struct uwsgi_alarm_log *old_ual = NULL, *ual = uwsgi.alarm_logs; while (ual) { @@ -148,6 +148,7 @@ static int uwsgi_alarm_log_add(char *alarms, char *regexp) { if (uwsgi_regexp_build(regexp, &ual->pattern, &ual->pattern_extra)) { return -1; } + ual->negate = negate; if (old_ual) { old_ual->next = ual; @@ -223,7 +224,7 @@ void uwsgi_alarms_init() { *space = 0; char *regexp = space + 1; // here the log-alarm is created - if (uwsgi_alarm_log_add(line, regexp)) { + if (uwsgi_alarm_log_add(line, regexp, usl->custom)) { uwsgi_log("invalid log-alarm: %s\n", usl->value); exit(1); } @@ -239,7 +240,10 @@ void uwsgi_alarm_log_check(char *msg, size_t len) { struct uwsgi_alarm_log *ual = uwsgi.alarm_logs; while (ual) { if (uwsgi_regexp_match(ual->pattern, ual->pattern_extra, msg, len) >= 0) { - uwsgi_alarm_log_run(ual, msg, len); + if (!ual->negate) { + uwsgi_alarm_log_run(ual, msg, len); + } + break; } ual = ual->next; } diff --git a/core/uwsgi.c b/core/uwsgi.c index da06731e..4015e89f 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -399,7 +399,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"alarm", required_argument, 0, "create a new alarm, syntax: ", uwsgi_opt_add_string_list, &uwsgi.alarm_list, UWSGI_OPT_MASTER | UWSGI_OPT_LOG_MASTER}, {"alarm-freq", required_argument, 0, "tune the anti-loop alam system (default 3 seconds)", uwsgi_opt_set_int, &uwsgi.alarm_freq, 0}, {"log-alarm", required_argument, 0, "raise the specified alarm when a log line matches the specified regexp, syntax: [,alarm...] ", uwsgi_opt_add_string_list, &uwsgi.alarm_logs_list, UWSGI_OPT_MASTER | UWSGI_OPT_LOG_MASTER}, - {"not-log-alarm", required_argument, 0, "raise the specified alarm when a log line DO NOT matches the specified regexp, syntax: [,alarm...] ", uwsgi_opt_add_string_list, &uwsgi.not_alarm_logs_list, UWSGI_OPT_MASTER | UWSGI_OPT_LOG_MASTER}, + {"not-log-alarm", required_argument, 0, "skip the specified alarm when a log line matches the specified regexp, syntax: [,alarm...] ", uwsgi_opt_add_string_list_custom, &uwsgi.alarm_logs_list, UWSGI_OPT_MASTER | UWSGI_OPT_LOG_MASTER}, {"alarm-list", no_argument, 0, "list enabled alarms", uwsgi_opt_true, &uwsgi.alarms_list, 0}, {"alarms-list", no_argument, 0, "list enabled alarms", uwsgi_opt_true, &uwsgi.alarms_list, 0}, #endif @@ -3339,6 +3339,12 @@ void uwsgi_opt_add_string_list(char *opt, char *value, void *list) { uwsgi_string_new_list(ptr, value); } +void uwsgi_opt_add_string_list_custom(char *opt, char *value, void *list) { + struct uwsgi_string_list **ptr = (struct uwsgi_string_list **) list; + struct uwsgi_string_list *usl = uwsgi_string_new_list(ptr, value); + usl->custom = 1; +} + #ifdef UWSGI_SSL void uwsgi_opt_sni(char *opt, char *value, void *foobar) { char *client_ca = NULL; diff --git a/uwsgi.h b/uwsgi.h index 355c4c79..465f9ed7 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -947,6 +947,7 @@ struct uwsgi_alarm_ll { struct uwsgi_alarm_log { pcre *pattern; pcre_extra *pattern_extra; + int negate; struct uwsgi_alarm_ll *alarms; struct uwsgi_alarm_log *next; }; @@ -1533,7 +1534,6 @@ struct uwsgi_server { int alarm_freq; struct uwsgi_string_list *alarm_list; struct uwsgi_string_list *alarm_logs_list; - struct uwsgi_string_list *not_alarm_logs_list; struct uwsgi_alarm *alarms; struct uwsgi_alarm_instance *alarm_instances; struct uwsgi_alarm_log *alarm_logs; @@ -3063,6 +3063,7 @@ void uwsgi_opt_set_str(char *, char *, void *); void uwsgi_opt_set_logger(char *, char *, void *); void uwsgi_opt_set_str_spaced(char *, char *, void *); void uwsgi_opt_add_string_list(char *, char *, void *); +void uwsgi_opt_add_string_list_custom(char *, char *, void *); void uwsgi_opt_add_dyn_dict(char *, char *, void *); #ifdef UWSGI_PCRE void uwsgi_opt_pcre_jit(char *, char *, void *);