Asterisk CDR Mysql
Asterisk CDR Mysql
Solution Details
Become an ITSP Now!
Become a serious
competitor in VoIP Immediately
FULL Consultancy,
Installation, Training & Support
Sell Hosted IP PBXs, Biz
Lines, Call Centre
Turnkey Provisioning at
your data center
Details
Details
*Rates shown do not include E-911 charges or government mandated taxes. Providers offering unlimited calling plans may have
restrictions. Read providers terms and conditions carefully before buying.
Asterisk can store CDR records in a MySQL database, as an alternative to CSV text files and
other database formats.
Compile
it's like standard Asterisk compilation
1.
2.
3.
4.
./configure
make menuselect
make
make install
Check that in make stage that there are no mysql.h errors, which mean you are missing mysqldevel package
[root@localhost asterisk-addons-1.6.2]# make
./mkdep -fPIC -I../asterisk -D_GNU_SOURCE
`ls *.c`
app_addon_sql_mysql.c:23:19: error: mysql.h: No such file or directory
cdr_addon_mysql.c:38:19: error: mysql.h: No such file or directory
cdr_addon_mysql.c:39:20: error: errmsg.h: No such file or directory
res_config_mysql.c:53:19: error: mysql.h: No such file or directory
res_config_mysql.c:54:27: error: mysql_version.h: No such file or directory
res_config_mysql.c:55:20: error: errmsg.h: No such file or directory
If make fails due to complaining about a missing "asterisk.h" file you can either copy this file
from your asterisk directory, or create a soft link ("ln -s ...") for /usr/src/asterisk that points to
your asterisk source directory.
Another way to resolve the missing "asterisk.h" file is to run the ./configure with option "--withasterisk=" like
./configure --with-asterisk=MyAsteriskSourceDir
A sample configuration file, can be found on the cdr_mysql.conf page.
Copy the sample configuration file to /etc/asterisk/cdr_mysql.conf and edit it according to your
requirements. Then edit your modules.conf to load cdr_addon_mysql.so and finally restart
asterisk; before the restart you should, however, check that your cdr table has been created
correctly and is accessible to the username and password you specified.
Please note that the rights granted in GRANT above is the _least_ the asterisk user will need.
To allow the user to do more than just add new data to the table, see the MySQL manual on
the topic
for trunk version since 29 Dec 2007 must be:
GRANT INSERT, SELECT ...
because cdr_addon_mysql now do DESC 'cdr'; for check tables fields.
Hint: Copy and paste this SQL command into a text file, save it under an appropriate name,
then execute the following command:
mysql --user=username --password=password databasename < nameoftextfile
Voila! The table is created for you. (:biggrin:)
An interesting note: on versions prior to v1.2, the name of the table, 'cdr', is hard-coded into the
mysql interface, so if the table is created under a different name, the mysql CDR backend will
not work. In v1.2 the table name is configurable via the "table=" option in cdr_mysql.conf
Yet another note: It probably isn't a good idea to use the InnoDB engine. Asterisk keeps
autocommit turned on by default; therefore, each INSERT query is its own transaction. This will
cause the query to take significantly longer to execute. On my personal computer, the "clock
time" penalty is about 4-7 times that of MyISAM on a default Ubuntu install. Please also note
that the CDR table does not require the features that the InnoDB engine provides.
Extending CDR
MySQL to supports adaptive columns natively in Asterisk 1.6
Dec. 2007: While reading the SVN commit logs I noticed that tilghman has committed a change
to allow MySQL to write to arbitrary column names. This has been present in the ODBC
driver for some time but not in the MySQL driver. It is currently only available in trunk (what will
become 1.6) but hopefully someone will write a backport. (Might want to start here: Bug
11642). Tilghman has has more details on his blog.
cdr_addon_mysql
Module has been completely revamped, with some options in the config file
no longer used and an additional new section called [aliases]. Please read
the sample config to familiarize yourself with these changes.
Module now permits arbitrary columns to be created and populated, just like
cdr_adaptive_odbc, simply by adding the column to the table and defining
the corresponding CDR() variable. Aliases may be used to define
relationships between differently-named variables and columns (such as the
calldate column and the start CDR variable).
The calldate column, as defined in the sample configuration, uses the start
time of the call, as opposed to the old behavior of using the end time.
However, you may get the old behavior for calldate, simply by changing the
alias to "end => calldate".
Standard columns may also be excluded now, simply by dropping the
column name from the table, renaming the column, or aliasing the cdrname
from a nonexistent variable (e.g. foo => amaflags).
[some_context]
;dial trunk
exten => _X.,1,Dial(SIP/trunk/${EXTEN})
;exten h must be in same context!
exten => h,1,noop("extended CDR")
exten => h,n,set(CDR(hangupcause)=${HANGUPCAUSE})
;
hangupcause
exten => h,n,set(CDR(peerip)=${CHANNEL(peerip)})
; like
10.0.0.5 if behind nat
exten => h,n,set(CDR(recvip)=${CHANNEL(recvip)})
; like
194.79.52.192 - public ip
exten => h,n,set(CDR(from)=${CHANNEL(from)})
; like
sip:[email protected]
exten => h,n,set(CDR(uri)=${CHANNEL(uri)})
; like
sip:[email protected]
exten => h,n,set(CDR(useragent)=${CHANNEL(useragent)})
;
useragent like Aastra_57i
exten => h,n,set(CDR(codec1)=${CHANNEL(audioreadformat)})
;
codec *
exten => h,n,set(CDR(codec2)=${CHANNEL(audiowriteformat)})
;
exten => h,n,set(CDR(llp)=${CHANNEL(rtpqos,audio,local_lostpackets)})
; lost
packets by local end **
exten => h,n,set(CDR(rlp)=${CHANNEL(rtpqos,audio,remote_lostpackets)}) ; lost
packets by remote end
exten => h,n,set(CDR(ljitt)=${CHANNEL(rtpqos,audio,local_jitter)})
; the
same for jitter
exten => h,n,set(CDR(rjitt)=${CHANNEL(rtpqos,audio,remote_jitter)})
See also
Asterisk billing
Asterisk CDR csv conversion mysql
Asterisk CDR csv mysql import
Asterisk CDR csv mysql Perl import
Asterisk CDR Master.csv postgresql Perl import
Asterisk cdr odbc
Asterisk config cdr_mysql.conf
Asterisk voicemail database
Asterisk queue_log on MySQL
What is CDR
Gonzalo
4- Creamos la tabla:
mysql> USE asteriskCDR;
Database changed
Una vez hecho esto ponemos como ndices para optimizar la bsqueda por estos
campos:
ALTER TABLE `cdr` ADD INDEX ( `calldate` );
ALTER TABLE `cdr` ADD INDEX ( `dst` );
ALTER TABLE `cdr` ADD INDEX ( `accountcode` );
5- Si queremos le damos permiso para acceder solo desde nuestra PBX Asterisk
(192.168.3.2):
Para que se pueda acceder a la BBDD desde otro servidor puede que necesitemos
configurar nuestra database editando el archivo /etc/mysql/my.cnf y cambiando la
opcin bind-address = 127.0.0.1 por bind-address = 0.0.0.0 y reiniciando el
servidor service mysql restart.
A continuacin configuramos nuestra PBX Asterisk (192.168.3.2) para guardar los
CDR en esa database.
Editamos el archivo /etc/asterisk/cdr_mysql.so y ponemos algo tal que as:
[global]
hostname=192.168.3.3 ;ip de nuestra database. Si fuese local pondramos
localhost
dbname=asteriskCDR
table=cdr
password=el que sea
user=asterisk
port=3306
sock=/tmp/mysql.sock
[columns]
;static "" => ;alias => alias start => calldate
alias callerid => clid
;alias src => src
;alias dst => dst
;alias dcontext => dcontext
;alias channel => channel
;alias dstchannel => dstchannel
;alias lastapp => lastapp
;alias lastdata => lastdata
;alias duration => duration
;alias billsec => billsec
;alias disposition => disposition
;alias amaflags => amaflags
;alias accountcode => accountcode
;alias userfield => userfield
;alias uniqueid => uniqueid
* Registered Backends
------------------mysql
csv
cdr-custom