furemcape.responder package

Responds to issues recorded in issuedb.

class furemcape.responder.Responder(*args, **kwargs)

Bases: furemcape.shared.obj.BaseAttrObject

Analyzes each hitdb entry and adds resulting issues to issuedb.

cfg

Raw configuration data.

Type

dict

response_prototypes

Response prototype configuration.

Type

dict

responses

Loaded list of ResponseDefinition objects.

Type

list

respond_as_of

Datetime to consider as ‘now’ (defaults to now actually).

Type

DateTime

respond_within

Duration within which to respond to issues (defaults to 1 day).

Type

Duration

sleep_for

Seconds to sleep.

Type

int

running

True while running response loop.

Type

bool

LOG = <Logger furemcape.responder.responder (WARNING)>
RESPONSE_PROTOTYPES = {'EMAIL': {'danger': 5, 'processor': 'furemcape.responder.processor.EmailResponse', 'throttle': {'10m': 10, '1h': 20, '1m': 5}}}
calculate_respond_after()

Calculates the datetime after which to respond to issues.

Returns

Datetime after which to respond to issues.

Return type

DateTime

load_config(path)

Replaces configuration with specified config file.

Parameters

path (str) – Path to config file.

respond_loop()

Main responder loop.

respond_next(hit)

Responds to the specified hit.

Parameters

hit (IssueHit) – Hit to respond to.

sleep()

Sleeps for configured number of seconds.

sweep_next()

Sweeps hits whose throttling has elapsed.

validate_db()

Raises exception if db not available.

Raises
  • AttributeError – Database not initialized. # noqa: DAR402

  • DoesNotExist – Required migrations not run. # noqa: DAR402

Submodules

furemcape.responder.config module

Utilities for loading responder configuration.

furemcape.responder.config.load_config(responder, path)

Replaces responder configuration with specified config file.

Parameters
  • responder (Responder) – Responder object.

  • path (str) – Path to Furem Cape config file.

furemcape.responder.config.load_default_config(responder)

Replaces responder configuration with default config file.

Parameters

responder (Responder) – Responder object.

furemcape.responder.config.set_config(responder, cfg)

Replaces responder configuration with specified config dict.

Parameters
  • responder (Responder) – Responder object.

  • cfg (dict) – Furem Cape config dict.

furemcape.responder.responder module

Analyzes each hitdb entry and adds resulting issues to issuedb.

class furemcape.responder.responder.Responder(*args, **kwargs)

Bases: furemcape.shared.obj.BaseAttrObject

Analyzes each hitdb entry and adds resulting issues to issuedb.

cfg

Raw configuration data.

Type

dict

response_prototypes

Response prototype configuration.

Type

dict

responses

Loaded list of ResponseDefinition objects.

Type

list

respond_as_of

Datetime to consider as ‘now’ (defaults to now actually).

Type

DateTime

respond_within

Duration within which to respond to issues (defaults to 1 day).

Type

Duration

sleep_for

Seconds to sleep.

Type

int

running

True while running response loop.

Type

bool

LOG = <Logger furemcape.responder.responder (WARNING)>
RESPONSE_PROTOTYPES = {'EMAIL': {'danger': 5, 'processor': 'furemcape.responder.processor.EmailResponse', 'throttle': {'10m': 10, '1h': 20, '1m': 5}}}
calculate_respond_after()

Calculates the datetime after which to respond to issues.

Returns

Datetime after which to respond to issues.

Return type

DateTime

load_config(path)

Replaces configuration with specified config file.

Parameters

path (str) – Path to config file.

respond_loop()

Main responder loop.

respond_next(hit)

Responds to the specified hit.

Parameters

hit (IssueHit) – Hit to respond to.

sleep()

Sleeps for configured number of seconds.

sweep_next()

Sweeps hits whose throttling has elapsed.

validate_db()

Raises exception if db not available.

Raises
  • AttributeError – Database not initialized. # noqa: DAR402

  • DoesNotExist – Required migrations not run. # noqa: DAR402

furemcape.responder.response_definition module

Definition of an issue response.

class furemcape.responder.response_definition.ResponseDefinition(*args, **kwargs)

Bases: furemcape.shared.obj.BaseAttrObject

Definition of an issue response.

Parameters
  • id (str) – Response definition ID.

  • prototype (str) – Definition ID of prototype to use for response defaults.

  • danger (int) – Danger level at or above to match.

  • exclude (dict) – Dict of issue property names to values list to ignore. Example: {‘user’: [‘’, ‘-‘]}

  • include (dict) – Dict of issue property names to values list to consider exclusively. Example: {‘user’: [‘admin’, ‘root’]}

  • processor (str) – Response processor class name.

  • processor_instance (BaseProcessor) – Response processor instance.

  • throttle (dict) – Dict of throttle durations to tokens. Example: {‘1m’: 5, ‘10m’: 10}

  • throttlers (list) – List of throttle instances.

  • throttled_hits (list) – List hits queued due to throttling.

LOG = <Logger furemcape.responder.response_definition (WARNING)>
match(issue)

True if response matches issue.

Parameters

issue (Issue) – Issue to match.

Returns

True if response matches issue.

Return type

bool

process(hit)

Processes the specified hit.

Parameters

hit (IssueHit) – Hit record.

sweep()

Processes throttled hits if throttling has abated.

throttled(hit=None)

True if throttled.

If hit specified, adds hit to throttled queue if this response currently is throttled. Otherwise, just checks if this response is throttled.

Parameters

hit (IssueHit) – Hit to throttle.

Returns

True if throttled.

Return type

bool

furemcape.responder.throttle module

Token-based throttle utility.

class furemcape.responder.throttle.Throttle(tokens=1, duration=None)

Bases: furemcape.shared.obj.BaseAttrObject

Token-based throttle utility.

tokens

Max number of tokens.

Type

int

duration

Duration tokens should last.

Type

Duration

per_second

Tokens to refil per second.

Type

float

available

Available tokens (throttled when < 1).

Type

float

previous

Time of previous token check.

Type

DateTime

LOG = <Logger furemcape.responder.throttle (WARNING)>
throttled(take=False)

True if no tokens left to take.

Parameters

take (bool) – True to take a token before checking if throttled.

Returns

True if no tokens left to take.

Return type

bool