通话记录(CDR)

通话记录(CDR)

支持把FreeSWITCH的通话记录写入mysql,sqlserver,oracle等数据库,也可以写入redis的list,或者PUBLISH到redis的channel,方便业务程序实时获取通话记录。

配置说明,在cti.json中添加cdr配置,cdr.json文件路径在cdr.conf.xml中配置,默认时fs的conf目录。

"cdr": {
"details": true,
"fields": [ "rtp_last_audio_codec_string","number:billsec", "number:duration","record_filename" ],
"redis": {
"channel": "cdr",
"list": "cdr"
},
"database": {
"dbtype": "mysql",
"connectionstring": "",
"username": "",
"password": "",
"table": "cdr"
},
"log":false
}
  • details 是否记录所有的CDR信息。JSON格式。
  • fields 要记录那些通道变量,number:开始的表示使用数字格式。

    可以自定义需要记录的通道变量,数据库中也要添加同名字段。
    
  • redis 配置CDR记录到redis的信息,如果不需要记录到redis,就不要配置这个。
  • database.dbtype 数据库类型 比如mysql ,sqlserver
  • connectionstring 连接串。mysql例子:127..0.0.1,3306@dbname sqlserevr例子:tcp:127.0.0.1,1433@dbname
  • username 用户名
  • password
  • table 表名

自定义字段

例子记录外呼队列的自定义变量到CDR

  • 外呼队列添加自定义变量

queue_template_demo

queue_myval_demo

  • mysql添加一个 queue_name的字段
  • cdr.json的 “fields”: [ “rtp_last_audio_codec_string”,”number:billsec”, “number:duration”,”record_filename” ,”queue_name”] 添加queue_name这个自定义变量名。
  • 线路也可以同样的方式添加自定义变量到CDR。

默认字段

  • uuid 通话的UUID
  • channel 通道
  • account sip分机账户或者网关名字或者fromuser
  • direction 方向 inbound outbound
  • destination_number 拨打的号码
  • caller_id_number 主叫
  • callee_id_number 被叫(单腿呼叫为空)
  • sip_term_status 终止sip代码(主动挂断为空)
  • sip_hangup_disposition 挂断说明 recv_bye:对方发起挂断 send_bye:本地发起挂断 recv_refuse:对方拒接 send_refuse:本地取消呼叫
  • network_addr 对方网络地址
  • created_time 发起呼叫时间
  • answered_time 接通时间
  • hungup_time 挂断时间
  • hangup_cause 挂断原因,见下表,含义参考:https://freeswitch.org/confluence/display/FREESWITCH/Hangup+Cause+Code+Table

    常见的几个
    
    RECOVERY_ON_TIMER_EXPIRE 呼叫超时
    NO_USER_RESPONSE 响应超时
    USER_BUSY 线路忙    
    UNALLOCATED_NUMBER  未分配的号码,比如(VOS)路由配置错误    
    CALL_REJECTED 呼叫拒绝,路由配置错误或者设备配置错误
    USER_NOT_REGISTERED 没有注册    
    
    全部说明:
    
    NONE
    UNALLOCATED_NUMBER
    NO_ROUTE_TRANSIT_NET
    NO_ROUTE_DESTINATION
    CHANNEL_UNACCEPTABLE
    CALL_AWARDED_DELIVERED
    NORMAL_CLEARING
    USER_BUSY
    NO_USER_RESPONSE
    NO_ANSWER
    SUBSCRIBER_ABSENT
    CALL_REJECTED
    NUMBER_CHANGED
    REDIRECTION_TO_NEW_DESTINATION
    EXCHANGE_ROUTING_ERROR
    DESTINATION_OUT_OF_ORDER
    INVALID_NUMBER_FORMAT
    FACILITY_REJECTED
    RESPONSE_TO_STATUS_ENQUIRY
    NORMAL_UNSPECIFIED
    NORMAL_CIRCUIT_CONGESTION
    NETWORK_OUT_OF_ORDER
    NORMAL_TEMPORARY_FAILURE
    SWITCH_CONGESTION
    ACCESS_INFO_DISCARDED
    REQUESTED_CHAN_UNAVAIL
    PRE_EMPTED
    FACILITY_NOT_SUBSCRIBED
    OUTGOING_CALL_BARRED
    INCOMING_CALL_BARRED
    BEARERCAPABILITY_NOTAUTH
    BEARERCAPABILITY_NOTAVAIL
    SERVICE_UNAVAILABLE
    BEARERCAPABILITY_NOTIMPL
    CHAN_NOT_IMPLEMENTED
    FACILITY_NOT_IMPLEMENTED
    SERVICE_NOT_IMPLEMENTED
    INVALID_CALL_REFERENCE
    INCOMPATIBLE_DESTINATION
    INVALID_MSG_UNSPECIFIED
    MANDATORY_IE_MISSING
    MESSAGE_TYPE_NONEXIST
    WRONG_MESSAGE
    IE_NONEXIST
    INVALID_IE_CONTENTS
    WRONG_CALL_STATE
    RECOVERY_ON_TIMER_EXPIRE
    MANDATORY_IE_LENGTH_ERROR
    PROTOCOL_ERROR
    INTERWORKING
    SUCCESS
    ORIGINATOR_CANCEL
    CRASH
    SYSTEM_SHUTDOWN
    LOSE_RACE
    MANAGER_REQUEST
    BLIND_TRANSFER
    ATTENDED_TRANSFER
    ALLOTTED_TIMEOUT
    USER_CHALLENGE
    MEDIA_TIMEOUT
    PICKED_OFF"
    USER_NOT_REGISTERED
    PROGRESS_TIMEOUT
    INVALID_GATEWAY
    GATEWAY_DOWN
    INVALID_URL
    INVALID_PROFILE
    NO_PICKUP
    SRTP_READ_ERROR
    BOWOUT
    BUSY_EVERYWHERE
    DECLINE
    DOES_NOT_EXIST_ANYWHERE
    NOT_ACCEPTABLE
    UNWANTED
    

建表SQL例子

CREATE TABLE cdr (
    uuid VARCHAR(50) ,
    channel VARCHAR(100) ,
    account VARCHAR(50) ,
        direction VARCHAR(50) ,
    destination_number VARCHAR(50),
    caller_id_number VARCHAR(50) ,
    callee_id_number VARCHAR(50) ,
    direction VARCHAR(50) ,
    sip_term_status VARCHAR(50) ,
    hangup_cause VARCHAR(100) ,
    sip_hangup_disposition VARCHAR(50) ,
    network_addr VARCHAR(50) ,
    created_time DATETIME ,
    answered_time DATETIME ,
    hungup_time  DATETIME ,
    billsec INT ,
    duration INT ,
    rtp_last_audio_codec_string VARCHAR(50) ,
    record_filename VARCHAR(256) ,
    details TEXT
)