Skip to content

Commit

Permalink
Handle unavailable syslog server (#14)
Browse files Browse the repository at this point in the history
* reconnect when syslog server is unavailable

* ignore unavailable syslog server on startup
  • Loading branch information
mib1185 authored Dec 1, 2024
1 parent 9dd3526 commit 733c5e3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion syslog/journal2syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def _wrap_sock_ssl(self, sock: socket.socket, host: str):

return context.wrap_socket(sock, server_hostname=host)

def handleError(self, _):
"""
Handle errors silent
Close failing socket so next emit will try to create a new socket
"""
if self.socket is not None:
self.socket.close()
self.socket = None

def createSocket(self):
"""
Try to create a socket and, if it's not a datagram socket, connect it
Expand Down Expand Up @@ -103,7 +112,8 @@ def createSocket(self):
err = exc
if sock is not None:
sock.close()
if err is not None:
if isinstance(err, ssl.SSLError):
# only fail on ssl errors
raise err
self.socket = sock
self.socktype = socktype
Expand Down

0 comments on commit 733c5e3

Please sign in to comment.