登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

baikgd的博客

技术是工具,生活是目的,更好的生活是目标!

 
 
 

日志

 
 

Installing a web-based Asterisk CDR analyzer  

2009-09-17 11:19:52|  分类: Asterisk |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

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-....

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 -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.

  评论这张
 
阅读(1226)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018