Asterisk 11 – Change CDR In Hangup Exten [Was: CDR Values Changed In Hangup Handler Not Saved]

Home » Asterisk Users » Asterisk 11 – Change CDR In Hangup Exten [Was: CDR Values Changed In Hangup Handler Not Saved]
Asterisk Users 4 Comments

2013/3/29 Julian Lyndon-Smith

Unfortunately, this doesn’t help.

Let’s drop the hangup handler at the moment, and focus on the “saving to file” part. Then my issue is I can’t update CDR value is hangup exten.

Here is a dialplan that illustrate this:

[from-foobar]
exten => _X.,1,Verbose(0,Entering context ${CONTEXT} from channel
${CHANNEL(channeltype)} ${CHANNEL} with EXTEN and CID set to ${EXTEN} and
${CALLERID(num)})
same => n, Set(CDR(userfield)=foo)
same => n, Dial(SIP/foobar/${EXTEN})
same => n, Set(CDR(userfield)

4 thoughts on - Asterisk 11 – Change CDR In Hangup Exten [Was: CDR Values Changed In Hangup Handler Not Saved]

  • Ah, right. Have a look at this documentation:

    You may need to add some mapping

    Julian cdr_custom

    This CDR backend allows for custom formatting of CDR records in a log file. This module is most commonly used for customized CSV output. The configuration file used for this module is /etc/asterisk/cdr_custom.conf. A
    single section called [mappings] should exist in this file. The
    [mappings] section contains mappings between a filename and the custom template for a CDR. The template is specified using Asterisk dialplan functions.

    The following example shows a sample configuration for cdr_custom that enables a single CDR log file, Master.csv. This file will be created as
    /var/log/asterisk/cdr-custom/Master.csv. The template that has been defined uses both the CDR() and CSV_QUOTE() dialplan functions. The CDR() function retrieves values from the CDR being logged. The CSV_QUOTE() function ensures that the values are properly escaped for the CSV file format:

    [mappings]

    Master.csv => ${CSV_QUOTE(${CDR(clid)})},${CSV_QUOTE(${CDR(src)})},
    ${CSV_QUOTE(${CDR(dst)})},${CSV_QUOTE(${CDR(dcontext)})},
    ${CSV_QUOTE(${CDR(channel)})},${CSV_QUOTE(${CDR(dstchannel)})},
    ${CSV_QUOTE(${CDR(lastapp)})},${CSV_QUOTE(${CDR(lastdata)})},
    ${CSV_QUOTE(${CDR(start)})},${CSV_QUOTE(${CDR(answer)})},
    ${CSV_QUOTE(${CDR(end)})},${CSV_QUOTE(${CDR(duration)})},
    ${CSV_QUOTE(${CDR(billsec)})},${CSV_QUOTE(${CDR(disposition)})},
    ${CSV_QUOTE(${CDR(amaflags)})},${CSV_QUOTE(${CDR(accountcode)})},
    ${CSV_QUOTE(${CDR(uniqueid)})},${CSV_QUOTE(${CDR(userfield)})}

    In the actual configuration file, the value in the Master.csv mapping should be on a single line. cdr_manager

  • Thanks but I willingly choose a standard CDR field (I checked with both accountcode and userfield) which appears in
    /var/log/asterisk/cdr-csv/Master.csv (to keep cdr-cusdom/Master.csv away to simplify things)
    the fact found in Master.csv is foo, the value set before entering the hangup extension (see previous dialplan)).

    To me, this is either a feature (“you can’t set CDR values in hangup exten”) or a bug.

    How would you qualify this ?

    2013/3/29 Julian Lyndon-Smith

  • you can’t set values in the h extension _unless_ you use the endbeforehexten option in cdr.conf

    you may need to reload the cdr module or restart asterisk for the option to take effect.

    It works. I know it does, as I use hangup handlers all the time. Much better than the h extension 😉

    Julian