Mod xml cdr
From FreeSWITCH Wiki
Description
Outputs CDR records in XML format to local file or to a webserver via HTTP POST.
Here is an Example XML cdr
Features
Output capabilities
- Always log to the disk
- Always log to HTTP/HTTPS
- Always log to both
Reliability capabilities
On failure it will log the HTTP POST data to disk where you specify, and it has configurable timeouts and retries for the HTTP post.
Getting it working
modules.conf
To compile the module, uncomment mod_xml_cdr in modules.conf
Install dependencies
If you try to build and get an error
you will need to install curl and the development headers.
Debian
Building
modules.conf.xml
Enable mod_xml_cdr in modules.conf.xml for the next time freeswitch is restarted. Type load mod_xml_cdr at the CLI to load the module.
Sample Configuration
Edit conf/freeCreate a file in the conf directory called xml_cdr.conf.xml with the following contents:
<configuration name="xml_cdr.conf" description="XML CDR CURL logger"> <settings> <param name="cred" value="user:pass"/> <param name="url" value="http://myhost/cdr.php"/> <param name="retries" value="2"/> <param name="delay" value="120"/> <param name="log-dir" value="/var/log/cdr"/> <param name="err-log-dir" value="/var/log/cdr/errors"/> <param name="encode" value="True"/> </settings>
- the directories you specify for log-dir or err-log-dir must exist.
- you will have to create your own HTTP CGI handler in place of cdr.php. See scripts/contrib/trixter/xml-cdr to view the code of the example cdr.php.
- double check freeswitch.xml and make sure xml_cdr.conf.xml is included. If not, it means you need to get a newer version of freeswitch for this feature to work.
Verifying
Place a call, hangup, and you should have a new XML file in /usr/local/freeswitch/log. Also check your webserver logs.
Configuration Options
| name | description | example |
| cred | credentials to use to post to webserver (if webserver requires it) | user:pass |
| url | webserver url | http://myhost/cdr.php |
| retries | number of retries before giving up http post and writing to disk | 2 |
| delay | delay in seconds before retrying | 120 |
| log-dir | directory to log to -- you must create this directory. If left blank, will use the default directory. If omitted, disables logging to a file and will only POST to webserver. If a name is given instead of a path, a subdirectory under the default will be used. This directory must already exists. | /tmp/log |
| err-log-dir | directory to log errors to -- you must create this directory. If left blank, will use the default directory. If omitted, disables logging to a file and will only POST to webserver. If a name is given instead of a path, a subdirectory under the default will be used. This directory must already exists. | /tmp/errlog |
| encode | whether to encode the information in the POST that is sent to the webserver. By default, (if this param is not provided or is invalid) the content-type of the post is application/x-www-form-plaintext and no URL-encoding is done on the POST'ed data. If set to 'True', it will set the content type to application/x-www-form-urlencoded and URL-encode the information. This is what most webservers expect. Finally if set to base64, the content type will be application/x-www-form-base64-encoded. | True |
Examples
See scripts/contrib/trixter/xml-cdr for examples to take a webpost (which mod_xml_cdr does now) and turn it into an associative array so your script can process it.
Reference Information
The Example XML cdr was generated by calling the FreeSWITCH conference via the PSTN. A SIP phone registered with FS dialed 9+2137991400 and went through this dialplan extension:
<!-- Dial 9, go out Qwest PRI on span 1 -->
<extension name="Dial 9">
<condition field="destination_number" expression="^9(\d{10})$">
<action application="bridge" data="openzap/1/A/$1"/>
</condition>
</extension>
Channel Variables
The XML CDR contains a number of channel variables as well as call flow information.
Call times are in date/time stamp format or in either epoch seconds or epoch microseconds (usec).
Date/time stamp variables are URI encoded so be sure to "URI decode" them prior to inserting them into a database.
Example: "2008-07-31%2011%3A35%3A38" is URI encoded. Decoded it is "2008-07-31 11:35:38".
The epoch began at 1970-01-01 00:00:00, therefore the epoch values are the number of seconds (or microseconds) since the epoch began.
Using the epoch microseconds values allows for extremely accurate measurements.
Call Date/Time Variables
answer_stamp
Date/time that the far end of the call was actually answered.
In the example CDR this value is "2008-07-31%2011%3A35%3A41" (2008-07-31 11:35:41).
end_stamp
Date/time that the call was terminated.
In the example CDR this value is "2008-07-31%2011%3A36%3A17" (2008-07-31 11:36:17).
profile_start_stamp
???? (still researching this one).
In the example CDR this value is "2008-07-31%2011%3A35%3A38" (2008-07-31 11:35:38).
progress_stamp
Date/time that progress information from the far end is first received.
In the example CDR this value is "2008-07-31%2011%3A35%3A38" (2008-07-31 11:35:38).
(Researching accuracy of this statement)
progress_media_stamp
Date/time that "early media" or progress media was first received. "Early media" includes ring-back tone (RBT).
In the example CDR this value is "2008-07-31%2011%3A35%3A38" (2008-07-31 11:35:38).
start_stamp
Date/time that the call was initiated.
In the example CDR this value is "2008-07-31%2011%3A35%3A38" (2008-07-31 11:35:38).
Call Epoch Variables
answer_epoch
Call answer time in epoch seconds.
In the example CDR this value is 1217529338.
answer_uepoch
Call answer time in epoch microseconds.
In the example CDR this value is 1217529338452698.
end_epoch
Call end time in epoch seconds.
In the example CDR this value is 1217529377.
end_uepoch
Call end time in epoch microseconds.
In the example CDR this value is 1217529377795951.
profile_start_epoch
Profile start time in epoch seconds.
In the example CDR this value is 1217529338.
profile_start_uepoch
Profile start time in epoch microseconds.
In the example CDR this value is 1217529338212616.
start_epoch
Call start time in epoch seconds.
In the example CDR this value is 1217529338.
start_uepoch
Call start time in epoch microseconds.
In the example CDR this value is 1217529338212616.
Call Duration Variables
billsec
Billable call duration in seconds. Billable time does not include call time spent in "early media" prior to the far end answering the call.
In the example CDR this value is 36.
billmsec
Billable call duration in milliseconds. Billable time does not include call time spent in "early media" prior to the far end answering the call.
In the example CDR this value is 36267.
billusec
Billable call duration in microseconds. Billable time does not include call time spent in "early media" prior to the far end answering the call.
In the example CDR this value is 36267529.
duration
Total call duration in seconds.
In the example CDR this value is 39.
flow_billsec
flow_billmsec
flow_billusec
mduration
Total call duration in milliseconds.
In the example CDR this value is 39583.
progresssec
Amount of time in seconds that the call is in "progress" mode prior to the far end answering.
In the example CDR this value is 0. (Less than 1 second.)
progressmsec
Amount of time in milliseconds that the call is in "progress" mode prior to the far end answering.
In the example CDR this value is 238.
progressusec
Amount of time in microseconds that the call is in "progress" mode prior to the far end answering.
In the example CDR this value is 237955.
progress_mediasec
Amount of time in seconds that the call is in "progress_media" (aka receiving "early media") mode prior to the far end answering.
In the example CDR this value is 0. (Less than 1 second.)
progress_mediamsec
Amount of time in milliseconds that the call is in "progress_media" (aka receiving "early media") mode prior to the far end answering.
In the example CDR this value is 238.
progress_mediausec
Amount of time in milliseconds that the call is in "progress_media" (aka receiving "early media") mode prior to the far end answering.
In the example CDR this value is 237955.
uduration
Total call duration in microseconds.
In the example CDR this value is 39583335.
Troubleshooting
Error loading module
2007-06-27 17:59:12 [ERR] switch_loadable_module.c:714 switch_loadable_module_load_file() Error Loading module /usr/local/freeswitch/mod/mod_xml_cdr.so **/usr/local/freeswitch/mod/mod_xml_cdr.so: undefined symbol: curl_easy_getinfo**
Fix: This indicates you dont have curl linked in right. Check the mod_xml_cdr/Makefile and make sure it has WANTS_CURL=yes
Does not write to non-default logDir
If you set logDir to /tmp/foo, you must mkdir /tmp/foo/xml_cdr or it will revert to the default directory.
I'm getting a Memory Error when module loads
2007-06-27 19:41:06 [DEBUG] mod_xml_cdr.c:192 do_config() processing logDir config 2007-06-27 19:41:06 [DEBUG] mod_xml_cdr.c:197 do_config() val is NON zero length, setting globals.logDir: /tmp/log 2007-06-27 19:41:06 [CRIT] mod_xml_cdr.c:219 do_config() Memory Error!
Fix: try setting a custom errLogDir in config and this error should go away. It is a bug, and it's not actually a memory error that indicates any memory related problems.
FAQ
Q: Does mod_cdr need to be compiled/enabled?
No, this module is independent -- you may have both but they wont communicate with each other.
Categories: XML | Integration | Modules
