Call Detail Records

Asterisk logs information about every call in a comma-delimited file. In telephony-speak this is called the “Call Detail Records” or CDR. For most of your projects the CDR is overkill, and you’ll probably have better luck saving your own data using the Asterisk Database.

The CDR file is located at /var/log/asterisk/cdr-csv/Master.csv and contains the following fields:

  • accountcode: What account number to use: Asterisk billing account, (string, 20 characters)
  • src: Caller*ID number (string, 80 characters)
  • dst: Destination extension (string, 80 characters)
  • dcontext: Destination context (string, 80 characters)
  • clid: Caller*ID with text (80 characters)
  • channel: Channel used (80 characters)
  • dstchannel: Destination channel if appropriate (80 characters)
  • lastapp: Last application if appropriate (80 characters)
  • lastdata: Last application data (arguments) (80 characters)
  • start: Start of call (date/time)
  • answer: Answer of call (date/time)
  • end: End of call (date/time)
  • duration: Total time in system, in seconds (integer)
  • billsec: Total time call is up, in seconds (integer)
  • disposition: What happened to the call: ANSWERED, NO ANSWER, BUSY, FAILED
  • amaflags: What flags to use: see amaflags::DOCUMENTATION, BILL, IGNORE etc, specified on a per channel basis like accountcode.

How you sift through this file is up to you, and will largely depend on your needs. Here’s some simple bash commands that may help you out:

  • tail <file name>
    • shows the last 10 lines in a text file.
  • cat <file name>
    • prints out the contents of a text file.
  • cat <file name> | grep <pattern to match>
    • For example: cat Master.csv | grep 16466429000
    • the “|” will “pipe” the output of one program into the input of another program. In this case, we “pipe” the contents of Master.csv into a filtering program called “grep” that will output any line that has “16466429000” in it.
  • cat <file name> | grep <pattern to match> >> <input file>
    • For example: cat Master.csv | grep 16466429000 >> new_records.csv
    • The “>>” will send the text output of a program into a text file.