Asterisk CDR using MySQL

Asterisk version 1.4.18

Running “cdr status” from the command line returns:

CDR logging: enabled74*CLI>
CDR mode: simple
CDR output unanswered calls: no
CDR registered backend: csv
CDR registered backend: cdr_manager
CDR registered backend: cdr-custom

cdr.conf contents:

usegmtime=yes ; log date/time in GMT. Default is "no"
loguniqueid=yes ; log uniqueid. Default is "no
loguserfield=yes ; log user field. Default is "no

usegmtime=yes ; log date/time in GMT. Default is "no"
loguniqueid=yes ; log uniqueid. Default is "no
loguserfield=yes ; log user field. Default is "no

cdr_mysql.conf contents:


Login works fine to the mysql CLI
"SELECT fields FROM cdr;" returns the following:

mysql> show fields from cdr;
| Field | Type | Null | Key | Default | Extra |
| calldate | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| clid | varchar(80) | NO | | NULL | |
| src | varchar(80) | NO | | NULL | |
| dst | varchar(80) | NO | MUL | NULL | |
| dcontext | varchar(80) | NO | | NULL | |
| channel | varchar(80) | NO | | NULL | |
| dstchannel | varchar(80) | NO | | NULL | |
| lastapp | varchar(80) | NO | | NULL | |
| lastdata | varchar(80) | NO | | NULL | |
| duration | int(11) | NO | | 0 | |
| billsec | int(11) | NO | | 0 | |
| disposition | varchar(45) | NO | | NULL | |
| amaflags | int(11) | NO | | 0 | |
| accountcode | varchar(20) | NO | MUL | NULL | |
| userfield | varchar(255) | NO | | NULL | |
| uniqueid | varchar(32) | NO | | NULL | |
16 rows in set (0.03 sec)

I have Realtime MySQL for the voicemail system working perfect.
This cdr thing is driving me nuts!

Thanks for any help!

I dont get what your issue is at all. I mean what is wrong and what do you want to achieve?

As for me I am using mysql to store my cdr records but for some reason it wont store the ‘src’ field for any of the calls. I am using the box as a mobile phone gateway so to speak. There is an iax trunk coming into the box bringing in mobile calls and an iax line going out to the service provider who has the actual cell phone routers. Is there something i am not sending from the originating box to the one that i am working on (with no src records in the cdr) or is it something to do with the asterisk install on the “mobile phone gateway box”?

sorted it out by adding the following callerid =device <6000> in users.conf and in extensions.conf i basically did the following

exten = _0XXXXXXXX!,1,Macro(trunkdial,${fair_cape_voice}/${EXTEN:0},${CALLERID(all)})

is there anything wrong with what i did and why was it setting the trunk itself as the source of the call… that doesnt make sense imo.

Okay, sorry about that. I got so caught up in writing in complete details that I forgot to say what the issue is.

The issue is that I cannot get cdr to work with MySQL. It just wants to use the csv.

have you got the mysql addons package installed?

check output from module show like cdr command

or module show like mysql :stuck_out_tongue:

He has the mysql package if he is using realtime voicemail.

Just remove the csv entry from cdr.conf(in mine all is commented out) restart asterisk and see if that helps.


Do I have to restart Asterisk or can I just reload it?

you can reload the cdr modules… i would prefer a restart of asterisk but if that is not possible a reload should work. also make sure you have the correct passwords in ur cdr_mysql conf file and that the username has the correct permissions in mysql, you prob know this already but just incase i put that down

I did a little write-up how I got is to work on my machine:
In the end I had to reboot the whole machine, don’t know why, but I found another post on this forum saying the same.

Checks you can do:
‘show module like cdr’ should result in a line with
’cdr status’ should produce a line ‘CDR registered backend: mysql’

If I’m not mistaken, the [mysql] section in cdr.conf is not needed. I used to have it also, tried to change the GMT bit, but it had no effect. I looked into asterisk-addons-1.4.6/cdr/cdr_addon_mysql.c, it doesn’t seem to read the cdr.conf file. In order to enable mysql logging, a configured cdr_mysql.conf should be all that’s needed. If you want to enable the Unique IDs, you need #define MYSQL_LOGUNIQUEID in cdr_addon_mysql.c

Before restart whole asterisk cdr didn’t write do MySQL. :confused: