10.6.4. Counter Handler Module

The counter event handler module is used to count certain events. You can define arbitrary counter names and each occurrence of an event will modify the counter in the counter table according to the selected action.

These counters can be used to graph time series of failed authentication, assigned tokens, user numbers or any other data with any condition over time.

10.6.4.1. Possible Actions

10.6.4.1.1. increase_counter

This action increases the counter in the database table eventcounter. If the counter does not exist, it will be created and increased.

10.6.4.1.2. decrease_counter

This action decreases the counter in the database table eventcounter. If the counter does not exist, it will be created and decreased.

Note

This action will not decrease the counter beyond zero unless the option allow_negative_values is enabled.

10.6.4.1.3. reset_counter

This action resets the counter in the database table eventcounter to zero.

10.6.4.2. Possible Options

10.6.4.2.1. counter_name

This is the name of the counter in the database. You can have as many counters in as many event handlers as you like.

10.6.4.2.2. allow_negative_values

Only available for the decrease_counter action. Allows the counter to become negative. If set to False (default) decreasing stops at zero.

Note

Since the option allow_negative_values is an attribute of the counter event handler action (and not the counter itself in the database) it is possible to define multiple event handlers accessing the same counter. Thus if a negative counter is accessed by an event handler with the option allow_negative_values set to false, the counter will be reset to zero.

10.6.4.3. Code

This is the event handler module for increasing/decreasing/resetting database counters. These counters can be used by rrdtool to monitor values and print time series of certain parameters.

class privacyidea.lib.eventhandler.counterhandler.CounterEventHandler[source]

An CounterEventHandler needs to return a list of actions, which it can handle. It also returns a list of allowed action and conditions It returns an identifier, which can be used in the eventhandling definitions

property actions

This method returns a dictionary of allowed actions and possible options in this handler module.

Returns:

dict with actions

property allowed_positions

This returns the allowed positions of the event handler definition. :return: list of allowed positions

description = 'This event handler increases arbitrary counters in the database.'
do(action, options=None)[source]

This method executes the defined action in the given event.

Parameters:
  • action

  • options (dict) – Contains the flask parameters g, request, response and the handler_def configuration

Returns:

identifier = 'Counter'