Mod cdr

From FreeSWITCH Wiki
Jump to: navigation, search

This module is currently non-functional. Please stay tuned for a revival. Some formats are already handled by newer modules - see CDR for a list. - Aug. 2008

Call Detail Record, Computer record containing data unique to a specific call.


Output options

The following output options are available:

  • CSV (Comma-separated values)
  • PDD (Perl Data-Dumper hash format)
  • XML
  • MySQL (Requires MySQL 4.1+)
  • ODBC (Coming soon pending somebody being able to actually test it)
  • Sqlite (Has been tested on Linux, needs testing on Windows prior to inclusion in trunk)
  • RADIUS (Currently testing on Linux, needs additional testing on Windows)


mod_cdr was moved from trunk to unsupported. Assuming you're currently on freeswitch's toplevel directory, run:

Type This
svn checkout src/mod/event_handlers/mod_cdr


Add mod_cdr.conf.xml to your freeswitch.xml configuration file include section:

<section name="configuration" description="Various Configuration">
  <!--#include "switch.conf.xml"-->
  <!--#include "ivr.conf.xml"-->
  <!--#include "mod_cdr.conf.xml"-->

mod_cdr will allow you to store times either as localtime or as UTC (GMT) time. Each module has a timezone configuraiton parameter that can be set to utc. If not specific or misconfigured, it will default to localtime.

Some configuration examples here maybe? =)

XML output

Here is an example on what the output will look like.

<?xml version="1.0"?>
<document type="freeswitch-cdr/xml">
	<callstartdate data="1173786451305432" />
	<formattedcallstartdate data="2007-03-13 12:47:31" />
	<callanswerdate data="1173786451665704" />
	<formattedcallanswerdate data="2007-03-13 12:47:31" />
	<calltransferdate data="0" />
	<formattedcalltransferdate data="1970-01-01 01:00:00" />
	<callenddate data="1173786469757624" />
	<formattedcallenddate data="2007-03-13 12:47:49" />
	<hangupcause data="NORMAL_CLEARING" />
	<hangupcausecode data="16" />
	<clid data="FreeSwitch" />
	<originated data="1" />
	<dialplan data="XML" />
	<myuuid data="65fd77f8-ee3d-ba41-9a68-f6dfacc1fa74" />
	<destuuid data="" />
	<src data="" />
	<dst data="" />
	<srcchannel data="PortAudio/888" />
	<dstchannel data="" />
	<ani data="" />
	<aniii data="" />
	<network_addr data="" />
	<lastapp data="" />
	<lastdata data="" />
	<billusec data="18091920" />
	<disposition data="1" />
	<amaflags data="0" />

Database output

You need to create a table called XXX that has the same columns as in the xml output above.

API Commands

mod_cdr has the following commands executable from the console:

 * modcdr_reload - If built with the apr_queue enhancements, will wait until the queue is empty, then reload all the configurations for the different logger classes, else will report an informational message.
 * modcdr_queue_pause - If built with apr_queue enhancements, will manually pause the retrieval of objects from the queue, else will report an informational message.
 * modcdr_queue_resume - If built with the apr_queue enhancements, will manually resume the retrieval of objects from the queue, else will report an informational message.
 * modcdr_show_available - Will show a list of the available (compiled in) logging classes.
 * modcdr_show_active - Will show a list of actively configured loggers (might be only a subset of those reported by modcdr_show_available).

Currently the best place to look for up-to-date configuration information is the README in src/mod/event_handlers/mod_cdr. As it matures, we will posting information and sample configurations here as well.


At the moment we do not have any autoconf/automake magic for mod_cdr. You do not need to install MySQL in order to build - all you need to do is edit the Makefile in src/mod/event_handlers/mod_cdr and remove mysqlcdr.o from the OBJS line, then comment out the CFLAGS and LDFLAGS that search for mysql_config. It'd be really great if somebody with a working knowledge of autoconf/automake could help make this easier to configure for build.

There are some enhancements for safely reloading the configuration of mod_cdr, however, those are pending changes to APR-Util's apr_queue.c/h files. The core dev team has been provided with patches, but they have not yet been able to include them or test them.

Installing and configuring on CentOS 4.4

Work in Progress

Trying to get mod_cdr to work. This is a work in progress that will be revised upon sucessful instalation and configuration of mod_cdr. If you have anything to had or see me going the wrong way here, feel free to comment.

You must have the mysql header libraries

yum install mysql-devel

Add mod_cdr on Modules.conf /this is the Modules.conf sitting at the top level of your source directory if you have downloaded the source in /usr/src then the exact location of the Modules.conf is /usr/src/freeswitch/modules.conf/ . After that do

make installall

Database Configuration


<configuration name="mod_cdr.conf" description="CDR Configuration">
    <param name="path" value="/tmp/csvcdr"/>


<configuration name="mod_cdr.conf" description="CDR Configuration">
     <param name="path" value="/path/to/where/the/file/goes"/>
     <param name="chanvars_fixed" value="foo=1"/>
     <param name="chanvars_supp" value="bar,sip_from_host"/>
     <param name="chanvars_supp_repeat_fixed" value="y"/>
     <param name="timezone" value="utc"/>


<configuration name="mod_cdr.conf" description="CDR Configuration">
  <param name="hostname" value=""/>
  <param name="username" value="test"/>
  <param name="password" value="test"/>
  <param name="dbname" value="testing"/>
  <!-- This following line logs username as a varchar, and The_Kow as a tiny -->
  <!-- <param name="chanvars_fixed" value="username=s,The_Kow=t"/> -->
  <!-- If you do not want to log any and all chanvars to the chanvar table, comment the next 2 lines out -->
  <param name="chanvars_supp" value="*"/>
  <param name="chanvars_supp_repeat_fixed" value="0"/>

MySQL Schema

create database freeswitchdb;
use freeswitchdb;
create table freeswitchcdr (
	callid bigint unsigned default 0 primary key, /* This will need to be handled specially for auto increment, as that might not be standard */
	callstartdate datetime NOT NULL,
	callanswerdate datetime NOT NULL,
	calltransferdate datetime NOT NULL,
	callenddate datetime NOT NULL,
	originated tinyint default 0,
	clid varchar(80) default "Freeswitch - Unknown",
	src varchar(80) NOT NULL,
	dst varchar(80) NOT NULL,
	ani varchar(80) default "",
	aniii varchar(80) default "",
	dialplan varchar(80) default "",
	myuuid char(36) NOT NULL,
	destuuid char(36) NOT NULL,
	srcchannel varchar(80) NOT NULL,
	dstchannel varchar(80) NOT NULL, /* Need to decide - this might be redundant as you can link the records via uuid */
	network_addr varchar(40) default "",
	lastapp varchar(80) default "",
	lastdata varchar(255) default "",
	billusec bigint default 0,
	disposition tinyint default 0, /* 0 = Busy or Unanswered, 1 = Answered */
	hangupcause int default 0,
	amaflags tinyint default 0

create index myuuid_index on freeswitchcdr (myuuid);
create index destuuid_index on freeswitchcdr (destuuid);

create table chanvars (
	callid bigint unsigned default 0,
	varname varchar(80) NOT NULL,
	varvalue varchar(255) default ""

create index callid_index on chanvars(callid,varname);
ALTER TABLE freeswitchcdr modify callid bigint unsigned auto_increment;
ALTER TABLE freeswitchcdr Engine=InnoDB;
ALTER TABLE chanvars Engine=InnoDB;

PDD (Perl Data-Dumper hash format)

<configuration name="mod_cdr.conf" description="CDR Configuration">
    <param name="path" value="/tmp/pddcdr"/>
    <param name="chanvars" value="foo,accountcode"/>
    <param name="chanvars_fixed" value="*"/>

See Also

  • src/mod/event_handlers/mod_cdr/README for more info on all available settings

Example XML cdr


Q: Are there example database schemas?

See schema.sql in the mod_cdr source dir

Q: Does chanvar_supp equal supplemental variables to track?

Yes. The difference between chanvars_fixed and chanvars_supp is that in order to use chanvars_fixed, the main freeswitchcdr table schema gets modified. These are ones that you tend to expect on every call. The chanvars_supp can be any random assortment of other, lessor important, and/or * (all chanvars), and those get tossed into a separate chanvar table. This table is essentially a key/value table with a foreign key back to the original cdr.