Last active
December 30, 2024 18:25
-
-
Save Sovenok-Hacker/338fe574dff93ed64c30cee28aef3670 to your computer and use it in GitHub Desktop.
Syslog to Gotify proxy (used https://gist.github.com/marcelom/4218010) | Beeline router system message server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| ## Tiny Syslog Server in Python | |
| HOST, PORT = "0.0.0.0", 514 | |
| GOTIFY_URL = "http://127.0.0.1:8050" # Your Gotify instance URL | |
| GOTIFY_TOKEN = "<YOURTOKEN>" # Your Gotify app token | |
| import socketserver as ss | |
| import requests | |
| class SyslogUDPHandler(ss.BaseRequestHandler): | |
| def handle(self): | |
| data = self.request[0].strip().decode() | |
| addr = self.client_address[0] | |
| print(f"[SYSLOG {addr}] {data}") | |
| requests.post( | |
| GOTIFY_URL + "/message", | |
| params={ | |
| "token": GOTIFY_TOKEN | |
| }, | |
| json={ | |
| "title": "Syslog message", | |
| "message": data | |
| } | |
| ) | |
| if __name__ == "__main__": | |
| try: | |
| server = ss.UDPServer((HOST, PORT), SyslogUDPHandler) | |
| server.serve_forever(poll_interval=0.2) | |
| except (IOError, SystemExit): | |
| raise | |
| except KeyboardInterrupt: | |
| print("Crtl+C Pressed. Shutting down.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment