]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
pcie_errors plugin: possibility only to filter messages from log file.
authorKamil Wiatrowski <kamilx.wiatrowski@intel.com>
Wed, 10 May 2017 10:21:54 +0000 (11:21 +0100)
committerKamil Wiatrowski <kamilx.wiatrowski@intel.com>
Fri, 22 Nov 2019 12:31:07 +0000 (13:31 +0100)
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 <kamilx.wiatrowski@intel.com>
src/utils_message_parser.c
src/utils_message_parser.h

index 6b3e4ae8312c32815101762280b7235825b52063..dc051f36fbb45ca34a521308d1b00eca72e98fc6 100644 (file)
@@ -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,
index 4d59e6a219fa917a76c681d8cd3f7c542aa27378..2c85366d8ca0726f862c38dd5bc216904dd4a593 100644 (file)
@@ -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;