pyloggr.main.syslog_server

This module provides stuff to implement a the main syslog/RELP server with Tornado

class ListOfClients[source]

Bases: object

Stores the current Syslog clients, sends notifications to observers, publishes the list of clients in Redis

__getitem__(client_id)[source]
add(client_id, client)[source]
remove(client_id)[source]
classmethod set_server_id(server_id)[source]
Parameters:server_id (int) – process number
class MainSyslogServer(rabbitmq_config, syslog_parameters, server_id)[source]

Bases: pyloggr.syslog.server.BaseSyslogServer

Tornado syslog server

SyslogServer listens for syslog messages (RELP, RELP/TLS, TCP, TCP/TLS, Unix socket) and sends messages to RabbitMQ.

_start_syslog()[source]

Start to listen for syslog clients

Note

Tornado coroutine

_stop_syslog()[source]

Stop listening for syslog connections

Note

Tornado coroutine

handle_data(data, sockname, peername)[source]

Handle UDP syslog

Parameters:
  • data – data sent
  • sockname – the server socket info
  • peername – the client socket info
handle_stream(stream, address)[source]

Called by tornado when we have a new client.

Parameters:
  • stream (IOStream) – IOStream for the new connection
  • address (tuple) – tuple (client IP, client source port)

Note

Tornado coroutine

launch()[source]

Starts the server

  • First we try to connect to RabbitMQ
  • If successfull, we start to listen for syslog clients

Note

Tornado coroutine

shutdown(*args, **kwargs)[source]

Authoritarian shutdown

stop_all()[source]

Stops completely the server. Stop listening for syslog clients. Close connection to RabbitMQ.

Note

Tornado coroutine

class Notification(dictionnary, routing_key)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__getstate__()

Exclude the OrderedDict from pickling

__repr__()

Return a nicely formatted representation string

_asdict()

Return a new OrderedDict which maps field names to their values

_replace(_self, **kwds)

Return a new Notification object replacing specified fields with new values

dictionnary

Alias for field number 0

routing_key

Alias for field number 1

class Publicator(syslog_servers_conf, rabbitmq_config)[source]

Bases: object

Publicator manages the RabbitMQ connection and actually makes the publish calls.

Publicator runs in its own thread, and has its own IOLoop.

Parameters:
  • syslog_servers_conf – Syslog configuration (used to initialize packers)
  • rabbitmq_config – RabbitMQ connection parameters
_do_publish_notification(message)[source]
_do_publish_syslog(message)[source]
init_thread()[source]

Publicator thread: start a new IOLoop, make it current, call _do_start as a callback

notify_observers(d, routing_key='')[source]

Send a notification via RabbitMQ

Parameters:
  • d (dict) – dictionnary to send as a notification
  • routing_key (str) – RabbitMQ routing key
publish_syslog_message(protocol, server_port, client_host, bytes_event, client_id, relp_id=None)[source]

Ask publications to publish a syslog event to RabbitMQ. Can be called by any thread

Parameters:
  • protocol (str) – ‘tcp’ or ‘relp’
  • server_port (int) – which syslog server port was used to transmit the event
  • client_host (str) – client hostname that sent the event
  • bytes_event (bytes) – the event as bytes
  • client_id (str) – SyslogClientConnection client_id
  • relp_id (int) – event RELP id
rabbitmq_status()[source]

Return True if we have an established connection to RabbitMQ

shutdown()[source]

Ask Publicator to shutdown. Can be called by any thread.

start()[source]

Start publications own thread

class SyslogClientConnection(stream, address, syslog_parameters)[source]

Bases: pyloggr.syslog.server.BaseSyslogClientConnection

Encapsulates a connection with a syslog client

_process_event(bytes_event, protocol, relp_event_id=None)[source]

_process_relp_event(bytes_event, relp_event_id) Process a TCP syslog or RELP event.

Parameters:
  • bytes_event – the event as bytes
  • protocol – relp or tcp
  • relp_event_id – event RELP ID, given by the RELP client
after_published_relp(*args, **kwargs)[source]

Called after an event received by RELP has been published in RabbitMQ

Parameters:
  • status – True if the event was successfully sent
  • event – the Event object
  • relp_id – event RELP id
disconnect()[source]

Disconnects the client

on_stream_closed()[source]

Called when a client has been disconnected

props

Return a few properties for this client

Return type:dict
class SyslogMessage(protocol, server_port, client_host, bytes_event, client_id, relp_id, total_messages)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__getstate__()

Exclude the OrderedDict from pickling

__repr__()

Return a nicely formatted representation string

_asdict()

Return a new OrderedDict which maps field names to their values

_replace(_self, **kwds)

Return a new SyslogMessage object replacing specified fields with new values

bytes_event

Alias for field number 3

client_host

Alias for field number 2

client_id

Alias for field number 4

protocol

Alias for field number 0

relp_id

Alias for field number 5

server_port

Alias for field number 1

total_messages

Alias for field number 6

after_published_tcp(*args, **kwargs)[source]

Called after an event received by TCP has been tried to be published in RabbitMQ

Parameters:
  • status – True if the event was successfully sent
  • event – the Event object
  • bytes_event – the event as bytes