Random UDP Message Received Needs To Be Parsed To Python File Through Rsyslog Omprog
I'm setting up a python script that will parse the inputs received via UDP from another server. Since the message or number of messages can be received randomly, I'm trying to rsys
Solution 1:
This minimal example worked for me (rsyslogd version 8.30.0). In /etc/rsyslog.conf
we have
$ModLoad imudp # UDP listener
$UDPServerRun 514
$ModLoad omprog
:inputname, isequal, "imudp" action(type="omprog"
binary="/tmp/prog.py" template="RSYSLOG_TraditionalFileFormat")
In /tmp/prog.py
we have
#!/usr/bin/python3
import sys
with open("/tmp/output","w",encoding='utf8',errors='ignore') as fd:
for data in sys.stdin:
print("got data: %s" % data[:-1], file=fd, flush=True)
When a udp packet arrives it is passed through to the python program which prints it to file /tmp/output
. Make sure to chmod a+rx /tmp/prog.py
.
Post a Comment for "Random UDP Message Received Needs To Be Parsed To Python File Through Rsyslog Omprog"