Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frutik/asterisk-ami-pgsql
This is a middleware which wraps the Asterisk's AMI interface commands into Postgres/SQL functions
https://github.com/frutik/asterisk-ami-pgsql
Last synced: 13 days ago
JSON representation
This is a middleware which wraps the Asterisk's AMI interface commands into Postgres/SQL functions
- Host: GitHub
- URL: https://github.com/frutik/asterisk-ami-pgsql
- Owner: frutik
- Created: 2011-04-21T13:08:58.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2018-06-11T11:28:59.000Z (over 6 years ago)
- Last Synced: 2024-07-03T09:21:05.923Z (4 months ago)
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 16
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
- Changelog: ChangeLog
Awesome Lists containing this project
README
## What is this
Attempt to provide access to Asterisk's AMI via Postgres/SQL
## Features
- You can have access to the asterisk's ami from any programming languages which supports access to the postgresql.
- You can employ all power of sql language: sorting, filtering by where clauses, grouping, join resulting output
of ami commands (like ordinary database tables) with the real tables.
- You can use your Asterisk as source of data for ETL processes. For example, to collect some stats.# Require
- Postgresql server with installed plpython
- Asterisk server with enabled and configured AMI
- Python and pip package manager
- Pyst python module (https://github.com/al-the-x/pyst)On CentOS 6.3
- install repo from http://yum.postgresql.org/repopackages.php
- refresh metainfo: yum update
- yum install postgresql92-server postgresql92-plpython# Installation
- Install dependencies:
sudo pip install https://github.com/al-the-x/pyst/tarball/master
- Install python module:
sudo pip install https://github.com/frutik/asterisk-ami-pgsql/tarball/master
- Create database (if not exists) and add plpython (if not exists):
createdb -U postgres asteriskcreatelang plpythonu -U postgres asterisk
- Install sql part:
psql -U postgres asterisk -f [TODO : add path to this file]install.sql- Add your server and required credentials into asterisk.managers table:
insert into asterisk.managers values ('192.168.1.1', 'me', 'mysecret');
# Upgrade
- Download new version
- Perform install procedure again# Usage
## Call White House's contact center
asterisk=# select asterisk.originate_async('localhost', 'SIP/117', '92024561111', 'default', 1);
originate_async
-----------------
t
(1 row)## Show 3 online peers
asterisk=# select * from asterisk.sippeers('localhost') where "IPport" <> '0' limit 3;
ipport | status | chanobjecttype | natsupport | objectname | realtimedevice | dynamic | acl | videosupport | channeltype | ipaddress | event
--------+------------+----------------+------------+------------+----------------+---------+-----+--------------+-------------+----------------+-----------
5060 | OK (5 ms) | peer | yes | 216 | no | yes | no | no | SIP | 10.1.10.4 | PeerEntry
2254 | OK (12 ms) | peer | yes | 215 | no | yes | no | no | SIP | 10.1.10.3 | PeerEntry
2253 | OK (12 ms) | peer | yes | 214 | no | yes | no | no | SIP | 10.1.10.3 | PeerEntry
(3 rows)## Check peer
asterisk=# select "Address-Port", "Status", "CodecOrder", "SIP-Useragent", "MaxCallBR", "Busy-level" from asterisk.sipshowpeer('127.0.0.1', '1117');
Address-Port | Status | CodecOrder | SIP-Useragent | MaxCallBR | Busy-level
--------------+-------------+--------------------+---------------+-----------+------------
5060 | OK (234 ms) | ulaw,alaw,g729,gsm | NetDial | 384 kbps |
(1 row)## Add agent to queue
select asterisk.queue_add('localhost', 'incomming_queue', 'AGENT/007');
## Remove agent from queue
select asterisk.queue_remove('localhost', 'incomming_queue', 'AGENT/007');
## Show queue statusasterisk=# select * from asterisk.queue_members('localhost', 'test_te') where "Name" = 'SIP/1113';
Queue | Name | Location | Membership | Penalty | CallsTaken | LastCall | Status | Paused
---------+----------+----------+------------+---------+------------+----------+--------+--------
test_te | SIP/1113 | SIP/1113 | dynamic | 1 | 0 | 0 | 5 | 0
(1 row)## Check customers waiting in queue
test=# select * from asterisk.queue_entries('127.0.0.1', 'test_te');
Queue | Position | Channel | CallerID | CallerIDName | Wait
---------+----------+---------------------+----------+--------------+------
test_te | 1 | SIP/430913-02c3aef0 | 430913 | 430913 | 69
(1 row)## Check general stats of queue
test=# select * from asterisk.queue_params('127.0.0.1', 'test_te');
Queue | Max | Calls | Holdtime | Completed | Abandoned | ServiceLevel | ServicelevelPerf | Weight
---------+-----+-------+----------+-----------+-----------+--------------+------------------+--------
test_te | 0 | 1 | 65 | 693 | 284 | 60 | 71.6 | 0
(1 row)## Join with the real table
You can do this. But examples will be provided later...
## Limitations
- This solution is not for scaling of access to AMI - you still need use some kind of ami proxy.
- This solution "just works for me". This is not best example of python code.
- Keep in mind - some of those commands could be slow.[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/frutik/asterisk-ami-pgsql/trend.png)](https://bitdeli.com/free "Bitdeli Badge")