Search code examples
loggingrsyslog

Rsyslog using else in config


Hi I need have config file with:

if $FROMHOST-IP == '192.168.xx.xxx' then { action(type="omfile" file="/var/log/rsyslog/myHostName/device.log") }
else {*.* ?RemoteHost}

but rsyslog after restart give me this message:

Oct 13 12:12:40 syslog-new rsyslogd[29378]: error during parsing file /etc/rsyslog.conf, on or before line 118: syntax error on token 'else' [v8.1901.0 try https://www.rsyslog.com/e/2207 ]
Oct 13 12:12:40 syslog-new rsyslogd[29378]: could not interpret master config file '/etc/rsyslog.conf'. [v8.1901.0 try https://www.rsyslog.com/e/2207 ]

Please help. Thank you


Solution

  • The RainerScript documentation on if..then..else is somewhat lacking in details, but in order to differentiate this use of if from the legacy filter syntax also beginning if, it seems you need to enclose the expression in (). Try

    if ($FROMHOST-IP == '192.168.xx.xxx') then { action(type="omfile" file="/var/log/rsyslog/myHostName/device.log") }
    else {*.* ?RemoteHost}