Configuring Asterisk CDR and Asterisk CDR Viewer

CDR (Call Data Record), allows you to keep statistics on call activity in the MySQL database.

On the test, I set up the Asterisk CDR and the Asterisk CDR Viewer in Ubuntu Server.
Suppose that Asterisk is already installed.

First we will install the necessary components:

sudo apt-get install mysql-server php5-mysql apache2 git
sudo service apache2 restart

Let’s start creating a database in which records of calls will be saved.
Connect to MySQL:

mysql -u root -p

Create a database:

CREATE DATABASE asteriskcdrdb;

Create asteriskcdr user:

CREATE USER 'asteriskcdr'@'localhost' IDENTIFIED BY 'ixnfo.com';
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO  asteriskcdr@localhost;
flush privileges;

Switch to the base asteriskcdrdb:

use asteriskcdrdb;

And create the table:

CREATE TABLE cdr (
   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 '',
   did varchar(50) NOT NULL default '',
   recordingfile varchar(255) NOT NULL default '',
   KEY `calldate` (`calldate`),
   KEY `dst` (`dst`),
   KEY `accountcode` (`accountcode`),
   KEY `uniqueid` (`uniqueid`)
);

This completes the creation of the database, now we proceed to configure the configuration file /etc/asterisk/cdr_mysql.conf, as standard, all the lines in it are commented out.
Uncomment and specify the parameters for connecting to the mysql database in the [global] section:

[global]
hostname=localhost
dbname=asteriskcdrdb
table=cdr
password=PASSWORD
user=asteriskcdr

In the configuration file of the modules /etc/asterisk/modules.conf, the module cdr_mysql.so must be registered for the load:

load => cdr_mysql.so
noload => cdr_radius.so

Manually it can be loaded from the asterisk console like this:

sudo asterisk -rvv
module load cdr_mysql.so
module show like cdr_mysql.so

After the module is loaded, when receiving calls, the data should be entered into the database, let’s see if there is something:

mysql -u root -p
use asteriskcdrdb;
select * from cdr;

In fact, now you can use data from the database in any convenient way, for example, to add to any billing script statistics and graphs.
We’ll set up the finished Asterisk CDR Viewer.
Download the files and move them to the web server directory:

cd /tmp/
git clone https://github.com/g613/asterisk-cdr-viewer/
cd asterisk-cdr-viewer
tar -xzvf asterisk-cdr-viewer-latest.tgz
mv asterisk-cdr-viewer /var/www/asterisk-cdr-viewer
chown -R www-data:www-data /var/www/

The Russian version can be found here (supports HTML5 instead of the outdated Flash Player):
https://github.com/prog-it/Asterisk-CDR-Viewer-Mod
https://files.ixnfo.com/Soft/Asterisk-CDR-Viewer-Mod-master.zip

Copy the file with the web configuration to the directory with the web server apache2:

cp /var/www/asterisk-cdr-viewer/contrib/httpd/asterisk-cdr-viewer.conf /etc/apache2/conf-enabled/asterisk-cdr-viewer.conf
service apache2 restart

Specify the connection settings for the database for the Asterisk-CDR-viewer in the file /var/www/asterisk-cdr-viewer/include/config.inc.php

After that you will be able to view the statistics by opening in the browser http://SERVER/acdr

In version 1.0.9, I noticed a typo in the code, because of which a white screen was displayed and there was an error in the logs:

PHP Parse error: syntax error, unexpected ‘[‘ in /var/www/asterisk-cdr-viewer/index.php on line 23

To fix this, open the file index.php and at the end of the 23 line we will see the missing $:

$startmonth = is_blank($_REQUEST['startmonth']) ? date('m') : printf('%02d',_REQUEST['startmonth']);

It should be like this:

$startmonth = is_blank($_REQUEST['startmonth']) ? date('m') : printf('%02d',$_REQUEST['startmonth']);

Done.

See also my articles:
How to configure ODBC for Asterisk
Solution the error “rc_avpair_new: unknown attribute 1490026597”

Join the Conversation

1 Comment

Leave a Reply

  1. worked like a charm on Centos 7 sub apt-get for yum corrected the path for apache but up and running in 25 min now just to get the old data into the db