Imported Upstream version 1.8.0
[platform/upstream/augeas.git] / lenses / tests / test_rsyslog.aug
1 (*
2 Module: Test_Rsyslog
3   Provides unit tests and examples for the <Rsyslog> lens.
4 *)
5
6 module Test_Rsyslog =
7
8 (* Variable: conf *)
9 let conf = "# rsyslog v5 configuration file
10
11 $ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
12 $ModLoad imklog   # provides kernel logging support (previously done by rklogd)
13 module(load=\"immark\" markmessageperiod=\"60\" fakeoption=\"bar\") #provides --MARK-- message capability
14
15 timezone(id=\"CET\" offset=\"+01:00\")
16
17 $UDPServerRun 514
18 $InputTCPServerRun 514
19 $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
20 $ActionFileEnableSync on
21 $IncludeConfig /etc/rsyslog.d/*.conf
22
23 *.info;mail.none;authpriv.none;cron.none                /var/log/messages
24 authpriv.*                                              /var/log/secure
25 *.emerg                                                 *
26 *.*    @2.7.4.1
27 *.*    @@2.7.4.1
28 *.emerg :omusrmsg:*
29 *.emerg :omusrmsg:foo,bar
30 *.emerg | /dev/xconsole
31 "
32
33 (* Test: Rsyslog.lns *)
34 test Rsyslog.lns get conf =
35   { "#comment" = "rsyslog v5 configuration file" }
36   {  }
37   { "$ModLoad" = "imuxsock"
38     { "#comment" = "provides support for local system logging (e.g. via logger command)" }
39   }
40   { "$ModLoad" = "imklog"
41     { "#comment" = "provides kernel logging support (previously done by rklogd)" }
42   }
43   { "module"
44     { "load" = "immark" }
45     { "markmessageperiod" = "60" }
46     { "fakeoption" = "bar" }
47     { "#comment" = "provides --MARK-- message capability" }
48   }
49   {  }
50   { "timezone"
51     { "id" = "CET" }
52     { "offset" = "+01:00" }
53   }
54   {  }
55   { "$UDPServerRun" = "514" }
56   { "$InputTCPServerRun" = "514" }
57   { "$ActionFileDefaultTemplate" = "RSYSLOG_TraditionalFileFormat" }
58   { "$ActionFileEnableSync" = "on" }
59   { "$IncludeConfig" = "/etc/rsyslog.d/*.conf" }
60   {  }
61   { "entry"
62     { "selector"
63       { "facility" = "*" }
64       { "level" = "info" }
65     }
66     { "selector"
67       { "facility" = "mail" }
68       { "level" = "none" }
69     }
70     { "selector"
71       { "facility" = "authpriv" }
72       { "level" = "none" }
73     }
74     { "selector"
75       { "facility" = "cron" }
76       { "level" = "none" }
77     }
78     { "action"
79       { "file" = "/var/log/messages" }
80     }
81   }
82   { "entry"
83     { "selector"
84       { "facility" = "authpriv" }
85       { "level" = "*" }
86     }
87     { "action"
88       { "file" = "/var/log/secure" }
89     }
90   }
91   { "entry"
92     { "selector"
93       { "facility" = "*" }
94       { "level" = "emerg" }
95     }
96     { "action"
97       { "user" = "*" }
98     }
99   }
100   { "entry"
101     { "selector"
102       { "facility" = "*" }
103       { "level" = "*" }
104     }
105     { "action"
106       { "protocol" = "@" }
107       { "hostname" = "2.7.4.1" }
108     }
109   }
110   { "entry"
111     { "selector"
112       { "facility" = "*" }
113       { "level" = "*" }
114     }
115     { "action"
116       { "protocol" = "@@" }
117       { "hostname" = "2.7.4.1" }
118     }
119   }
120   { "entry"
121     { "selector"
122       { "facility" = "*" }
123       { "level" = "emerg" }
124     }
125     { "action"
126       { "omusrmsg" = "*" }
127     }
128   }
129   { "entry"
130     { "selector"
131       { "facility" = "*" }
132       { "level" = "emerg" }
133     }
134     { "action"
135       { "omusrmsg" = "foo" }
136       { "omusrmsg" = "bar" } }
137   }
138   { "entry"
139     { "selector"
140       { "facility" = "*" }
141       { "level" = "emerg" }
142     }
143     { "action"
144       { "pipe" = "/dev/xconsole" }
145     }
146   }
147
148 (* Parse complex $template lines, RHBZ#1083016 *)
149 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" =
150   { "$template" = "SpiceTmpl,\"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\\n\"" }
151
152 (* Parse property-based filters, RHBZ#1083016 *)
153 test Rsyslog.lns get ":programname, startswith, \"spice-vdagent\" /var/log/spice-vdagent.log;SpiceTmpl\n" =
154   { "filter"
155     { "property" = "programname" }
156     { "operation" = "startswith" }
157     { "value" = "spice-vdagent" }
158     { "action"
159       { "file" = "/var/log/spice-vdagent.log" }
160       { "template" = "SpiceTmpl" } } }
161
162 test Rsyslog.lns get ":msg, !contains, \"error\" /var/log/noterror.log\n" =
163   { "filter"
164     { "property" = "msg" }
165     { "operation" = "!contains" }
166     { "value" = "error" }
167     { "action"
168       { "file" = "/var/log/noterror.log" } } }
169
170 test Rsyslog.lns get ":msg,!contains,\"garbage\" ~\n" =
171   { "filter"
172     { "property" = "msg" }
173     { "operation" = "!contains" }
174     { "value" = "garbage" }
175     { "action"
176       { "discard" } } }
177
178 test Rsyslog.lns put "" after
179   set "/module[1]/load" "imuxsock"
180   = "module(load=\"imuxsock\")\n"
181
182 test Rsyslog.lns put "" after
183   set "/module[1]/load" "imuxsock" ;
184   set "/module[1]/SysSock.RateLimit.Interval" "0"
185   = "module(load=\"imuxsock\" SysSock.RateLimit.Interval=\"0\")\n"
186
187 test Rsyslog.lns put "" after
188   set "/module[1]/load" "imuxsock" ;
189   set "/module[1]/SysSock.RateLimit.Interval" "0" ;
190   set "/module[1]/SysSock.RateLimit.Burst" "1"
191   = "module(load=\"imuxsock\" SysSock.RateLimit.Interval=\"0\" SysSock.RateLimit.Burst=\"1\")\n"