File rsyslog.conf
################ # Modules ################ $ModLoad imtcp $ModLoad imudp $ModLoad imuxsock $ModLoad imklog ################ # Templates ################ # Use default timestamp format $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # log every host in its own directory $template RemoteHost,"/var/syslog/hosts/%HOSTNAME%/%$YEAR%/%$MONTH%/%$DAY%/syslog.log" ################ ### Rulesets ################ ################ # Local Logging $RuleSet local kern.* /var/log/messages *.info;mail.none;authpriv.none;cron.none /var/log/messages authpriv.* /var/log/secure mail.* -/var/log/maillog cron.* /var/log/cron *.emerg * uucp,news.crit /var/log/spooler local7.* /var/log/boot.log # use the local RuleSet as default if not specified otherwise $DefaultRuleset local ################ # Remote Logging $RuleSet remote *.* ?RemoteHost # Send messages we receive to Gremlin *.* @@W.X.Y.Z:514 ################ ### Listeners ################ # bind ruleset to tcp listener, must be at the end $InputTCPServerBindRuleset remote $InputTCPServerRun 514 $InputUDPServerBindRuleset remote $UDPServerRun 514
###################### MODULES ###################### $ModLoad imuxsock $ModLoad imklog $template myFormat,"%rawmsg%\n" RULES ###################### authpriv.* /var/log/secure;myFormat mail.info /var/log/mail.info mail.warn /var/log/mail.warn mail.err /var/log/mail.err daemon.* /var/log/daemon.log
logrotate.conf In the default rsyslog logrotate /etc/logrotate.d/rsyslog config I see the following:
/var/log/syslog { rotate 7 daily missingok notifempty delaycompress compress sharedscripts postrotate reload rsyslog >/dev/null 2>&1 || true endscript }
# provides support for local system logging $ModLoad imuxsock # provides kernel logging support (previously done by rklogd) $ModLoad imklog # provides UDP and TCP syslog reception. $ModLoad imudp $ModLoad imtcp # Accept connection on port 514 in TCP and UDP $UDPServerRun 514 $InputTCPServerRun 514 # This one is the template to generate the log filename dynamically, depending on the client's IP address. $template FILENAME,"/var/log/%fromhost-ip%/syslog.log" # Log all messages to the dynamically formed file. Now each clients log (192.168.1.2, 192.168.1.3,etc...), will be under a separate directory which is formed by the template FILENAME. *.* ?FILENAME
For a client:
$ModLoad imuxsock $ModLoad imklog # Provides UDP forwarding. The IP is the server's IP address *.* @192.168.1.1:514 # Provides TCP forwarding. But the current server runs on UDP # *.* @@192.168.1.1:514
New format
template (name="DynFile" type="string" string="/var/log/system-%HOSTNAME%.log")
Legacy format
$template DynFile,"/var/log/system-%HOSTNAME%.log"
$template FileFormat,"%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n" $template TraditionalFileFormat,"%TIMESTAMP% %HOSTNAME% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n" $template ForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag:1:32%%msg:::sp-if-no-1st-sp%%msg%" $template TraditionalForwardFormat,"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag:1:32%%msg:::sp-if-no-1st-sp%%msg%"
Template names beginning with “RSYSLOG_” are reserved for rsyslog use. Do NOT use them if, otherwise you may receive a conflict in the future (and quite unpredictable behaviour). There is a small set of pre-defined templates that you can use without the need to define it:
RSYSLOG_TraditionalFileFormat - the "old style" default log file format with low-precision timestamps RSYSLOG_FileFormat - a modern-style logfile format similar to TraditionalFileFormat, buth with high-precision timestamps and timezone information RSYSLOG_TraditionalForwardFormat - the traditional forwarding format with low-precision timestamps. Most useful if you send messages to other syslogd's or rsyslogd below version 3.12.5. RSYSLOG_ForwardFormat - a new high-precision forwarding format very similar to the traditional one, but with high-precision timestamps and timezone information. Recommended to be used when sending messages to rsyslog 3.12.5 or above. RSYSLOG_SyslogProtocol23Format - the format specified in IETF's internet-draft ietf-syslog-protocol-23, which is assumed to be come the new syslog standard RFC. This format includes several improvements. The rsyslog message parser understands this format, so you can use it together with all relatively recent versions of rsyslog. Other syslogd's may get hopelessly confused if receiving that format, so check before you use it. Note that the format is unlikely to change when the final RFC comes out, but this may happen. RSYSLOG_DebugFormat - a special format used for troubleshooting property problems. This format is meant to be written to a log file. Do not use for production or remote forwarding.
Forwading from syslogserver to another one. http://www.rsyslog.com/storing-and-forwarding-remote-messages/
Formats http://www.rsyslog.com/doc/v8-stable/configuration/examples.html#templates
http://securitysynapse.blogspot.com/2019/01/rsyslog-fun-basic-splunk-log-collection-part-i.html