From: Kamil Wiatrowski Date: Wed, 10 May 2017 10:21:54 +0000 (+0100) Subject: pcie_errors plugin: possibility only to filter messages from log file. X-Git-Tag: collectd-5.11.0~18^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0c75f7104539ac54ce726f086ad584d22d24964;p=thirdparty%2Fcollectd.git pcie_errors plugin: possibility only to filter messages from log file. Add new possible value for submatch index: -1. For this value do not add the matched string to results. It can be used to only filter the required messages from syslog without adding the match to result. Change-Id: I93d9595be77427c135cc09baac901cd919d6c27e Signed-off-by: Kamil Wiatrowski --- diff --git a/src/utils_message_parser.c b/src/utils_message_parser.c index 6b3e4ae83..dc051f36f 100644 --- a/src/utils_message_parser.c +++ b/src/utils_message_parser.c @@ -70,8 +70,6 @@ static void message_item_assembly(parser_job_data *self, checked_match *cm, sstrncpy(msg_it->name, (cm->msg_pattern).name, sizeof(msg_it->name)); sstrncpy(msg_it->value, matches[cm->msg_pattern.submatch_idx], sizeof(msg_it->value)); - self->messages_storage[self->message_idx] - .matched_patterns_check[cm->msg_pattern_idx] = 1; ++(self->message_item_idx); } @@ -155,8 +153,8 @@ static int message_assembler(const char *row, char *const *matches, checked_match *cm = (checked_match *)user_data; parser_job_data *parser_job = cm->parser_job; - if (cm->msg_pattern.submatch_idx < 0 || - cm->msg_pattern.submatch_idx >= matches_num) { + if (cm->msg_pattern.submatch_idx < -1 || + cm->msg_pattern.submatch_idx >= (int) matches_num) { ERROR(UTIL_NAME ": Invalid target submatch index: %d", cm->msg_pattern.submatch_idx); return -1; @@ -186,7 +184,12 @@ static int message_assembler(const char *row, char *const *matches, return 0; } /* Populate message items */ - parser_job->message_item_assembly(parser_job, cm, matches); + if (cm->msg_pattern.submatch_idx >= 0) + parser_job->message_item_assembly(parser_job, cm, matches); + + /* Mark pattern as checked */ + parser_job->messages_storage[parser_job->message_idx] + .matched_patterns_check[cm->msg_pattern_idx] = 1; /* Handle message ending */ if (strcmp((cm->msg_pattern).regex, diff --git a/src/utils_message_parser.h b/src/utils_message_parser.h index 4d59e6a21..2c85366d8 100644 --- a/src/utils_message_parser.h +++ b/src/utils_message_parser.h @@ -43,7 +43,7 @@ typedef struct message_item_pattern_t { */ char *regex; /* Index of regex submatch that is stored as result. Value 0 takes whole - * match result */ + * match result. Value -1 does not add result to message item. */ int submatch_idx; /* Regular expression that excludes string from further processing */ char *excluderegex;