Plugins

Crreating Plugin

To create a plugin you first need to create a new module in the plugins directory of the quartx_call_logger package. Then create a class that inherits from either quartx_call_logger.plugins.Plugin or quartx_call_logger.plugins.SerialPlugin.

When the call logger starts up it scans the plugin directory for plugins and registers them automatically.

There is one method that is required in the plugin class, “run”. This method is the main entry point for the plugin. This method should be using a loop that checks the state of the plugin property self.running, and when true the loop should continue monitoring the call logs.

from . import Plugin, Record

class VoipService(Plugin):
    def run(self):
        while self.running:
            # Run code that monitors for call logs
            ...

            # Create a call record
            record = Record(Record.INCOMING, number="0876156584", line=2, ext=101)

            # Send the call record to the monitoring frontend
            self.push(record)

Settings

If there are any required settings for the plugin, they should be added to the defaults.yml configuration file. This file is located in /quartx_call_logger/data/defaults.yml. These settings are then passed to the plugin constructor whenever the plugin is initialized.

Example settings configuration:

SiemensHipathSerial:
  # Port & baud rate settings required to communicate with the Siemen Hipath serial interface
  # port: The port where the serial device is located. e.g. /dev/ttyUSB0 on GNU/Linux or COM3 on Windows
  # rate: Baud rate used when communicating with the serial interface, such as 9600
  port: /dev/ttyUSB0
  rate: 9600

Note

The name for the plugin settings needs to be the exact name given to the plugin class.

Record API

class quartx_call_logger.record.Record[source]

This class is a dictionary like object.

Fields that are common to all call types.

  • call_type (int) - The type of call record, incoming/received/outgoing
  • line (int) - The line number that the call is on.
  • ext (int) - The extention number that the call is on.
  • number (str) - (optional) The phone number of the caller. If not givin, ‘+353000000000’ is used.
  • date (datetime) - (optional) The datetime of the call, optional but recommended.

Extra fields that are used for Received & Outgoing calls:

  • ring (int) - (optional) The time in seconds that the caller was ringing for. Defaults = 0
  • duration (int) - (optional) The duration of the call in seconds. Defaults = 0
  • answered (int/bool) - (optional) Indicate if call was answered. Determined by duration if not given.

Note

duration & ring may also be in the format of HH:MM:SS.

Note

date must be in the ISO 8601 format e.g. 2019-08-11T01:49:49+00:00. UTC is preferred.

There are 10 possible call types. Currently only the first 3 are processed, this will change in the future when we have more data to determine best way to process them.:

  • 0 Incoming call.
  • 1 Received call.
  • 2 Outgoing call.
  • 3 Received call (Other Service).
  • 4 Outgoing call (Other Service).
  • 5 Received call (Farwarded).
  • 6 Outgoing call (Farwarded).
  • 7 Received conference call.
  • 8 Outgoing conference call.
  • 9 Outgoing call Via Farwarded.

Plugin API

class quartx_call_logger.plugins.Plugin[source]

This is the Base Plugin class for all phone system plugins.

Note

This class is not ment to be called directly, but subclassed by a Plugin.

timeout = 10

The timeout setting in seconds. Can be changed in the user config.

timeout_decay = 1.5

The timeout decay, used to increase the timeout after each failed connection. Can be changed in the user config.

max_timeout = 300

The max timeout in seconds, the timeout will not decay past this point. Can be changed in the user config.

base_timeout = 10

The base timeout value without decay

logger = logging.Logger

The logger object associated with this plugin

push(record: quartx_call_logger.record.Record) → NoReturn[source]

Send a call log record to the call monitoring API.

run() → NoReturn[source]

Main entry point for plugin. Must be overridden

running

Flag to indicate that everything is working and ready to keep monitoring.

settings = <module 'quartx_call_logger.settings' from '/home/docs/checkouts/readthedocs.org/user_builds/quartx-call-logger/checkouts/latest/quartx_call_logger/settings.py'>

Public settings

class quartx_call_logger.plugins.SerialPlugin(port: str, rate: int)[source]

This is an extended plugin with serial interface support.

Note

This class is not ment to be called directly, but subclassed by a Plugin.

Parameters:
  • port – The port/path to the serial interface.
  • rate – The serial baud rate to use.
decode(data: bytes) → str[source]

Overide this method to handel decoding of serial data.

Parameters:data – The raw data line from the serial interface as type bytes.
Returns:The decoded into data line as type str.
parse(data: str) → quartx_call_logger.record.Record[source]

Overide this method to handel parsing of serial data.

Parameters:data – The decoded data line.
Returns:A quartx_call_logger.record.Record object.