Evening,

one little message before falling asleep. When creating hierarichies
of nested patterns, I needed to define a "catch-all" pattern, a
default match. It can not be made using regexp .*, because such a
regexp would match any sibling patterns as well and, due to
pm_pattern's MFU reordering, would eventually override them.

The new "default" pattern is a <pattern>, which contains no
<matchfield> elements. In a list of sibling <pattern>s, there can be
only up to one "default" pattern. It is always evaluated last and
always matches.

Milan
diff -Naur nxlog-ce-2.8.1248.old/src/modules/processor/pattern/patterndb.c nxlog-ce-2.8.1248/src/modules/processor/pattern/patterndb.c
--- nxlog-ce-2.8.1248.old/src/modules/processor/pattern/patterndb.c	2016-01-10 19:53:55.107329669 +0100
+++ nxlog-ce-2.8.1248/src/modules/processor/pattern/patterndb.c	2016-01-10 19:55:13.822171267 +0100
@@ -5,6 +5,7 @@
  * Author: Botond Botyanszki <botond.botyans...@nxlog.org>
  * Modified: Milan Krcmar <milan.krc...@gmail.com> Sun, 10 Jan 2016
  * - recursive (nested) <pattern> elements
+ * - default <pattern> element (without <matchfield>s)
  */
 
 #include "patterndb.h"
@@ -88,12 +89,23 @@
     ASSERT(patterns != NULL);
     ASSERT(pattern != NULL);
 
-    if ( NX_DLIST_FIRST(pattern->matchfields) == NULL )
+    // do we already have a 'default' pattern?
+    if ( NX_DLIST_LAST(patterns) != NULL &&
+         NX_DLIST_EMPTY(NX_DLIST_LAST(patterns)->matchfields) )
+    {
+        if ( NX_DLIST_EMPTY(pattern->matchfields) )
+        { // the added pattern is also 'default'
+	    throw_msg("can not declare more than one default pattern");
+        }
+        else
+        {
+            NX_DLIST_INSERT_BEFORE(patterns, NX_DLIST_LAST(patterns), pattern, link);
+        }
+    }
+    else
     {
-	throw_msg("pattern has no matchfields");
+        NX_DLIST_INSERT_TAIL(patterns, pattern, link);
     }
-    NX_DLIST_INSERT_TAIL(patterns, pattern, link);
-
 }
 
 
@@ -619,7 +631,8 @@
 
 	    (pattern->matchcnt)++;
 	    if ( ((tmppattern = NX_DLIST_PREV(pattern, link)) != NULL) &&
-		 (tmppattern->matchcnt < pattern->matchcnt) )
+		 (tmppattern->matchcnt < pattern->matchcnt) &&
+                 (NX_DLIST_LAST(pattern->matchfields) != NULL) )
 	    { // advance pattern in list for optimized matching
 		NX_DLIST_REMOVE(patterns, pattern, link);
 		NX_DLIST_INSERT_BEFORE(patterns, tmppattern, pattern, link);
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
nxlog-ce-users mailing list
nxlog-ce-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nxlog-ce-users

Reply via email to