Panoramisk

repository·master·Indexed 41 days ago

https://github.com/gawel/panoramisk

An asynchronous Python library for interacting with the Asterisk Manager Interface (AMI) via TCP. Built on asyncio, it allows developers to listen to Asterisk events, execute actions, and build Fast AGI applications using the panoramisk.fast_agi module.

Tokens
1K
Snippets
5
Records
8
Agent score
51%

What's inside Panoramisk

  1. Overview of Panoramisk

    master
    Panoramisk is an asynchronous Python library built on asyncio designed to interface with the Asterisk Manager Interface (AMI). It allows developers to interact with Asterisk's TCP manager server to listen for real-time events and send actions (commands) to the Asterisk system.
  2. Configure Asterisk Manager Interface (AMI) for Panoramisk

    master

    To allow Panoramisk to communicate with Asterisk, you must configure the Asterisk Manager Interface (AMI) in your /etc/asterisk/manager.conf file. You need to create a user with appropriate permissions and restrict access to specific IP addresses using deny and permit rules.

    After updating the configuration, you must reload the manager for the changes to take effect.

    [username]
    secret=password
    deny=0.0.0.0/0.0.0.0
    permit=127.0.0.1/255.255.255.255
    read = all
    write = all

    To apply the changes, run:

    $ rasterisk -x 'manager reload'
  3. Write tests using panoramisk.testing.Manager

    master

    To test your Panoramisk code without a live Asterisk instance, use panoramisk.testing.Manager. You can initialize the manager with a stream argument pointing to a file containing an Asterisk trace (e.g., a YAML file). This allows you to simulate Asterisk actions and verify responses by sending actions through the manager and awaiting the resulting future.

    from panoramisk import testing
    
    # stream is a filename containing an Asterisk trace
    manager = testing.Manager(stream='tests/fixtures/ping.yaml')
    
    # Send an action to the simulated Asterisk
    future = manager.send_action({'Action': 'Ping'})
    
    # Retrieve the result
    resp = future.result()
    
    # Assertions
    assert 'ping' in resp
    assert resp.ping == 'Pong'
  4. Inspect AMI traffic during development

    master

    When developing with Panoramisk, you may need to inspect the precise requests and responses passing through the Asterisk Manager Interface (AMI).

    Depending on your environment, you can use the following tools:

    • Tcpdump or Wireshark: Recommended for production or heavily loaded systems.
    • Netcat: Suitable for quick inspections on a local machine.
    • netcat-middleman.sh: A provided shell script that helps log both incoming and outgoing traffic.
  5. Use the Fast AGI API to create applications

    master

    The panoramisk.fast_agi module provides a high-level API designed for building Fast AGI (Asterisk Gateway Interface) applications. The primary entry point for creating these applications is the Application class. You can use this class to manage the lifecycle and logic of your AGI-based services.

    from panoramisk.fast_agi import Application
    
    # Initialize and use the Application class to build your AGI logic
    app = Application()
  6. Use the Panoramisk Manager class

    master
    The Manager class is the primary entry point for interacting with the Asterisk Manager Interface via Panoramisk. It handles the connection and communication logic required to send commands and receive events from Asterisk.
  7. Use panoramisk.testing.Manager for simulated Asterisk traces

    master

    The Manager class in panoramisk.testing is used to mock Asterisk interactions.

    Key Parameter:

    • stream: A path to a file (typically a YAML file) that contains a recorded Asterisk trace. This stream serves as the source of truth for the simulated Asterisk behavior during the test.
    from panoramisk import testing
    
    manager = testing.Manager(stream='path/to/trace.yaml')