Blame SOURCES/0036-Rsyslog-parse-property-filters-and-file-actions-with.patch

ab36df
From 71550a96fb273e8da723e9cf6ac77bbea8480695 Mon Sep 17 00:00:00 2001
ab36df
From: Dominic Cleal <dcleal@redhat.com>
ab36df
Date: Mon, 2 Jun 2014 12:51:19 +0100
ab36df
Subject: [PATCH] Rsyslog: parse property filters and file actions with complex
ab36df
 templates
ab36df
ab36df
Fixes RHBZ#1083016
ab36df
ab36df
(cherry picked from commit 74816cdcf599cf005b78d9a686dcedc84faf38b4)
ab36df
ab36df
Conflicts:
ab36df
	NEWS
ab36df
---
ab36df
 lenses/rsyslog.aug            | 24 ++++++++++++++++++++----
ab36df
 lenses/syslog.aug             |  2 +-
ab36df
 lenses/tests/test_rsyslog.aug | 22 ++++++++++++++++++++++
ab36df
 3 files changed, 43 insertions(+), 5 deletions(-)
ab36df
ab36df
diff --git a/lenses/rsyslog.aug b/lenses/rsyslog.aug
ab36df
index 6a1b03a..943847f 100644
ab36df
--- a/lenses/rsyslog.aug
ab36df
+++ b/lenses/rsyslog.aug
ab36df
@@ -23,16 +23,21 @@ module Rsyslog =
ab36df
 
ab36df
 autoload xfm
ab36df
 
ab36df
-let macro = [ key /$[A-Za-z0-9]+/ . Sep.space . store Rx.neg1 . Util.comment_or_eol ]
ab36df
+let macro_rx = /[^,# \n\t][^#\n]*[^,# \n\t]|[^,# \n\t]/
ab36df
+let macro = [ key /$[A-Za-z0-9]+/ . Sep.space . store macro_rx . Util.comment_or_eol ]
ab36df
 
ab36df
 (* View: users
ab36df
    Map :omusrmsg: and a list of users, or a single *
ab36df
 *)
ab36df
-let omusrmsg = Util.del_str ":omusrmsg:" . 
ab36df
+let omusrmsg = Util.del_str ":omusrmsg:" .
ab36df
                  Syslog.label_opt_list_or "omusrmsg" (store Syslog.word)
ab36df
                                           Syslog.comma "*"
ab36df
 
ab36df
-let action = Syslog.action | omusrmsg
ab36df
+(* View: file_tmpl
ab36df
+   File action with a specified template *)
ab36df
+let file_tmpl = Syslog.file . [ label "template" . Util.del_str ";" . store Rx.word ]
ab36df
+
ab36df
+let action = Syslog.action | omusrmsg | file_tmpl
ab36df
 
ab36df
 (* View: entry
ab36df
    An entry contains selectors and an action
ab36df
@@ -40,7 +45,18 @@ let action = Syslog.action | omusrmsg
ab36df
 let entry = [ label "entry" . Syslog.selectors . Syslog.sep_tab .
ab36df
               [ label "action" . action ] . Util.eol ]
ab36df
 
ab36df
-let entries = ( Syslog.empty | Syslog.comment | entry | macro )*
ab36df
+(* View: prop_filter
ab36df
+   Parses property-based filters, which start with ":" and the property name *)
ab36df
+let prop_filter =
ab36df
+     let sep = Sep.comma . Util.del_ws_spc
ab36df
+  in let prop_name = [ Util.del_str ":" . label "property" . store Rx.word ]
ab36df
+  in let prop_oper = [ label "operation" . store /[A-Za-z!-]+/ ]
ab36df
+  in let prop_val  = [ label "value" . Quote.do_dquote (store /[^\n"]*/) ]
ab36df
+  in let prop_act  = [ label "action" . action ]
ab36df
+  in [ label "filter" . prop_name . sep . prop_oper . sep . prop_val .
ab36df
+       Sep.space . prop_act . Util.eol ]
ab36df
+
ab36df
+let entries = ( Syslog.empty | Syslog.comment | entry | macro | prop_filter )*
ab36df
 
ab36df
 let lns = entries . ( Syslog.program | Syslog.hostname )*
ab36df
 
ab36df
diff --git a/lenses/syslog.aug b/lenses/syslog.aug
ab36df
index 97c721e..47f52e9 100644
ab36df
--- a/lenses/syslog.aug
ab36df
+++ b/lenses/syslog.aug
ab36df
@@ -115,7 +115,7 @@ module Syslog =
ab36df
 	(* Variable: file_r
ab36df
 	 a file begins with a / and get almost anything else after
ab36df
 	 *)
ab36df
-	let file_r     = /\/[^ \t\n]+/
ab36df
+	let file_r     = /\/[^ \t\n;]+/
ab36df
 
ab36df
 	(* Variable: loghost_r
ab36df
 	 Matches a hostname, that is labels speparated by dots, labels can't
ab36df
diff --git a/lenses/tests/test_rsyslog.aug b/lenses/tests/test_rsyslog.aug
ab36df
index bf85129..46b24c3 100644
ab36df
--- a/lenses/tests/test_rsyslog.aug
ab36df
+++ b/lenses/tests/test_rsyslog.aug
ab36df
@@ -117,3 +117,25 @@ test Rsyslog.lns get conf =
ab36df
       { "omusrmsg" = "foo" }
ab36df
       { "omusrmsg" = "bar" } }
ab36df
   }
ab36df
+
ab36df
+(* Parse complex $template lines, RHBZ#1083016 *)
ab36df
+test Rsyslog.lns get "$template SpiceTmpl,\"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\\n\"\n" =
ab36df
+  { "$template" = "SpiceTmpl,\"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\\n\"" }
ab36df
+
ab36df
+(* Parse property-based filters, RHBZ#1083016 *)
ab36df
+test Rsyslog.lns get ":programname, startswith, \"spice-vdagent\" /var/log/spice-vdagent.log;SpiceTmpl\n" =
ab36df
+  { "filter"
ab36df
+    { "property" = "programname" }
ab36df
+    { "operation" = "startswith" }
ab36df
+    { "value" = "spice-vdagent" }
ab36df
+    { "action"
ab36df
+      { "file" = "/var/log/spice-vdagent.log" }
ab36df
+      { "template" = "SpiceTmpl" } } }
ab36df
+
ab36df
+test Rsyslog.lns get ":msg, !contains, \"error\" /var/log/noterror.log\n" =
ab36df
+  { "filter"
ab36df
+    { "property" = "msg" }
ab36df
+    { "operation" = "!contains" }
ab36df
+    { "value" = "error" }
ab36df
+    { "action"
ab36df
+      { "file" = "/var/log/noterror.log" } } }