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.

riemann_client.transport.socket_recvall(socket, length, bufsize=4096)[source]

A helper method to read of bytes from a socket to a maximum length

exception riemann_client.transport.RiemannError[source]

Bases: exceptions.Exception

Raised when the Riemann server returns an error message

class riemann_client.transport.Transport[source]

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()[source]
disconnect()[source]
send()[source]
class riemann_client.transport.SocketTransport(host='localhost', port=5555)[source]

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.UDPTransport(host='localhost', port=5555)[source]

Bases: riemann_client.transport.SocketTransport

connect()[source]

Creates a UDP socket

disconnect()[source]

Closes the socket

send(message)[source]

Sends a message, but does not return a response

Returns:None - can’t receive a response over UDP
class riemann_client.transport.TCPTransport(host='localhost', port=5555, timeout=None)[source]

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()[source]

Connects to the given host

disconnect()[source]

Closes the socket

send(message)[source]

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)[source]

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()[source]

Connects using TLSTransport.connect() and wraps with TLS

class riemann_client.transport.BlankTransport(*args, **kwargs)[source]

Bases: riemann_client.transport.Transport

A transport that collects events 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()[source]

Creates a list to hold messages

send(message)[source]

Adds a message to the list, returning a fake ‘ok’ response

Returns:A response message with ok = True
disconnect()[source]

Clears the list of messages