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(calltype: int, **kwargs)[source]

This class is a dictionary like object, subclassed from MutableMapping.

The fields that are used for Incoming calls:

  • number (str) - The phone number of the call.
  • line (int) - The line number that the call is on.
  • ext (int) - The extention number that the call is on.

The fields that are used for Received & Outgoing calls:

  • number (str) - The phone number of the call.
  • line (int) - The line number that the call is on.
  • ext (int) - The extention number that the call is on.
  • ring (int) - The time in seconds that the caller was ringing for.
  • duration (int) - The duration of the call in seconds.
  • answered (int/bool) (optional) Flag to indecate if the call was answered.
  • date (datetime) (optional) The datetime of the call, optional but recommended.

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.

Variables:
  • NOT_ANSWERED (int) – Mark as not answered
  • ANSWERED (int) – Mark as answered
  • VOICEMAIL (int) – Mark as farwarded to voicemail
  • INCOMING (int) – Mark as an incoming call
  • RECEIVED (int) – Mark as a reveived call
  • OUTGOING (int) – Mark as a call outgoing call
Parameters:
  • calltype (int) – The type of call record, incoming/reveived/outgoing
  • kwargs – Any field can be passed in as a keyword argument

Plugin API

class quartx_call_logger.plugins.Plugin[source]

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

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 indecate that everything is working and ready to keep monitoring.

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

This is an extended plugin with serial interface support.

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.