There are so many methods are available to to import CSV file into MySQL database. Here I am going to tell you how to import Asterisk CDR (Call Detail Record) file into MySQL database. To complete this task i am going to use PHP script to read CSV records and insert these records into MySQL [].
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 Here are some features of Asterisk-stat. CDR report (monthly or daily).
Monthly traffic. Daily load. Compare call load with previous days.
![Download Download](/uploads/1/2/5/4/125492925/618723696.png)
![Install asterisk on debian Install asterisk on debian](http://im1.asset.yvimg.kz/userimages/akehayc/7V2EK5rGhjDf1cJKZn0Ld48RRLOJry.png)
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 or download the auto install script form To get started, install the Apache web server, PHP and MySQL database. Run this command in the console.
Wget tar -zxvf asterisk-addons-1.2.8.tar.gz make clean make make install Copy the file cdrmysql.conf.sample from configs directory to /etc/asterisk, rename it to cdrmysql.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 cdraddonmysql.so under the global section. global load = cdraddonmysql.so Login to your MySQL server and create a root password to secure your server then create a database to store your CDR records. Wget tar -zxvf asterisk-stat-v201.tar.gz Rename asterisk-stat-v201 to asterisk-stats and edit the defines.php in /lib directory. Define ('WEBROOT', '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 ('DBTYPE', 'mysql'); define ('DBTABLENAME', 'cdr'); Create a symlink from cdr.php to index.php.
Ln -sf cdr.php index.php And the URL would be: 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 exportpdf.php from: includeonce(dirname(FILE). '/lib/fpdf.php'); to: includeonce(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. 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.
Store Asterisk CDRs to SQLITE3 The cdrsqlite module was deprecated and has been removed. Users of this module should use the cdrsqlite3custom module instead.
If Asterisk is compiled from source, then providing that SQLite3 is installed, then during make menuselect under Call Detail Recording, cdrsqlite3custom can be selected for installation. For those using Asterisk via RPMs such as in the popular free PBX system, then something like yum install asterisk11-sqlite3.x8664. Do yum search sqlite3 to find the correct module for your version of Asterisk. There is only one config file for the cdrsqlite3custom.so module, this is configured at /etc/asterisk/cdrsqlite3custom.conf and the default settings are as follows. Note - if the database server is hosted on the same machine as the; asterisk server, you can achieve a local Unix socket connection by; setting hostname=localhost;; port and sock are both optional parameters.
If hostname is specified; and is not 'localhost', then cdrmysql will attempt to connect to the; port specified or use the default port. If hostname is not specified; or if hostname is 'localhost', then cdrmysql will attempt to connect; to the socket file specified by sock or otherwise use the default socket; file.; global hostname=localhost dbname=asteriskcdrdb password=password user=asteriskcdruser table=cdr;port=3306;sock=/tmp/mysql.sock;userfield=1 Enable the last option userfield if you wish to use SetCDRUserField.
Configure with your hostname, dbname, password, user and table. After installation, restart asterisk. To check that CDR are being written to the MySQL DB with the following. Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with; or g. Your MySQL connection id is 4862 Server version: 5.5.44-0ubuntu0.12.04.1 (Ubuntu) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or ' h' for help. Type ' c' to clear the current input statement. Mysql select. from cdr LIMIT 10.
CTRL-D exits the MySQL console. $ yum -y install python-setuptools $ easyinstall supervisor $ wget -O /etc/supervisord.conf $ wget -O /etc/init.d/supervisor $ chmod +x /etc/init.d/supervisor $ supervisord -version $ /etc/init.d/supervisor stop; sleep 2; /etc/init.d/supervisor start Also make sure you have recent version of Git. Check your git version with.