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.
Start the Apache and MySQL and make sure that it will run during boot time by typing this command.
chkconfig httpd on
service mysqld start
chkconfig mysqld on
Go to /usr/src/directory, download and install asterisk-addon source from Asterisk website.
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.
SET PASSWORD FOR root@localhost = PASSWORD ('password');
Create Asterisk CDR databases and user to the databases.
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.
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.
select uniqueid, src, calldate from cdr;
You can also check in Asterisk console by typing this Asterisk command:
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.
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
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.


Delicious
Digg
StumbleUpon
Furl
Facebook
Twitter
Google
Yahoo
Buzz Up!
LinkedIn
Technorati



Comments
Restart the box as stated in the instructions!
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
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
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
28 May 2008
23 hours 1 min
Hey Diego, I received your message. Apparently, it was considered spam by spam filter...
Anyway, maybe you don't have php installed, or you didn't install it correctly? Please check your php installation using this script:
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.
28 May 2008
23 hours 1 min
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.
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