Blogs on System Administration, Scripting, System Monitoring, Cloud Computing & Virtualizaton, VoIP Systems, SMS Systems and Web Applications Development.

Add Custom Fields in Asterisk’s MySQL CDRs


This blog is to introduce some unique fields in Asterisk MySQL CDRs for identifying a call and asterisk instance.


Following are the steps required:

Step # 1

Introduce following columns in database table `cdr`:

  • ip_address
  • call_id
  • unique_identifier

ALTER TABLE `cdr` ADD `ip_address` VARCHAR(20) NULL;
ALTER TABLE `cdr` ADD `call_id` VARCHAR(200) NULL;
ALTER TABLE `cdr` ADD `unique_identifier` VARCHAR(100) NULL;

Step # 2

Add following section in asterisk file i.e. cdr_mysql.conf. It will enable the CDR() function to recognize custom fields included in asterisk MySQL CDRs.

ip_address = ip_address
call_id = call_id
unique_identifier = unique_identifier

Step # 3

Following is the dialplan (in file i.e. extensions.conf) to handle custom Asterisk MySQL CDRs.

exten => _X.,1,set(CDR(ip_address)=${SHELL(/sbin/ifconfig | /usr/bin/awk '/inet addr/{print substr($2,6)}' | /bin/grep -v '' | /usr/bin/head -n1):0:-1})
exten => _X.,n,set(CDR(call_id)=${SIPCALLID})
exten => _X.,n,set(CDR(unique_identifier)=${UNIQUEID})

Step # 4

You need to restart asterisk or following commands to apply such changes.

$ /usr/sbin/asterisk -rx "module reload"
$ /usr/sbin/asterisk -rx "dialplan reload" 


It is the simplest way to introduce some of custom fields with custom names in existing mysql cdrs of Asterisk.

1 comment:

  1. fun88 | Play online slots & win real money at
    Play the latest free games and compete fun88 soikeotot in fun88 casino with no deposit & credit card needed. Fun88 offers MILLIONS 온라인카지노 of free 1XBET spins every month.


Please Enter your Comments Here.