Skip to content

Commit

Permalink
Rsyslog: support multiple actions in filters and selectors (#653)
Browse files Browse the repository at this point in the history
raphink authored Nov 12, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 686e32f commit 5181105
Showing 2 changed files with 45 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lenses/rsyslog.aug
Original file line number Diff line number Diff line change
@@ -65,11 +65,17 @@ let hostname = [ label "hostname" .
( Syslog.plus | [ Build.xchgs "-" "reverse" ] ) .
Syslog.hostnames . Util.eol . Syslog.entries ]

(* View: actions *)
let actions =
let prop_act = [ label "action" . action ]
in let act_sep = del /[ \t]*\n&[ \t]*/ "\n& "
in Build.opt_list prop_act act_sep

(* View: entry
An entry contains selectors and an action
*)
let entry = [ label "entry" . Syslog.selectors . Syslog.sep_tab .
[ label "action" . action ] . Util.eol ]
actions . Util.eol ]

(* View: prop_filter
Parses property-based filters, which start with ":" and the property name *)
@@ -78,9 +84,8 @@ let prop_filter =
in let prop_name = [ Util.del_str ":" . label "property" . store Rx.word ]
in let prop_oper = [ label "operation" . store /[A-Za-z!-]+/ ]
in let prop_val = [ label "value" . Quote.do_dquote (store /[^\n"]*/) ]
in let prop_act = [ label "action" . action ]
in [ label "filter" . prop_name . sep . prop_oper . sep . prop_val .
Sep.space . prop_act . Util.eol ]
Sep.space . actions . Util.eol ]

let entries = ( Syslog.empty | Util.comment | entry | macro | config_object | prop_filter )*

37 changes: 37 additions & 0 deletions lenses/tests/test_rsyslog.aug
Original file line number Diff line number Diff line change
@@ -222,3 +222,40 @@ test Rsyslog.lns get "*.* ?DynamicFile\n" =
{ "dynamic" = "DynamicFile" }
}
}

(* Multiple actions in filters and selectors *)
test Rsyslog.lns get ":msg, startswith, \"iptables:\" -/var/log/iptables.log
& ~
# Save boot messages also to boot.log
local7.* /var/log/boot.log
local3.err /var/log/nfsen/nfsenlog
& /var/log/also.log
\n" =
{ "filter"
{ "property" = "msg" }
{ "operation" = "startswith" }
{ "value" = "iptables:" }
{ "action"
{ "no_sync" }
{ "file" = "/var/log/iptables.log" } }
{ "action"
{ "discard" } }
}
{ "#comment" = "Save boot messages also to boot.log" }
{ "entry"
{ "selector"
{ "facility" = "local7" }
{ "level" = "*" } }
{ "action"
{ "file" = "/var/log/boot.log" } }
}
{ "entry"
{ "selector"
{ "facility" = "local3" }
{ "level" = "err" } }
{ "action"
{ "file" = "/var/log/nfsen/nfsenlog" } }
{ "action"
{ "file" = "/var/log/also.log" } } }
{ }

0 comments on commit 5181105

Please sign in to comment.