commit
37d3aa45fd
1 changed files with 38 additions and 0 deletions
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
#!/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.") |
Loading…
Reference in new issue