Transport API¶
Transports are used for direct communication with the Riemann server. They are usually used inside a Client, and are used to send and receive protocol buffer objects.
- class riemann_client.transport.BlankTransport¶
Bases: riemann_client.transport.Transport
A transport that collects messages in a list, and has no connection
Used by --transport none, which is useful for testing commands without contacting a Riemann server. This is also used by the automated tests in riemann_client/tests/test_riemann_command.py.
- connect()¶
Creates a list to hold messages
- disconnect()¶
Clears the list of messages
- send(message)¶
Adds a message to the list, returning a fake ‘ok’ response
Returns: A response message with ok = True
- exception riemann_client.transport.RiemannError¶
Bases: exceptions.Exception
Raised when the Riemann server returns an error message
- class riemann_client.transport.SocketTransport(host='localhost', port=5555)¶
Bases: riemann_client.transport.Transport
Provides common methods for Transports that use a sockets
- address¶
Returns: A tuple describing the address to connect to Return type: (host, port)
- socket¶
Returns the socket after checking it has been created
- class riemann_client.transport.TCPTransport(host='localhost', port=5555, timeout=None)¶
Bases: riemann_client.transport.SocketTransport
Communicates with Riemann over TCP
Parameters: - host (str) – The hostname to connect to
- port (int) – The port to connect to
- timeout (int) – The time in seconds to wait before raising an error
- connect()¶
Connects to the given host
- disconnect()¶
Closes the socket
- send(message)¶
Sends a message to a Riemann server and returns it’s response
Parameters: message – The message to send to the Riemann server Returns: The response message from Riemann Raises RiemannError: if the server returns an error
- class riemann_client.transport.TLSTransport(host='localhost', port=5555, timeout=None, ca_certs=None)¶
Bases: riemann_client.transport.TCPTransport
Communicates with Riemann over TCP + TLS
Options are the same as TCPTransport unless noted
Parameters: ca_certs (str) – Path to a CA Cert bundle used to create the socket - connect()¶
Connects using TLSTransport.connect() and wraps with TLS
- class riemann_client.transport.Transport¶
Bases: object
Abstract transport definition
Subclasses must implement the connect(), disconnect() and send() methods.
Can be used as a context manager, which will call connect() on entry and disconnect() on exit.
- connect()¶
- disconnect()¶
- send()¶
- class riemann_client.transport.UDPTransport(host='localhost', port=5555)¶
Bases: riemann_client.transport.SocketTransport
- connect()¶
Creates a UDP socket
- disconnect()¶
Closes the socket
- send(message)¶
Sends a message, but does not return a response
Returns: None - can’t receive a response over UDP
- riemann_client.transport.socket_recvall(socket, length, bufsize=4096)¶
A helper method to read of bytes from a socket to a maximum length