CDR
From AstriPedia
Asterisk generates Call Detail Records in a database or in a comma separated text file.
- cdr_csv supports comma separated text file storage, this is the default driver
- cdr_manager supports CDR information via the AMI, The Asterisk Manager interface
- cdr_odbc supports UnixODBC databases, see http://www.unixodbc.org for an updated list of supported databases, from MySQL to MsSQL and text files.
- cdr_tds supports FreeTDS databases (Among them MS SQL)
- NOTE. Please read README.tds for information on possible problems with the FreeTDS driver
- cdr_sqlite supports SQlite
- cdr_pgsql supports PostgreSQL
In the asterisk-addons cvs archive, there's a cdr_mysql driver for MySQL.
Contents |
Applications
* SetAccount Set account code for billing
* SetAMAFlags Sets AMA flags
* NoCDR Make sure no CDR is saved for a specific call
* ResetCDR Reset CDR
* ForkCDR Save current CDR and start a new CDR for this call
* Authenticate Authenticates and sets the account code
* SetCDRUserField Set CDR user field
* AppendCDRUserField Append data to CDR User field
For more information, use the "show application" command. You can set default account codes and AMA flags for devices in channel configuration files, like sip.conf, iax.conf etc.
Fields of the CDR in Asterisk
1. accountcode: What account number to use, (string, 20 characters)
2. src: Caller*ID number (string, 80 characters)
3. dst: Destination extension (string, 80 characters)
4. dcontext: Destination context (string, 80 characters)
5. clid: Caller*ID with text (80 characters)
6. channel: Channel used (80 characters)
7. dstchannel: Destination channel if appropriate (80 characters)
8. lastapp: Last application if appropriate (80 characters)
9. lastdata: Last application data (arguments) (80 characters)
10. start: Start of call (date/time)
11. answer: Answer of call (date/time)
12. end: End of call (date/time)
13. duration: Total time in system, in seconds (integer), from dial to hangup
14. billsec: Total time call is up, in seconds (integer), from answer to hangup
15. disposition: What happened to the call: ANSWERED, NO ANSWER, BUSY
16. amaflags: What flags to use: DOCUMENTATION, BILL, IGNORE etc,
specified on a per channel basis like accountcode.
17. user field: A user-defined field, maximum 255 characters
In some cases, uniqueid is appended:
* uniqueid: Unique Channel Identifier (32 characters)
This needs to be enabled in the source code at compile time
ONE IMPORTANT NOTE: If you are trying to collect records on IAX to IAX calls you need to be aware that by default, IAX will attempt to transfer calls in this situation (if DTMF is not required). When the transfer is completed the call is dumped from the middle machine and thus the call detail records will report a short call time. If you want detailed records you must turn off IAX transfer, but unless your servers are very close together, you will definitely get a latency hit from doing so.
CDR Variables
If the channel has a cdr, that cdr record has its own set of variables which can be accessed just like channel variables. The following builtin variables are available.
${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.
In addition, you can set your own extra variables by using Set(CDR(name)=value). These variables can be output into a text-format CDR by using the cdr_custom CDR driver; see the cdr_custom.conf.sample file in the configs directory for an example of how to do this.
CSV and MySQL
Call data records can be stored in many different databases or even CSV text.
MSSQL: Asterisk can currently store CDRs into an MSSQL database in two different ways: cdr_odbc.c or cdr_tds.c
Call Data Records can be stored using unixODBC (which requires the FreeTDS package) [cdr_odbc.c] or directly by using just the FreeTDS package [cdr_tds.c] The following provide some examples known to get asterisk working with mssql. NOTE: Only choose one db connector.
ODBC [cdr_odbc.c]: Compile, configure, and install the latest unixODBC package: tar -zxvf unixODBC-2.2.9.tar.gz && cd unixODBC-2.2.9 && ./configure --sysconfdir=/etc --prefix=/usr --disable-gui && make && make install
Compile, configure, and install the latest FreeTDS package:
tar -zxvf freetds-0.62.4.tar.gz && cd freetds-0.62.4 && ./configure --prefix=/usr --with-tdsver=7.0 --with-unixodbc=/usr/lib && make && make install
Compile, or recompile, asterisk so that it will now add support
for cdr_odbc.c
make clean && make update && make && make install
Setup odbc configuration files. These are working examples from my system. You will need to modify for your setup. You are not required to store usernames or passwords here.
/etc/odbcinst.ini
[FreeTDS] Description = FreeTDS ODBC driver for MSSQL Driver = /usr/lib/libtdsodbc.so Setup = /usr/lib/libtdsS.so FileUsage = 1
/etc/odbc.ini
[MSSQL-asterisk] description = Asterisk ODBC for MSSQL driver = FreeTDS server = 192.168.1.25 port = 1433 database = voipdb tds_version = 7.0 language = us_english
Only install one database connector. Do not confuse asterisk by using both ODBC (cdr_odbc.c) and FreeTDS (cdr_tds.c). This command will erase the contents of cdr_tds.conf
[ -f /etc/asterisk/cdr_tds.conf ] > /etc/asterisk/cdr_tds.conf
NOTE: unixODBC requires the freeTDS package, but asterisk does not call freeTDS directly.
Setup cdr_odbc configuration files. These are working samples from my system. You will need to modify for your setup. Define your usernames and passwords here, secure file as well.
/etc/asterisk/cdr_odbc.conf
[global] dsn=MSSQL-asterisk username=voipdbuser password=voipdbpass loguniqueid=yes
And finally, create the 'cdr' table in your mssql database.
CREATE TABLE cdr ( [calldate] [datetime] NOT NULL , [clid] [varchar] (80) NOT NULL , [src] [varchar] (80) NOT NULL , [dst] [varchar] (80) NOT NULL , [dcontext] [varchar] (80) NOT NULL , [channel] [varchar] (80) NOT NULL , [dstchannel] [varchar] (80) NOT NULL , [lastapp] [varchar] (80) NOT NULL , [lastdata] [varchar] (80) NOT NULL , [duration] [int] NOT NULL , [billsec] [int] NOT NULL , [disposition] [varchar] (45) NOT NULL , [amaflags] [int] NOT NULL , [accountcode] [varchar] (20) NOT NULL , [uniqueid] [varchar] (32) NOT NULL , [userfield] [varchar] (255) NOT NULL )
Start asterisk in verbose mode, you should see that asterisk logs a connection to the database and will now record every call to the database when it's complete.
TDS [cdr_tds.c]: Compile, configure, and install the latest FreeTDS package: tar -zxvf freetds-0.62.4.tar.gz && cd freetds-0.62.4 && ./configure --prefix=/usr --with-tdsver=7.0 make && make install
Compile, or recompile, asterisk so that it will now add support for cdr_tds.c (Currently only asterisk SVN supports cdr_tds.c)
make clean && make update && make && make install
Only install one database connector. Do not confuse asterisk by using both ODBC (cdr_odbc.c) and FreeTDS (cdr_tds.c). This command will erase the contents of cdr_odbc.conf
[ -f /etc/asterisk/cdr_odbc.conf ] > /etc/asterisk/cdr_odbc.conf
Setup cdr_tds configuration files. These are working samples from my system. You will need to modify for your setup. Define your usernames and passwords here, secure file as well.
/etc/asterisk/cdr_tds.conf [global] hostname=192.168.1.25 port=1433 dbname=voipdb user=voipdbuser password=voipdpass charset=BIG5
And finally, create the 'cdr' table in your mssql database.
CREATE TABLE cdr ( [accountcode] [varchar] (20) NULL , [src] [varchar] (80) NULL , [dst] [varchar] (80) NULL , [dcontext] [varchar] (80) NULL , [clid] [varchar] (80) NULL , [channel] [varchar] (80) NULL , [dstchannel] [varchar] (80) NULL , [lastapp] [varchar] (80) NULL , [lastdata] [varchar] (80) NULL , [start] [datetime] NULL , [answer] [datetime] NULL , [end] [datetime] NULL , [duration] [int] NULL , [billsec] [int] NULL , [disposition] [varchar] (20) NULL , [amaflags] [varchar] (16) NULL , [uniqueid] [varchar] (32) NULL )
Start asterisk in verbose mode, you should see that asterisk logs a connection to the database and will now record every call to the database when it's complete.
MYSQL:
PGSQL:
SQLLITE:
08/02/2004 : Duane Cox <dcox@illicom.net> - added mssql information
