I'm baffled as to why I can't get rsyslog to log data sent to it via TCP whenever I send the data with a Python script, but works perfectly fine if I send the same string via netcat
Rsyslog is set up to receive syslog data on TCP/514: /etc/rsyslog.conf
$ModLoad imtcp
$InputTCPServerRun 514
/etc/rsyslog.d/LogByIP.conf
$template LogByIP,"/tmp/%fromhost-ip%.log"
if ($fromhost-ip != '127.0.0.1') then ?LogByIP
Restarted rsyslog. Executed this command from the client machine:
[root@localhost ~]# echo HELLO2 |nc logbox 514
Contents of /tmp/.log
Nov 18 15:36:16 HELLO2
So rsyslog is working as expected. Now when I try to do the same thing in Python, the message never gets written to file.
#! /usr/bin/python
import socket
host='logbox'
port=514
message='hello world'
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
s.sendall(message)
s.close()
Running tcpdump on the logbox, I can see the session setup, the string transmitted and the session closed out in TCP, but "hello world" never shows up in the logfile. What am I missing here?