📜 ⬆️ ⬇️

New web-interface of statistics and listening to calls for Asterisk IP PBX

The idea of ​​writing web-based statistics and listening to calls for IP PBX Asterisk has not left me for several years. The solutions found on the Internet did not suit for some criteria - somewhere there was not enough functionality, some of them were not at all pleasing to the eye.

And so, armed with a stack of technologies and riding a war horse provided by ServerClub , I set off.

The result of my trip was a new interface , with diagrams, graphs and the ability to download and listen to calls. I will not continue to bore you with words, here are a couple of screenshots:
')


And under the cut you will find a video guide on the interface, the necessary settings and a detailed description of all the available functionality.

Interface.


So that the post did not look like a sheet from the screenshots, I made a small slideshow where you can familiarize yourself with the interface.



Description. What is ready, plans.


Currently the following functionality is implemented:

Incoming calls:


Outgoing calls:


* outgoing reports are generated only by calls to the world, i.e. internal calls between employees are not counted

Several settings are also available, indicating whether Asterisk uses the queue * and the path to the call recording files on the server.
* implemented in the settings, but not yet in the interface

In the near future add:


Asterisk. Settings


To work with the described interface, Asterisk version 1.8 and higher is required. At the PBX, the cdr, cel and queue_log tables in the MySQL database should be configured. If you have not done it yet, then I will tell you how.

I will also give an example of setting up a dialplan Asterisk, for organizing the preservation of records of conversations.

We configure Asterisk for work with MySQL
1. Install the necessary packages (for example in Debian / Ubuntu)
aptitude install unixodbc-dev libmyodbc 

2. Asterisk should be built with the following options.


3. Next, edit a few config files.
small hint if odbc-connector does not cling
I caught a bug on one of the systems, in which the connector for some reason stopped clinging and the aster fell into the crust:

Core was generated by `asterisk -cvvvvvvvgd '.

Program terminated with signal 8, Arithmetic exception.

# 0 0x00007ff4cc77a61b in sqlchar_as_sqlwchar () from /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so

I decided that I downloaded the latest version from the MySQL site - dev.mysql.com/downloads/file/?id=461779

I unpacked it into / usr / lib / x86_64-linux-gnu / odbc /

and slightly fixed the config

/etc/odbcinst.ini

 [MySQL] Descripti driver Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc5w.so Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmy5S.so CPTimeout = CPReuse = 


/etc/asterisk/res_odbc.conf

 [asterisk] enabled => yes dsn => MySQL-asterisk username => asterisk_user password => 232d2edxse3e 

cdr_adaptive_odbc.conf

 [cdr_adaptive_connection] connection=asterisk table=cdr alias start => calldate # ,     ,   ,      #alias dst => does_not_exist #alias realdst => dst 

/etc/odbc.ini

 [MySQL-asterisk] Description = MySQL Asterisk database ;Trace = Off ;TraceFile = stderr Driver = MySQL Server = localhost User = asterisk_user Password = 232d2edxse3e ;Port = 3306 Socket = /var/run/mysqld/mysqld.sock Database = asterisk Charset = utf8 

/etc/odbcinst.ini

 [MySQL] Description = MySQL driver Driver = /usr/lib/odbc/libmyodbc.so Setup = /usr/lib/odbc/libodbcmyS.so CPTimeout = CPReuse = 

* for x64
 [MySQL] Description = MySQL driver Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so CPTimeout = CPReuse = 

In the end
cdr_mysql.conf

add
 alias filename => filename 

4. Create a database and a cdr table in MYSQL
 mysql> create database asterisk; mysql> use asterisk; mysql> CREATE TABLE `cdr` ( `id` int(9) unsigned NOT NULL AUTO_INCREMENT, `calldate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `clid` varchar(80) NOT NULL DEFAULT '', `src` varchar(80) NOT NULL DEFAULT '', `dst` varchar(80) NOT NULL DEFAULT '', `dcontext` varchar(80) NOT NULL DEFAULT '', `channel` varchar(80) NOT NULL DEFAULT '', `dstchannel` varchar(80) NOT NULL DEFAULT '', `lastapp` varchar(80) NOT NULL DEFAULT '', `lastdata` varchar(80) NOT NULL DEFAULT '', `duration` int(11) NOT NULL DEFAULT '0', `billsec` int(11) NOT NULL DEFAULT '0', `disposition` varchar(45) NOT NULL DEFAULT '', `amaflags` int(11) NOT NULL DEFAULT '0', `accountcode` varchar(20) NOT NULL DEFAULT '', `uniqueid` varchar(32) NOT NULL DEFAULT '', `userfield` varchar(255) NOT NULL DEFAULT '', `filename` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`), KEY `calldate` (`calldate`), KEY `accountcode` (`accountcode`), KEY `uniqueid` (`uniqueid`), KEY `dst` (`dst`), KEY `src` (`src`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; mysql> grant all on asterisk.* to 'asterisk_user'@'localhost' identified by '232d2edxse3e'; 

5. cel table
 mysql>CREATE TABLE `cel` ( `id` int(11) NOT NULL AUTO_INCREMENT, `eventtype` varchar(30) NOT NULL, `eventtime` datetime NOT NULL, `cid_name` varchar(80) NOT NULL, `cid_num` varchar(80) NOT NULL, `cid_ani` varchar(80) NOT NULL, `cid_rdnis` varchar(80) NOT NULL, `cid_dnid` varchar(80) NOT NULL, `exten` varchar(80) NOT NULL, `context` varchar(80) NOT NULL, `channame` varchar(80) NOT NULL, `src` varchar(80) DEFAULT NULL, `dst` varchar(80) DEFAULT NULL, `channel` varchar(80) DEFAULT NULL, `dstchannel` varchar(80) DEFAULT NULL, `appname` varchar(80) NOT NULL, `appdata` varchar(80) NOT NULL, `amaflags` int(11) NOT NULL, `accountcode` varchar(20) NOT NULL, `uniqueid` varchar(32) NOT NULL, `linkedid` varchar(32) NOT NULL, `peer` varchar(80) NOT NULL, `userdeftype` varchar(255) NOT NULL, `eventextra` varchar(255) DEFAULT NULL, `userfield` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `uniqueid_index` (`uniqueid`), KEY `linkedid_index` (`linkedid`), KEY `eventtime` (`eventtime`), KEY `exten` (`exten`), KEY `eventtype` (`eventtype`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; 

6. Now create a label queue_log
 mysql> CREATE TABLE IF NOT EXISTS `queue_log` ( id int(10) UNSIGNED NOT NULL AUTO_INCREMENT, time timestamp NULL DEFAULT '0000-00-00 00:00:00', callid varchar(32) NOT NULL default '', queuename varchar(32) NOT NULL default '', agent varchar(32) NOT NULL default '', event varchar(32) NOT NULL default '', data1 varchar(100) NOT NULL default '', data2 varchar(100) NOT NULL default '', data3 varchar(100) NOT NULL default '', data4 varchar(100) NOT NULL default '', data5 varchar(100) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; mysql> \q Bye 

6. /etc/asterisk/extconfig.conf
in /etc/asterisk/extconfig.conf
/etc/asterisk/extconfig.conf

the string
 queue_log => odbc,asterisk 

7. Restart Asterisk and check the connection.
 *CLI> odbc show asterisk ODBC DSN Settings ----------------- Name: asterisk DSN: MySQL-asterisk Last connection attempt: 1970-01-01 07:00:00 Pooled: No Connected: Yes 

8. It is also worth calling to check if the data falls into the database.

Dialplan Asterisk - excerpt from /etc/asterisk/extensions.ael
 globals { WAV=/var/calls; //   WAV MP3=/var/calls; //  mp3  RECORDING=1; // , 1 - . }; macro recording (calling,called) { if ("${RECORDING}" = "1"){ Set(fname=${UNIQUEID}-${STRFTIME(${EPOCH},,%Y-%m-%d-%H_%M)}-${calling}-${called}); Set(datedir=${STRFTIME(${EPOCH},,%Y/%m/%d)}); System(mkdir -p ${MP3}/${datedir}); System(mkdir -p ${WAV}/${datedir}); Set(monopt=nice -n 19 /usr/bin/lame -b 32 --silent "${WAV}/${datedir}/${fname}.wav" "${MP3}/${datedir}/${fname}.mp3" && rm -f "${WAV}/${fname}.wav" && chmod o+r "${MP3}/${datedir}/${fname}.mp3"); Set(CDR(filename)=${fname}.mp3); Set(CDR(recordingfile)=${fname}.wav); Set(CDR(realdst)=${called}); MixMonitor(${WAV}/${datedir}/${fname}.wav,b,${monopt}); }; }; _XXXXXX => { &recording(${CALLERID(number)},${EXTEN}); Dial(SIP/83843${EXTEN}@multifon,180,tT); HangUP(); } // end of _XXXXXX 


Conversation Record Files Go Straight Into
/var/calls

where have the following hierarchy
 ls /var/calls/2016/ -l total 24 drwxr-xr-x 19 asterisk asterisk 4096 May 31 10:10 05 drwxr-xr-x 30 asterisk asterisk 4096 Jun 30 10:02 06 drwxr-xr-x 31 asterisk asterisk 4096 Jul 31 10:18 07 drwxr-xr-x 31 asterisk asterisk 4096 Aug 31 09:00 08 drwxr-xr-x 26 asterisk asterisk 4096 Sep 26 09:51 09 


Asterisk. Connection to the statistics interface


It is time to dispel some doubts, or confirm some guesses. Yes - currently the service is provided according to the SAAS model, i.e. A client is installed on your PBX to synchronize the database and call records.

After registration (I don’t think it’s worthwhile to dwell on it - everything’s as usual), you need to go to your personal account at stat.vistep.ru , go to the settings, specify the path to the recording files and click “Save”. After that, the link to download the client script will be available.

To install the script, follow these steps:

1. Install nodejs and npm package manager on the server, if they are not already installed (using yum or apt/aptitude/apt-get )

2. Install pm2

 npm install -g pm2 

3. Create and go to the folder /opt/stat.vistep.ru

 mkdir /opt/stat.vistep.ru cd /opt/stat.vistep.ru 

4. Place the archive with the script in the folder created by the step earlier, and unpack it

 unzip skript_name.zip 

5. Edit the script, making changes to lines 393 - 397 (and 398 - optionally, if you are familiar with regexp), namely

 "dbhost":"localhost", "dbuser":"asterisk_user", "dbpassword":"232w2edxse3e", "db":"asterisk", "timezone":"Asia/Novokuznetsk", // <---   "fileMask": /\.*/ // 

6. Run the script for execution:

 pm2 start stat.vistep.ru.js --name "ViStep.RU stat" 

7. Configure autorun / shutdown of the synchronization script with the OS:

 pm2 startup ubuntu # centos, gentoo pm2 save 

With the settings on it all. It remains to wait for the data to be downloaded to the statistics server and start using!

Terms of Service


At the moment we offer 2 options for cooperation on the product Stat.ViStep.RU :

- Local version , for permanent use.
All updates will be available to you at no additional charge.

- Cloud version .
Updates are included in the monthly fee.

Assistance in installing / configuring the product is free in both versions.

All the details you can find out by writing to us at sales@vistep.ru

Conclusion


That ended my tale of the journey and its results. But only the tale, not the journey itself - it is just beginning. I believe that many more accomplishments, exciting paths and interesting quests are waiting for me.

For help in setting up Asterisk, you are welcome to email us at support@vistep.ru.
If there is a question about cooperation, terms of service or something else, then I am waiting for letters to sales@vistep.ru

Also, all my contacts are in my profile and, of course, I will be happy to answer your questions in the comments.

Demo access:
support@vistep.ru
0jnoiLJNFDr4-3r2f4

For this, let me finish. Thank you for attention!

Source: https://habr.com/ru/post/310988/


All Articles