3 Provides unit tests and examples for the <Rsyslog> lens.
9 let conf = "# rsyslog v5 configuration file
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
15 timezone(id=\"CET\" offset=\"+01:00\")
18 $InputTCPServerRun 514
19 $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
20 $ActionFileEnableSync on
21 $IncludeConfig /etc/rsyslog.d/*.conf
23 *.info;mail.none;authpriv.none;cron.none /var/log/messages
24 authpriv.* /var/log/secure
29 *.emerg :omusrmsg:foo,bar
30 *.emerg | /dev/xconsole
33 (* Test: Rsyslog.lns *)
34 test Rsyslog.lns get conf =
35 { "#comment" = "rsyslog v5 configuration file" }
37 { "$ModLoad" = "imuxsock"
38 { "#comment" = "provides support for local system logging (e.g. via logger command)" }
40 { "$ModLoad" = "imklog"
41 { "#comment" = "provides kernel logging support (previously done by rklogd)" }
45 { "markmessageperiod" = "60" }
46 { "fakeoption" = "bar" }
47 { "#comment" = "provides --MARK-- message capability" }
52 { "offset" = "+01:00" }
55 { "$UDPServerRun" = "514" }
56 { "$InputTCPServerRun" = "514" }
57 { "$ActionFileDefaultTemplate" = "RSYSLOG_TraditionalFileFormat" }
58 { "$ActionFileEnableSync" = "on" }
59 { "$IncludeConfig" = "/etc/rsyslog.d/*.conf" }
67 { "facility" = "mail" }
71 { "facility" = "authpriv" }
75 { "facility" = "cron" }
79 { "file" = "/var/log/messages" }
84 { "facility" = "authpriv" }
88 { "file" = "/var/log/secure" }
107 { "hostname" = "2.7.4.1" }
116 { "protocol" = "@@" }
117 { "hostname" = "2.7.4.1" }
123 { "level" = "emerg" }
132 { "level" = "emerg" }
135 { "omusrmsg" = "foo" }
136 { "omusrmsg" = "bar" } }
141 { "level" = "emerg" }
144 { "pipe" = "/dev/xconsole" }
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\"" }
152 (* Parse property-based filters, RHBZ#1083016 *)
153 test Rsyslog.lns get ":programname, startswith, \"spice-vdagent\" /var/log/spice-vdagent.log;SpiceTmpl\n" =
155 { "property" = "programname" }
156 { "operation" = "startswith" }
157 { "value" = "spice-vdagent" }
159 { "file" = "/var/log/spice-vdagent.log" }
160 { "template" = "SpiceTmpl" } } }
162 test Rsyslog.lns get ":msg, !contains, \"error\" /var/log/noterror.log\n" =
164 { "property" = "msg" }
165 { "operation" = "!contains" }
166 { "value" = "error" }
168 { "file" = "/var/log/noterror.log" } } }
170 test Rsyslog.lns get ":msg,!contains,\"garbage\" ~\n" =
172 { "property" = "msg" }
173 { "operation" = "!contains" }
174 { "value" = "garbage" }
178 test Rsyslog.lns put "" after
179 set "/module[1]/load" "imuxsock"
180 = "module(load=\"imuxsock\")\n"
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"
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"
193 (* On Fedora 26, there are comments in module statements *)
194 test Rsyslog.lns get "module(load=\"imuxsock\" # provides support for local system logging (e.g. via logger command)
195 SysSock.Use=\"off\") # Turn off message reception via local log socket;
196 # local messages are retrieved through imjournal now.\n" =
198 { "load" = "imuxsock" }
199 { "SysSock.Use" = "off" }
200 { "#comment" = "Turn off message reception via local log socket;" } }
201 { "#comment" = "local messages are retrieved through imjournal now." }
203 (* rsyslog doesn't use bsd-like #! or #+/- specifications *)
204 test Rsyslog.lns get "#!prog\n" = { "#comment" = "!prog" }
205 test Rsyslog.lns get "#+host\n" = { "#comment" = "+host" }
206 test Rsyslog.lns get "#-host\n" = { "#comment" = "-host" }
208 (* Added in rsyslog 8.33 *)
209 test Rsyslog.lns get "include(file=\"/etc/rsyslog.d/*.conf\" mode=\"optional\")\n" =
211 { "file" = "/etc/rsyslog.d/*.conf" }
212 { "mode" = "optional" } }
214 (* Dynamic file name template *)
215 test Rsyslog.lns get "*.* ?DynamicFile\n" =
222 { "dynamic" = "DynamicFile" }
226 (* Multiple actions in filters and selectors *)
227 test Rsyslog.lns get ":msg, startswith, \"iptables:\" -/var/log/iptables.log
229 # Save boot messages also to boot.log
230 local7.* /var/log/boot.log
231 local3.err /var/log/nfsen/nfsenlog
235 { "property" = "msg" }
236 { "operation" = "startswith" }
237 { "value" = "iptables:" }
240 { "file" = "/var/log/iptables.log" } }
244 { "#comment" = "Save boot messages also to boot.log" }
247 { "facility" = "local7" }
250 { "file" = "/var/log/boot.log" } }
254 { "facility" = "local3" }
255 { "level" = "err" } }
257 { "file" = "/var/log/nfsen/nfsenlog" } }
259 { "file" = "/var/log/also.log" } } }