From 7879a010e82e73f38953430ce1ecbc16099ed16e Mon Sep 17 00:00:00 2001 From: Unbit Date: Wed, 27 Feb 2013 04:39:55 +0100 Subject: [PATCH] backported negative --log-alarm --- core/alarm.c | 12 +++++++++--- core/uwsgi.c | 8 ++++++++ uwsgi.h | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/core/alarm.c b/core/alarm.c index 0fba913e..3df689ff 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,12 @@ 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); + } + else { + break; + } } ual = ual->next; } diff --git a/core/uwsgi.c b/core/uwsgi.c index 22d14af2..95637213 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -380,6 +380,9 @@ 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}, + {"alarm-log", 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, "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}, + {"not-alarm-log", 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 @@ -3328,6 +3331,11 @@ void uwsgi_opt_add_addr_list(char *opt, char *value, void *list) { usl->custom_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_PCRE void uwsgi_opt_add_regexp_list(char *opt, char *value, void *list) { diff --git a/uwsgi.h b/uwsgi.h index ba62b0cc..90cc7160 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -943,6 +943,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; }; @@ -2971,6 +2972,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_addr_list(char *, char *, void *); void uwsgi_opt_add_dyn_dict(char *, char *, void *); #ifdef UWSGI_PCRE