Contact

Blogs

Take a look at the things that interest us.

Adding Custom Fields to Asterisk CDR

Wesley Wesley 2 years

In my last post, I have talked about how to set up the Asterisk CDR, in this post I would like to go in-depth with how to use the Asterisk CDR in your dail plan.

When you have done your first call with the Asterisk CDR, the call detail records can be quite overwhelming. For example, take a look at the Mysql record from our last test call.

# Mysql dump
(1,'100','100-busy','phones','100,'<100>','PJSIP/100-000000a','PJSIP/200-000000b','Voicemail','100,a','2020-12-18 16:24:02','2020-12-18 17:30:02','2020-12-18 17:30:02','2','1','ANSWERED','DOCUMENTATION','14676676765.2','')

It seems a bit too complicated.

Look again at the output above and you'll notice some information such as both the extension numbers and a few timestamps. However, things get a bit more complicated when you want to describe the rest of the dataset.

Thankfully, Asterisk themselves have a very good wiki article explaining what’s what. When you compare the list below (taken from the Asterisk Wiki) with the Mysql output above, you can start to gain a more comprehensive understanding.

# Asterisk Wiki Parameters
${CDR(clid)}           = Caller ID
${CDR(src)}            = Source
${CDR(dst)}            = Destination
${CDR(dcontext)}       = Destination context
${CDR(channel)}        = Channel name
${CDR(dstchannel)}     = Destination channel
${CDR(lastapp)}        = Last app executed
${CDR(lastdata)}       = Last app’s arguments
${CDR(start)}          = Time the call started.
${CDR(answer)}         = Time the call was answered.
${CDR(end)}            = Time the call ended.
${CDR(duration)}       = Duration of the call.
${CDR(billsec)}        = Duration of the call once it was answered.
${CDR(disposition)}    = ANSWERED, NO ANSWER, BUSY
${CDR(amaflags)}       = DOCUMENTATION, BILL, IGNORE etc
${CDR(accountcode)}    = The channel’s account code.
${CDR(uniqueid)}       = The channel’s unique id.
${CDR(userfield)}      = The channels uses specified field.

If you would like to add a custom field to your CDR records, you can do so by modifying your dial plan by adding the following code to your desired extension.

same => n, Set(CDR(userfield)=custom field)

For example

# extensions.conf
[phones]
exten => _1XXX,1,Ringing
same  => _1XXX,n,Set(CDR(userfield)=custom field)
exten => _1XXX,n,Dial(PJSIP/${EXTEN},60,tT)
exten => _1XXX,n,Answer()
exten => _1XXX,n,Hangup

Once your extensions.conf changes have been saved and you have restarted/reloaded your Asterisk dial plan the new syntax will be active and appear in the Call Detail Records.

Adding Custom Fields to Asterisk CDR 2021-08-23 14:11:21

There are no comments.

4831

Have questions about our services?

Contact our Sales team to get answers.

Contact Us
gomibako@aska-ltd.jp