#!/usr/bin/env python | |
## Tiny Syslog Server in Python. | |
## | |
## This is a tiny syslog server that is able to receive UDP based syslog | |
## entries on a specified port and save them to a file. | |
## That's it... it does nothing else... | |
## There are a few configuration parameters. | |
LOG_FILE = 'youlogfile.log' | |
HOST, PORT = "0.0.0.0", 514 | |
# | |
# NO USER SERVICEABLE PARTS BELOW HERE... | |
# | |
import logging | |
import SocketServer | |
logging.basicConfig(level=logging.INFO, format='%(message)s', datefmt='', filename=LOG_FILE, filemode='a') | |
class SyslogUDPHandler(SocketServer.BaseRequestHandler): | |
def handle(self): | |
data = bytes.decode(self.request[0].strip()) | |
socket = self.request[1] | |
print( "%s : " % self.client_address[0], str(data)) | |
logging.info(str(data)) | |
if __name__ == "__main__": | |
try: | |
server = SocketServer.UDPServer((HOST,PORT), SyslogUDPHandler) | |
server.serve_forever(poll_interval=0.5) | |
except (IOError, SystemExit): | |
raise | |
except KeyboardInterrupt: | |
print ("Crtl+C Pressed. Shutting down.") |
This comment has been minimized.
This comment has been minimized.
Great Script BTW |
This comment has been minimized.
This comment has been minimized.
Thank's for sharing nice code. |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks!! |
This comment has been minimized.
This comment has been minimized.
I am using rsyslog on centos as a client . |
This comment has been minimized.
This comment has been minimized.
Excellent! just what I needed... Thank you:) |
This comment has been minimized.
This comment has been minimized.
Nice one! Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks for the initiative. How do we add TLS support to this? |
This comment has been minimized.
This comment has been minimized.
Can you explain why would I use this instead of the real syslog facility? |
This comment has been minimized.
This comment has been minimized.
You can add
It worked very well when I needed a syslog server for some tests. Thanks for sharing. |
This comment has been minimized.
This comment has been minimized.
Cute. If you are in python3, simply change |
This comment has been minimized.
This comment has been minimized.
I developed a Python 3 implementation of a simple UDP syslog server which inserts the recieved messages into a MariaDB or MySQL database. https://github.com/choeffer/py3syslog |
This comment has been minimized.
This comment has been minimized.
Thx, using it for routers monitoring :p |
This comment has been minimized.
This comment has been minimized.
Nice thanks, will use it to trigger another script after syslog message is sent through EEM script. |
This comment has been minimized.
This comment has been minimized.
I am just beginner in codding and my apoligise if I miss out the point but can someone explain me how to receive logs from regarding system? Don't you need to add this code in somewhere? logging.getLogger() |
This comment has been minimized.
This comment has been minimized.
Thanks for this useful script to help to receive the syslog and send to Apache Kafka. |
This comment has been minimized.
This comment has been minimized.
@marcelom Hello, "logging.info(str(data))" causes latency, if I send million of record in one minute, it saves only half of packet. How can we fix them? Can you help me :/ |
This comment has been minimized.
This comment has been minimized.
@maxenc7, seems like the contention is in the implementation of the logging.info() call itself. Nothing I can do there. That said, 1M/s seems a little bit too much for this tiny logger to handle. In fact, seems a lot for anything to handle in that amount of time. You are probably gonna have to use something to load balance this (haproxy or nginx) and then use several backends. This is completely outside the scope of this gist. |
This comment has been minimized.
This comment has been minimized.
@marcelom Could you please create a buffer field for "str(data)" information and write it to the file without logging.info()? |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
Thanks, I've used it as a syslog frontend to redis.
https://github.com/iobear/beewatch/blob/master/bin/psyslog.py