severb / graypy

Python logging handler for Graylog that sends messages in GELF (Graylog Extended Log Format).
https://www.graylog.org/
BSD 3-Clause "New" or "Revised" License
258 stars 90 forks source link

A way to check / test if connection is established? #139

Open alercelik opened 2 years ago

alercelik commented 2 years ago

Hello,

Is there a way to check if connection is established succesfully with the graylog server? I could not see any. Currently i give random ports to constructor and not get any errors thus I have no way to find out whether connection is established. It would be really helpful if there is a parameter or a method to indicate that.

BeeStingBob commented 1 year ago

I'm using this snippet

  def check_connection(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        result = sock.connect_ex((self.host, self.port))
        sock.close()
        if result == 0:
            return True
        return False