I'm encountering case when rsyslog message is lost when the file its supposed to write to does not exist.
Here is my setup:
- log server 192.168.1.2 have such config:
module(load="imtcp")
input(type="imtcp" port="514")
$template MyRemoteLog1,"/nfs/some/dir/%FROMHOST-IP%/%programname%/%$year%-%$month%-%$day%.log"
$template MyRemoteLog2,"/nfs/other/dir/%FROMHOST-IP%/%syslogfacility-text%.%syslogseverity-text%.%programname%.log"
$template MsgOnly,"%msg:2:$:%\n"
if $FROMHOST-IP== ['192.168.1.3'] AND $SYSLOGFACILITY-TEXT== ['local5'] then ?MyRemoteLog1;MsgOnly
& stop
if $FROMHOST-IP== ['192.168.1.3'] then ?MyRemoteLog2
& stop
- client that send log 192.168.1.3 have such config:
*.* @@192.168.1.2:514
- I have also tried changing 192.168.1.3's config to become like such but the problem persists:
*.* action(type="omfwd"
Target="192.168.1.2"
Port="514"
resendlastmsgonreconnect="on"
action.resumeRetryCount="-1"
queue.filename="queue"
queue.size="100000"
queue.saveonshutdown="on"
Protocol="tcp" )
Basically, if local5 then it's stored to /nfs/some/dir/192.168.1.3/mytag/2022-03-15.log, but if it's not local5 then it's stored to /nfs/other/dir/192.168.1.3/user.notice.mytag.log in logserver
Also, my setup write the log files to nfs mounted disk (if it matters).
The problem is as such:
- system already running (logs have been written)
- in 192.168.1.3(client), run
date | logger -p local5.debug -t mytag
- in 192.168.1.2(server), new file /nfs/some/dir/192.168.1.3/mytag/2022-03-15.log is created, but content is blank
- in 192.168.1.3(client), run
date | logger -p local5.debug -t mytag
(again) - in 192.168.1.2(server), file /nfs/some/dir/192.168.1.3/mytag/2022-03-15.log is written (message in step 4 is written, but message in step 2 is lost)
- in 192.168.1.2(server), delete the file, then run rsyslog rotate script like such:
rm /nfs/some/dir/192.168.1.3/mytag/2022-03-15.log ; /usr/lib/rsyslog/rsyslog-rotate
- in 192.168.1.3(client), run
date | logger -p local5.debug -t mytag
(again) - in 192.168.1.2(server), new file /nfs/some/dir/192.168.1.3/mytag/2022-03-15.log is created, but content is blank
I think that this experiment shows that when file is not exist yet, it will be created but the content is not written. Why is that so?
At first I thought that it might be because of rsyslog over plain TCP is not reliable and that I might need to use RELP. But after such experiment, I don't think the problem is on network.
Here is my nfs mount:
172.16.1.4:/some/dir/nfs_export on /nfs type nfs (rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=172.16.1.4,mountvers=3,mountport=38559,mountproto=udp,local_lock=none,addr=172.16.1.4)
After turning on rsyslog debug message by adding config $DebugFile /tmp/rsyslogdebug.txt
and config $DebugLevel 1
and running this command:
kill -USR1 `ps aux | grep rsyslog | tr -s ' ' | cut -d' ' -f2 | head -n1`
I managed to find such logs in /tmp/rsyslogdebug.txt
:
7792.776708768:main Q:Reg/w0 : omfile.c: omfile: file to log to: /nfs/some/dir/192.168.1.3/mytag/2022-03-15.log
7792.779333692:main Q:Reg/w0 : errmsg.c: Called LogMsg, msg: error during config processing: omfile: chown for file '/nfs/some/dir/192.168.1.3/mytag/2022-03-15.log' failed: Operation not permitted
7792.779415835:main Q:Reg/w0 : operatingstate.c: osf: MSG error during config processing: omfile: chown for file '/nfs/some/dir/192.168.1.3/mytag/2022-03-15.log' failed: Operation not permitted: signaling new internal message via SIGTTOU: 'error during config processing: omfile: chown for file '/nfs/some/dir/192.168.1.3/mytag/2022-03-15.log' failed: Operation not permitted [v8.2001.0 try https://www.rsyslog.com/e/2207 ]'
7792.779567477:main thread : janitor.c: janitorRun() called
7792.779745372:main Q:Reg/w0 : errmsg.c: Called LogMsg, msg: error during config processing: Could not open dynamic file '/nfs/some/dir/192.168.1.3/mytag/2022-03-15.log' [state -3000] - discarding message
7792.779812889:main Q:Reg/w0 : operatingstate.c: osf: MSG error during config processing: Could not open dynamic file '/nfs/some/dir/192.168.1.3/mytag/2022-03-15.log' [state -3000] - discarding message: signaling new internal message via SIGTTOU: 'error during config processing: Could not open dynamic file '/nfs/some/dir/192.168.1.3/mytag/2022-03-15.log' [state -3000] - discarding message [v8.2001.0 try https://www.rsyslog.com/e/2207 ]'