shellbot.updaters package

Module contents

class shellbot.updaters.ElasticsearchUpdater(engine=None, **kwargs)[source]

Bases: shellbot.updaters.base.Updater

Writes inbound events to Elasticsearch

An event may be a Message, a Join or Leave notification, or any other Event.

Updaters expose a filtering function that can be connected to the inbound flow of events handled by the Listener.

Example:

updater = ElasticsearchUpdater(host='db.local:9200')
listener = Listener(filter=updater.filter)
get_host()[source]

Provides the Elasticsearch host

Return type:str
on_bond(bot)[source]

Creates index on space bonding

on_init(host=None, index=None, **kwargs)[source]

Writes inbound events to Elasticsearch

put(event)[source]

Processes one event

Parameters:event (Event or Message or Join or Leave) – inbound event

The function writes the event as a JSON document in Elasticsearch.

class shellbot.updaters.FileUpdater(engine=None, **kwargs)[source]

Bases: shellbot.updaters.base.Updater

Writes inbound events to a file

This updater serializes events and write JSON records to a flat file.

An event may be a Message, a Join or Leave notification, or any other Event.

Updaters expose a filtering function that can be connected to the inbound flow of events handled by the Listener.

Example:

updater = FileUpdater(path='/var/log/my_app.log')
listener = Listener(filter=updater.filter)
get_path()[source]

Provides the path to the target file

Return type:str
on_bond(bot)[source]

Creates path on space bonding

on_init(path=None, **kwargs)[source]

Writes inbound events to a file

put(event)[source]

Processes one event

Parameters:event (Event or Message or Join or Leave) – inbound event

The function serializes the event and write it to a file.

class shellbot.updaters.QueueUpdater(engine=None, **kwargs)[source]

Bases: shellbot.updaters.base.Updater

Writes inbound events to a queue

This updater serializes events and write them to a queue.

An event may be a Message, a Join or Leave notification, or any other Event.

Updaters expose a filtering function that can be connected to the inbound flow of events handled by the Listener.

Example:

updater = QueueUpdater(queue=Queue())
listener = Listener(filter=updater.filter)

Of course, some process has to grab content from updater.queue afterwards.

on_init(queue=None, **kwargs)[source]

Writes inbound events to a queue

put(event)[source]

Processes one event

Parameters:event (Event or Message or Join or Leave) – inbound event

This function serializes the event and write it to a queue.

class shellbot.updaters.SpaceUpdater(engine=None, **kwargs)[source]

Bases: shellbot.updaters.base.Updater

Replicates messages to a secondary space

format(event)[source]

Prepares an outbound line

Parameters:event (Event or Message or Join or Leave) – an inbound event
Returns:outbound line
Return type:str

This function adapts inbound events to the appropriate format. It turns an object with multiple attributes to a single string that can be pushed to a Cisco Spark room.

on_init(space=None, speaker=None, **kwargs)[source]

Replicates messages to a secondary space

Parameters:
  • space (Space) – the target space to use (optional)
  • speaker (Speaker) – the speaker instance to use (optional)

Parameters are provided mainly for test injection.

put(event)[source]

Processes one event

Parameters:event (Event or Message or Join or Leave) – an inbound event

With this class a string representation of the received event is forwarded to the speaker queue of a chat space.

class shellbot.updaters.Updater(engine=None, **kwargs)[source]

Bases: object

Handles inbound events

Updaters are useful for logging or replication, or side storage, or achiving, of received events.

An event may be a Message, a Join or Leave notification, or any other Event.

Updaters expose a filtering function that can be connected to the inbound flow of events handled by the Listener.

Example:

updater = FileUpdater(path='/var/log/shellbot.log')
listener = Listener(filter=updater.filter)

Here events are written down to a flat file, yet multiple updaters are available.

For example, push every event to Elasticsearch:

updater = ElasticsearchUpdater()
listener = Listener(filter=updater.filter)

There is also an updater where events are written to a separate Cisco Spark room. This will be useful in cases where safety or control are specifically important.

We are looking for new updaters, so please have a careful look at this file and consider to submit your own module.

filter(event)[source]

Filters events handled by listener

Parameters:event (Event or Message or Join or Leave, etc.) – an event received by listener
Returns:a filtered event

This function implements the actual auditing of incoming events.

format(event)[source]

Prepares an outbound line

Parameters:event (Event or Message or Join or Leave) – an inbound event
Returns:outbound line
Return type:str

This function adapts inbound events to the appropriate format. It turns an object with multiple attributes to a single string that can be saved in a log file.

on_bond(bot)[source]

Reacts on space bonding

This function should be expanded in sub-class, where necessary.

Example:

def on_bond(self, bot):
    self.db = Driver.open(bot.id)
on_dispose()[source]

Reacts on space disposal

This function should be expanded in sub-class, where necessary.

Example:

def on_disposal(self):
    self.db = Driver.close()
on_init(**kwargs)[source]

Handles extended initialisation parameters

This function should be expanded in sub-class, where necessary.

Example:

def on_init(self, prefix='secondary.space', **kwargs):
    ...
put(event)[source]

Processes one event

Parameters:event (Event or Message or Join or Leave) – inbound event

The default behaviour is to write text to sys.stdout so it is easy to redirect the stream for any reason.