Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / rsyslog.aug
1 (*
2 Module: Rsyslog
3   Parses /etc/rsyslog.conf
4
5 Author: Raphael Pinson <raphael.pinsons@camptocamp.com>
6
7 About: Reference
8   This lens tries to keep as close as possible to `man 5 rsyslog.conf` where possible.
9
10 About: License
11    This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14    To be documented
15
16 About: Configuration files
17    This lens applies to /etc/rsyslog.conf. See <filter>.
18
19 About: Examples
20    The <Test_Rsyslog> file contains various examples and tests.
21 *)
22 module Rsyslog =
23
24 autoload xfm
25
26 let macro_rx = /[^,# \n\t][^#\n]*[^,# \n\t]|[^,# \n\t]/
27 let macro = [ key /$[A-Za-z0-9]+/ . Sep.space . store macro_rx . Util.comment_or_eol ]
28
29 let config_object_param = [ key /[A-Za-z.]+/ . Sep.equal . Quote.dquote
30                             . store /[^"]+/ . Quote.dquote ]
31 (* Inside config objects, we allow embedded comments; we don't surface them
32  * in the tree though *)
33 let config_sep = del /[ \t]+|[ \t]*#.*\n[ \t]*/ " "
34
35 let config_object =
36   [ key /action|global|input|module|parser|timezone|include/ .
37     Sep.lbracket .
38     config_object_param . ( config_sep . config_object_param )* .
39     Sep.rbracket . Util.comment_or_eol ]
40
41 (* View: users
42    Map :omusrmsg: and a list of users, or a single *
43 *)
44 let omusrmsg = Util.del_str ":omusrmsg:" .
45                  Syslog.label_opt_list_or "omusrmsg" (store Syslog.word)
46                                           Syslog.comma "*"
47
48 (* View: file_tmpl
49    File action with a specified template *)
50 let file_tmpl = Syslog.file . [ label "template" . Util.del_str ";" . store Rx.word ]
51
52 let dynamic = [ Util.del_str "?" . label "dynamic" . store Rx.word ]
53
54 let namedpipe = Syslog.pipe . Sep.space . [ label "pipe" . store Syslog.file_r ]
55
56 let action = Syslog.action | omusrmsg | file_tmpl | dynamic | namedpipe
57
58 (* Cannot use syslog program because rsyslog does not suppport #! *)
59 let program = [ label "program" . Syslog.bang .
60     ( Syslog.opt_plus | [ Build.xchgs "-" "reverse" ] ) .
61     Syslog.programs . Util.eol .  Syslog.entries ]
62
63 (* Cannot use syslog hostname because rsyslog does not suppport #+/- *)
64 let hostname = [ label "hostname" .
65       ( Syslog.plus | [ Build.xchgs "-" "reverse" ] ) .
66       Syslog.hostnames . Util.eol .  Syslog.entries ]
67
68 (* View: actions *)
69 let actions =
70      let prop_act  = [ label "action" . action ]
71   in let act_sep = del /[ \t]*\n&[ \t]*/ "\n& "
72   in Build.opt_list prop_act act_sep
73
74 (* View: entry
75    An entry contains selectors and an action
76 *)
77 let entry = [ label "entry" . Syslog.selectors . Syslog.sep_tab .
78               actions . Util.eol ]
79
80 (* View: prop_filter
81    Parses property-based filters, which start with ":" and the property name *)
82 let prop_filter =
83      let sep = Sep.comma . Util.del_opt_ws " "
84   in let prop_name = [ Util.del_str ":" . label "property" . store Rx.word ]
85   in let prop_oper = [ label "operation" . store /[A-Za-z!-]+/ ]
86   in let prop_val  = [ label "value" . Quote.do_dquote (store /[^\n"]*/) ]
87   in [ label "filter" . prop_name . sep . prop_oper . sep . prop_val .
88        Sep.space . actions . Util.eol ]
89
90 let entries = ( Syslog.empty | Util.comment | entry | macro | config_object | prop_filter )*
91
92 let lns = entries . ( program | hostname )*
93
94 let filter = incl "/etc/rsyslog.conf"
95            . incl "/etc/rsyslog.d/*"
96            . Util.stdexcl
97
98 let xfm = transform lns filter