Configuring CEL in Asterisk

At the right time, Asterisk is gaining more and more popularity, it is used not only by organizations, but also by ordinary people, and for its users the question arises of charging calls. For example, in a relatively simple system, where the accuracy is not significant, you can get by using the standard CDR (Call Detail Record) module, which has three events: “Start”, “Answer”, “End” of the call and keep track of time as the difference between the end of the call and answering a call, but what if we have a call with a non-zero probability that can be diverted or put on hold? For this purpose, Asterisk has a CEL (Channel Event Logging) module, and under the cut I will describe its concept and configuration example.

So, the main object in Asterisk is the “Channel”, the connection between the two communication ports is based on it. It makes sense to have an event system that records important events, each event joins a channel, for example ANSWER or HANGUP. CEL generates events that can be collected in one place and subsequently used to calculate statistics.

Key events at CEL:
EventDescription
CHAN_STARTchannel creation time
CHAN_ENDchannel completion time
ANSWER response time
HANGUPtime when the subscriber “hung up”
CONF_ENTERconference inclusion time
CONF_EXITconference channel deletion time
CONF_STARTconference entry time of the first subscriber
CONF_ENDtime the last subscriber leaves the conference
APP_STARTapplication launch time
APP_ENDapplication completion time
PARK_STARTcall suspension start time
PARK_ENDpause time
BRIDGE_STARTbridge launch time
BRIDGE_ENDbridge completion time
BRIDGE_UPDATEchannel override ()
3WAY_STARTgenerated when a conference with 3 participants is started, usually used for conditional call forwarding
3WAY_END
BLINDTRANSFERthis event occurs when the call is forwarded unconditionally
ATTENDEDTRANSFERoccurs when conditional call forwarding
Forwardevent occurs when the channel is redirected
Hookflashevent generated when the DAHDI interface hangs up
USER_DEFINEDdepends on the dialplan and has a name given by the user


After reviewing the CEL concept, you can begin to configure it. The goal is to record all events in the MySql database, all work with the database will be done using ODBC.
Before configuring ODBC in Asterisk, you must install the necessary packages in the system: (if you are using a system other than Debian, you should use a different package manager) The configuration for the MySQL ODBC driver is performed in the /etc/odbcinst.ini file Configuration example: If the specified directories are there are no specified paths, they can be in another directory, they can be easily found, it is enough to execute the following commands:
apt-get install unixODBC unixODBC-dev libmyodbc




[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/odbc/libmyodbc.so
Setup = /usr/lib/odbc/libodbcmyS.so
FileUsage = 1


:~# updatedb
:~# locate libmyodbc.so
:~# locate libodbcmyS.so
The last two commands will show the location of the libraries on the screen, let's go through the corresponding path, for example: /usr/lib/i386-linux-gnu/odbc/libmyodbc.so

The next step is to configure the /etc/odbc.ini file , which is used to create the identifier, which Asterisk will use it to refer to this configuration, if in the future you decide to change the database, you should reconfigure this file.
Here is a configuration example:
[asterisk-connector]
Description = MySQL connection to 'asterisk' database
Driver = MySQL
Database = asterisk
Server = localhost
UserName = user
Password = 123456
Port = 3306

Now we will configure Asterisk to work with the database via ODBC, for this, use the /etc/asterisk/res_odbc.conf file .
Example configuration of this file:
[asterisk]
enabled => yes
dsn => asterisk-connector
username => asterisk
password => 123456
pooling => no
pre-connect => yes
The dsn option specifies the connection that is configured in /etc/odbc.ini, and the pre-connect option tells Asterisk to raise the connection to the database when the res_odbc.so module loads.

Important: Asterisk must be built with ODBC support!
To check, you can run the command from the CLI odbc show.

And now the most important thing, we proceed to the configuration of CEL. Open the configuration file. Open the /etc/asterisk/cel.conf config and make the following changes to it:
[general]
enable=yes
apps=all
events=all
dateformat = %F %T

apps - this option indicates which applications should be monitored.
events - with this option we indicate which events (from the table above) should be entered in the database.
Next, you need to edit the file /etc/asterisk/cel_custom.confuncomment the [mappings] section in it.

And the last file to be edited /etc/asterisk/cel_odbc.conf , we will make the following changes to it:
[first]
connection=asterisk
table=cel
loguniqueid=yes
The connection option specifies the name of the connector from the res_odbc.conf file , and the table option specifies the name of the database table for saving data.

The testament of tuning is to create a database and table.
:~# mysql –uroot –p
mysql> CREATE DATABASE asterisk;
mysql> use asterisk;
mysql> CREATE TABLE IF NOT EXISTS `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) NOT NULL,
`dst` varchar(80) NOT NULL,
`channel` varchar(80) NOT NULL,
`dstchannel` varchar(80) NOT 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) NOT NULL,
`userfield` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `uniqueid_index` (`uniqueid`),
KEY `linkedid_index` (`linkedid`)
);

Restart Asterisk.

Verification of work is carried out using commands from the Asterisk CLI:
cel show status
odbc show

This is the configuration, it remains to make a test call and look at the contents of the table.

Also popular now: