Installing a web-based Asterisk CDR analyzer

By default Asterisk generates CDR records in a CSV files located in /var/log/asterisk/cdr-csv directory. Asterisk can also store CDR records in a database such as MySQL or PostgreSQL database as an alternative to CSV files. If your CDR records are stored in a database, you can install a web-based CDR analyzer to easily manage and analyze your CDR records like Asterisk-stat by http://areski.net.

Here are some features of Asterisk-stat

  • CDR report (monthly or daily)
  • Monthly traffic
  • Daily load
  • Compare call load with previous days
  • Many criterias to define the report
  • Export CDR report to PDF and CSV
  • Support MySQL and PostgreSQL database
  • Many others

To install asterisk-stat, you need to install HTTP server, PHP and MySQL database. I assume that you are running CentOS 4.4 or higher and have Asterisk 1.2 installed in you server. To install Asterisk 1.2, checkout this tutorial http://www.cahilig.org/install-asterisk-12-centos-4-and-centos-5 or download the auto install script form http://www.cahilig.org/install-asterisk-12-auto-install-script-centos-4-and-centos-5.

To get started, install the Apache web server, PHP and MySQL database. Run this command in the console.

apt-get install httpd php php-mysql php-gd mysql mysql-devel mysql-server

Start the Apache and MySQL and make sure that it will run during boot time by typing this command.

service httpd start
chkconfig httpd on
service mysqld start
chkconfig mysqld on

Go to /usr/src/directory, download and install asterisk-addon source from Asterisk website.

wget http://downloads.digium.com/pub/asterisk/releases/asterisk-addons-1.2.8.tar.gz
tar -zxvf asterisk-addons-1.2.8.tar.gz
make clean
make
make install

Copy the file cdr_mysql.conf.sample from configs directory to /etc/asterisk, rename it to cdr_mysql.conf. Edit the database configuration.

[global]
hostname=localhost
dbname=asteriskcdrdb
table=cdr
password=password
user=asterisk
port=3306

Then edit your /etc/asterisk/modules.conf and add the cdr_addon_mysql.so under the [global] section.

[global]
load => cdr_addon_mysql.so

Login to your MySQL server and create a root password to secure your server then create a database to store your CDR records.

mysql -u root
SET PASSWORD FOR root@localhost = PASSWORD ('password');

Create Asterisk CDR databases and user to the databases.

create database asteriskcdrdb;
GRANT SELECT,INSERT ON asteriskcdrdb.* TO asterisk@localhost IDENTIFIED BY 'password';

Create a table called cdr under the database name you will be using the following schema.

USE asteriskcdrdb;
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 ''
);

quit

Restart your Asterisk PBX, start making a call and check if the CDR is written in your database.

use asteriskcdrdb;
select uniqueid, src, calldate from cdr;

You can also check in Asterisk console by typing this Asterisk command:

asterisk -ncrvvvvvvvvvv
cdr mysql status

It will display the message that look exactly like this:

Connected to asteriskcdrdb@localhost using table cdr for 0 hours, 15 minutes, 15 seconds.
Wrote 1 records since last restart.

If you see the message similar from above, you have successfully installed asterisk-addon.

Go to /var/www/html/ directory and grab asterisk-stats package from http://areski.net.

wget http://areski.net/asterisk-stat-v2/asterisk-stat-v2_0_1.tar.gz
tar -zxvf asterisk-stat-v2_0_1.tar.gz

Rename asterisk-stat-v2_0_1 to asterisk-stats and edit the defines.php in /lib directory.

define ("WEBROOT", "http://hostname/asterisk-stats/");
define ("FSROOT", "/var/www/html/asterisk-stats/");



define ("LIBDIR", FSROOT."lib/");


define ("HOST", "localhost");
define ("PORT", "3306");
define ("USER", "asterisk");
define ("PASS", "password");
define ("DBNAME", "asteriskcdrdb");
define ("DB_TYPE", "mysql");


define ("DB_TABLENAME", "cdr");

Create a symlink from cdr.php to index.php

ln -sf cdr.php index.php

And the URL would be:
http://hostname/asterisk-stats

The asterisk-stats v2.0.1 has a bug when you are exporting CDR in pdf format.
To fix the bug, you need to change line 5 of export_pdf.php from:

include_once(dirname(FILE) . "/lib/fpdf.php');

to:

include_once(dirname(FILE) . "/lib/fpdf.php");

It should be fine now, you can export your CDR to PDF files.

Your Asterisk-stat is done, however it is not yet secured, everybody can login without any authentication. If you want to put an authentication to your Asterisk-stat, just follow this howto. It will require web site visitors to login with a user id and password.

You can delete the CDR in your MySQL database using phpMyAdmin.

No votes yet

Comments

Anonymous's picture

Restart the box as stated in the instructions!

Anonymous's picture

your manual is very usefull the apache supor for php is fine i tried it and worked. the problem is when i open the localhost/asterisk-stats the browser shows "not found" some one helped me to solve before that problem it is about the index.php but i dont remember at this moment and that person is too busy.

i will be very pleased with your help

boediger

Anonymous's picture

Somehow, asterisk is still storing data to the csv file and not to my mysql database, also, command "cdr mysql status" no such command, on asterisk CLI.

Do i need to restart the linux box? so modules will reload or just asterisk restart?

Thanks in advance for your help.

JP

Anonymous's picture

your manual is very usefull the apache supor for php is fine i tried it and worked. the problem is when i open the localhost/asterisk-stats the browser shows "not found" some one helped me to solve before that problem it is about the index.php but i dont remember at this moment and that person is too busy.

i will be very pleased with your help

Richard's picture
Member since:
28 May 2008
Last activity:
23 hours 1 min

Hey Diego, I received your message. Apparently, it was considered spam by spam filter...

Diego wrote:
i follow all your instructions but when i go to http://hostname/asterisk-stats the browser doesn't find the page the myqsl database resgister all the calls so i think it is not the problem. thank you Diego G.

Anyway, maybe you don't have php installed, or you didn't install it correctly? Please check your php installation using this script:
  1. <?php
  2. ?>

Create a file called phpinfo.php and put the script above, then put the file on your /var/wwww/ directory. Open your browser and point to http://localhost/phpinfo.php. If your php configuration is ok, the browser will display a lot of info about your php configuration.

Richard's picture
Member since:
28 May 2008
Last activity:
23 hours 1 min

Diego wrote:
hey men thanks a lot

i was searching a how to install a cdr analizer the only one problem a had was when i finish the installation go to the web page http://hostname/asterisk-stats i m using debian etch

i have a lot of questions maybe you can help me

and thanks fron colombia

Welcome! I will do everything I can to help you, however I do not really understand what is your problem. Could you please elaborate your problem a little bit more.

Anonymous's picture

hey men thanks a lot

i was searching a how to install a cdr analizer the only one problem a had was when i finish the installation go to the web page http://hostname/asterisk-stats i m using debian etch

i have a lot of questions maybe you can help me

and thanks fron colombia

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may quote other posts using [quote] tags.

More information about formatting options