You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
#!/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 = 'Master_C.log' |
|
HOST, PORT = "0.0.0.0", 48514 |
|
|
|
# |
|
# 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) |
|
print(f"Syslog running on host {HOST} port {PORT}") |
|
except (IOError, SystemExit): |
|
raise |
|
except KeyboardInterrupt: |
|
print ("Crtl+C Pressed. Shutting down.") |