CDR File Module

From Yate Documentation
(Difference between revisions)
Jump to: navigation, search
(Created page with " Cdrfile is a module that receive a "chan.cdr" message (maybe from cdrbuild) and is writing the cdr into a file. Here's list of available variables that could be used to cons...")
 
(List of available variables that could be used to construct a CDR record)
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  
Cdrfile is a module that receive a "chan.cdr" message (maybe from cdrbuild) and is writing the cdr into a file.
+
This module is used to write the CDRs(call detail record) into a file. The configuration file is cdrfile.conf.
  
Here's list of available variables that could be used to construct a CDR record. Notice, in order for a parameter to be avaiable in the cdr, it has to be enabled in [[CDR Build Module#Configuration|cdrbuild.conf]].
+
Cdrfile is a module that receives a [[call.cdr]] message (maybe from [[CDR Build Module|cdrbuild]]).
  
The cdrwrite parameter is special, a boolean value of false will prevent the CDR from being written. This is to avoid generating CDR records for utility channels while still being able to track them.
+
===The configuration file===
 +
 
 +
The file used in configuration is cdrfile.conf.
 +
 
 +
==== Section [general] ====
 +
 
 +
* '''file''': string: Name of the file to write the CDR to
 +
: You should check that this file is log rotated - see '/etc/logrotate.d/yate'
 +
: Example: file=/var/log/yate-cdr.tsv
 +
 
 +
* '''tabs''': bool: Use tab-separated instead of comma-separated if format is missing.
 +
: tabs=true
 +
 
 +
* '''combined''': bool: Use combined CDR for all legs of a call.
 +
: combined=false
 +
 
 +
* '''format''': string: Custom format to use, overrides default.
 +
: Each ${parameter} is replaced with the value of that parameter in the [[call.cdr]] message.
 +
 
 +
:Below are listed the format defaults for each mode combination:
 +
 
 +
::* tab-separated (.tsv), combined=false
 +
:::'''format'''=${time}    ${billid}    ${chan}    ${address}    ${caller}    ${called}    ${billtime}    ${ringtime}    ${duration}    ${direction}    ${status}    {reason}
 +
 
 +
::* tab-separated (.tsv), combined=true
 +
::: '''format'''=${time}    ${billid}    ${chan}    ${address}    ${caller}    ${called}    ${billtime}    ${ringtime}    ${duration}    ${status}    ${reason}    ${out_leg.chan}<br/>    ${out_leg.address}      ${out_leg.billtime}    ${out_leg.ringtime}    ${out_leg.duration}    ${out_leg.reason}
 +
 
 +
::* comma-separated (.csv), combined=false
 +
::: '''format'''=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${direction}","${status}","${reason}"
 +
 
 +
::* comma-separated (.csv), combined=true<br/>
 +
:::'''format'''=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${status}","${reason}","${out_leg.chan}",<br/>"${out_leg.address}",${out_leg.billtime},${out_leg.ringtime},${out_leg.duration},"${out_leg.reason}"
 +
 
 +
===List of available variables that could be used to construct a CDR record===
 +
 
 +
'''Note''': in order for a parameter to be available in the CDR, it has to be enabled in [[CDR Build Module#Adding_custom_parameters|cdrbuild.conf]].
 +
 
 +
The "cdrwrite" parameter is special, a boolean value of false will prevent the CDR from being written. This is to avoid generating CDR records for utility channels while still being able to track them.
  
 
* ${time} - UNIX time
 
* ${time} - UNIX time
Line 13: Line 50:
 
* ${called} - destination number
 
* ${called} - destination number
 
* ${callername} - caller id  
 
* ${callername} - caller id  
* ${billtime} - billable call duration, starts from the point when the  
+
* ${billtime} - billable call duration, starts from the point when the remote party actually answers the call
                remote party actually answers the call
+
* ${ringtime} - amount of time the call was in ring state, from first ring to answer or hangup
* ${ringtime} - total time of the call
+
* ${duration} - total time of the call
 
* ${direction} - has a value of outgoing or incoming
 
* ${direction} - has a value of outgoing or incoming
 
* ${status} - disposition of the call
 
* ${status} - disposition of the call
* ${reason} - reason for call disconnection  
+
* ${reason} - reason for call disconnection
+
* ${out_leg.chan} - outgoing call leg channel used
 +
* ${out_leg.address} - the destination address for outgoing call leg
 +
* ${out_leg.billtime} - the billable outgoing call leg duration
 +
* ${out_leg.ringtime} - ring time of the outgoing call leg
 +
* ${out_leg.duration} - total time of the outgoing call leg
 +
* ${out_leg.reason} - reason for outgoing call leg disconnection
  
===Configuration===
+
===Usage example===
  
cdrfile.conf:
+
==== Set CDR billing====
 +
 
 +
In many real-life situations CDR billing is done in seconds.
 +
 
 +
It's useful to set:
 +
 
 +
cdrbuild.conf
 +
 
  [general]
 
  [general]
  ; file: string: Name of the file to write the CDR to
+
  resolution=sec
; You should check that this file is log rotated - see /etc/logrotate.d/yate
+
 
; Example: file=/var/log/yate-cdr.tsv
+
 
;file=
+
====Write CDR to file====
 +
 
 +
1) Write CDRs with combined set on false and the format below:
 +
 
 +
cdrfile.conf
 
   
 
   
  ; tabs: bool: Use tab-separated instead of comma-separated if format is missing
+
  [general]
  ;tabs=true
+
  file=/var/log/yate-cdr.csv
+
  format=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${direction}","${status}","${reason}"
; format: string: Custom format to use, overrides default. Each ${parameter}
+
;  is replaced with the value of that parameter in the call.cdr message
+
+
; tab-separated (.tsv)
+
;format=${time} ${billid} ${chan} ${address} ${caller} ${called} ${billtime} ${ringtime} ${duration} ${direction} ${status} ${reason}
+
 
+
; comma-separated (.csv)
+
  ;format=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${direction}","${status}","${reason}"
+
  
In many real-life situations CDR billing is done in seconds and it's useful to set resolution=sec in cdrbuild.conf.
+
 
 +
To see the CDRs, open file /var/log/yate-cdr.csv
 +
 
 +
 
 +
1389371573,"1389371436-1","sip/1","192.168.168.156:5060","103","104",43,20,63,"incoming","answered",""
 +
1389371573,"1389371436-1","sip/2","192.168.168.18:1368","103","104",43,20,63,"outgoing","answered",""
 +
 
 +
2) Write CDRs with combined set on true and the format for CDR:
 +
 
 +
[general]
 +
file=/var/log/yate-cdr.csv
 +
combined=true
 +
; comma-separated (.csv), combined=true
 +
format=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${status}",\
 +
"${reason}","${out_leg.chan}","${out_leg.address}",${out_leg.billtime},${out_leg.ringtime},${out_leg.duration},"${out_leg.reason}"
 +
 
 +
To see the CDRs, open file /var/log/yate-cdr.csv
 +
 
 +
1389374027,"1389373828-6","sip/6","192.168.168.18:1368","1234567890","103",36,25,61,"answered","","sip/7","192.168.168.156:5060",36,25,61,""
  
 
===Converting call time===
 
===Converting call time===
Line 48: Line 111:
 
If you need a human and machine readable representation of the time column you can use the following AWK script:
 
If you need a human and machine readable representation of the time column you can use the following AWK script:
 
   
 
   
  awk 'BEGIN{FS="\t";OFS="\t"} {$1=strftime("%Y%m%d%H%M%S",$1); print $0}' /var/log/yate-cdr.tsv
+
  awk 'BEGIN{FS=",";OFS=","} {$1=strftime("%Y%m%d%H%M%S",$1); print $0}' /var/log/yate-cdr.csv
 +
 
 +
The above assumes comma-separated format, the ${time} parameter is in the first column (the $1 positional parameter) and the CDR file is in its usual place.
 +
 
 +
Adapt the script as needed. You can make the date/time more readable by inserting separators in the time format:
 +
 
 +
awk 'BEGIN{FS=",";OFS=","} {$1=strftime("%Y-%m-%d %H:%M:%S",$1); print $0}' /var/log/yate-cdr.csv
 +
2014-01-10 18:32:53,"1389371436-1","sip/1","192.168.168.156:5060","103","104",43,20,63,"incoming","answered",""
 +
2014-01-10 18:32:53,"1389371436-1","sip/2","192.168.168.18:1368","103","104",43,20,63,"outgoing","answered",""
 +
.........
 +
 
 +
'''See also'''
  
The above assumes TAB separated format, the ${time} parameter is in the first column (the $1 positional parameter) and the CDR file is in its usual place.
+
* [[CDR Build Module]]
 +
* [[Modules]]
  
Adapt the script as needed. You can make the date/time more readable by inserting separators in the time format.
+
[[Category:CDR]] [[Category:Converting time]] [[Category:Billing]]

Latest revision as of 15:14, 11 January 2014

This module is used to write the CDRs(call detail record) into a file. The configuration file is cdrfile.conf.

Cdrfile is a module that receives a call.cdr message (maybe from cdrbuild).

Contents

[edit] The configuration file

The file used in configuration is cdrfile.conf.

[edit] Section [general]

  • file: string: Name of the file to write the CDR to
You should check that this file is log rotated - see '/etc/logrotate.d/yate'
Example: file=/var/log/yate-cdr.tsv
  • tabs: bool: Use tab-separated instead of comma-separated if format is missing.
tabs=true
  • combined: bool: Use combined CDR for all legs of a call.
combined=false
  • format: string: Custom format to use, overrides default.
Each ${parameter} is replaced with the value of that parameter in the call.cdr message.
Below are listed the format defaults for each mode combination:
  • tab-separated (.tsv), combined=false
format=${time} ${billid} ${chan} ${address} ${caller} ${called} ${billtime} ${ringtime} ${duration} ${direction} ${status} {reason}
  • tab-separated (.tsv), combined=true
format=${time} ${billid} ${chan} ${address} ${caller} ${called} ${billtime} ${ringtime} ${duration} ${status} ${reason} ${out_leg.chan}
${out_leg.address} ${out_leg.billtime} ${out_leg.ringtime} ${out_leg.duration} ${out_leg.reason}
  • comma-separated (.csv), combined=false
format=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${direction}","${status}","${reason}"
  • comma-separated (.csv), combined=true
format=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${status}","${reason}","${out_leg.chan}",
"${out_leg.address}",${out_leg.billtime},${out_leg.ringtime},${out_leg.duration},"${out_leg.reason}"

[edit] List of available variables that could be used to construct a CDR record

Note: in order for a parameter to be available in the CDR, it has to be enabled in cdrbuild.conf.

The "cdrwrite" parameter is special, a boolean value of false will prevent the CDR from being written. This is to avoid generating CDR records for utility channels while still being able to track them.

  • ${time} - UNIX time
  • ${billid} - billing record id
  • ${chan} - channel used
  • ${address} - destination address
  • ${caller} - username/number of the device that initiated/received the call
  • ${called} - destination number
  • ${callername} - caller id
  • ${billtime} - billable call duration, starts from the point when the remote party actually answers the call
  • ${ringtime} - amount of time the call was in ring state, from first ring to answer or hangup
  • ${duration} - total time of the call
  • ${direction} - has a value of outgoing or incoming
  • ${status} - disposition of the call
  • ${reason} - reason for call disconnection
  • ${out_leg.chan} - outgoing call leg channel used
  • ${out_leg.address} - the destination address for outgoing call leg
  • ${out_leg.billtime} - the billable outgoing call leg duration
  • ${out_leg.ringtime} - ring time of the outgoing call leg
  • ${out_leg.duration} - total time of the outgoing call leg
  • ${out_leg.reason} - reason for outgoing call leg disconnection

[edit] Usage example

[edit] Set CDR billing

In many real-life situations CDR billing is done in seconds.

It's useful to set:

cdrbuild.conf

[general]
resolution=sec


[edit] Write CDR to file

1) Write CDRs with combined set on false and the format below:

cdrfile.conf

[general]
file=/var/log/yate-cdr.csv
format=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${direction}","${status}","${reason}"


To see the CDRs, open file /var/log/yate-cdr.csv


1389371573,"1389371436-1","sip/1","192.168.168.156:5060","103","104",43,20,63,"incoming","answered",""
1389371573,"1389371436-1","sip/2","192.168.168.18:1368","103","104",43,20,63,"outgoing","answered",""

2) Write CDRs with combined set on true and the format for CDR:

[general]
file=/var/log/yate-cdr.csv
combined=true
; comma-separated (.csv), combined=true
format=${time},"${billid}","${chan}","${address}","${caller}","${called}",${billtime},${ringtime},${duration},"${status}",\
"${reason}","${out_leg.chan}","${out_leg.address}",${out_leg.billtime},${out_leg.ringtime},${out_leg.duration},"${out_leg.reason}"

To see the CDRs, open file /var/log/yate-cdr.csv

1389374027,"1389373828-6","sip/6","192.168.168.18:1368","1234567890","103",36,25,61,"answered","","sip/7","192.168.168.156:5060",36,25,61,""

[edit] Converting call time

If you need a human and machine readable representation of the time column you can use the following AWK script:

awk 'BEGIN{FS=",";OFS=","} {$1=strftime("%Y%m%d%H%M%S",$1); print $0}' /var/log/yate-cdr.csv

The above assumes comma-separated format, the ${time} parameter is in the first column (the $1 positional parameter) and the CDR file is in its usual place.

Adapt the script as needed. You can make the date/time more readable by inserting separators in the time format:

awk 'BEGIN{FS=",";OFS=","} {$1=strftime("%Y-%m-%d %H:%M:%S",$1); print $0}' /var/log/yate-cdr.csv
2014-01-10 18:32:53,"1389371436-1","sip/1","192.168.168.156:5060","103","104",43,20,63,"incoming","answered",""
2014-01-10 18:32:53,"1389371436-1","sip/2","192.168.168.18:1368","103","104",43,20,63,"outgoing","answered",""
.........

See also

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers