1,
创建odbc 文件
/etc/odbc.ini
[freeswitch]
Driver = MySQL
SERVER = localhost
PORT = 3306
DATABASE = freeswitch
OPTION = 67108864
USER = root
PASSWORD = password
2,
创建freeswitch的数据库
创建数据库cdr表格,把uuid设为主键,其中billsec 和duration为int
CREATE TABLE cdr (
`uuid` varchar(50) DEFAULT NULL,
`caller_id_name` varchar(60) DEFAULT NULL,
`sip_contact_host` varchar(50) DEFAULT NULL,
`sip_received_ip` varchar(50) DEFAULT NULL,
`sip_received_port` varchar(10) DEFAULT NULL,
`direction` varchar(15) DEFAULT NULL,
`caller_id_number` varchar(30) DEFAULT NULL,
`destination_number` varchar(30) DEFAULT NULL,
`context` varchar(10) DEFAULT NULL,
`start_stamp` varchar(30) DEFAULT NULL,
`answer_stamp` varchar(30) DEFAULT NULL,
`end_stamp` varchar(30) DEFAULT NULL,
`duration` int(20) DEFAULT NULL,
`billsec` int(20) DEFAULT NULL,
`hangup_cause` varchar(30) DEFAULT NULL,
`bleg_uuid` varchar(50) DEFAULT NULL,
`read_codec` varchar(30) DEFAULT NULL,
`write_codec` varchar(30) DEFAULT NULL,
PRIMARY KEY (`uuid`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;
3,
增加文件conf/autoload_configs/odbc_cdr.conf.xml
<configuration name="odbc_cdr.conf" description="ODBC CDR Configuration">
<settings>
<param name="odbc-dsn" value="odbc://freeswitch"/>
<!-- global value can be "a-leg", "b-leg", "both" (default is "both") -->
<param name="log-leg" value="both"/>
<!-- value can be "always", "never", "on-db-fail" -->
<param name="write-csv" value="on-db-fail"/>
<!-- location to store csv copy of CDR -->
<param name="csv-path" value="/opt/his/debug/cdr_csv2"/>
<param name="csv-path-on-fail" value="/opt/his/debug/cdr_csv2/failed"/>
<!-- dump SQL statement after leg ends -->
<param name="debug-sql" value="false"/>
</settings>
<tables>
<!-- only a-legs will be inserted into this table -->
<table name="cdr" log-leg="a-leg">
<field name="uuid" chan-var-name="uuid"/>
<field name="caller_id_name" chan-var-name="caller_id_name"/>
<field name="sip_contact_host" chan-var-name="sip_contact_host"/>
<field name="sip_received_ip" chan-var-name="sip_received_ip"/>
<field name="sip_received_port" chan-var-name="sip_received_port"/>
<field name="direction" chan-var-name="direction"/>
<field name="caller_id_number" chan-var-name="caller_id_number"/>
<field name="destination_number" chan-var-name="destination_number"/>
<field name="context" chan-var-name="context"/>
<field name="start_stamp" chan-var-name="start_stamp"/>
<field name="answer_stamp" chan-var-name="answer_stamp"/>
<field name="end_stamp" chan-var-name="end_stamp"/>
<field name="duration" chan-var-name="duration"/>
<field name="billsec" chan-var-name="billsec"/>
<field name="hangup_cause" chan-var-name="hangup_cause"/>
<field name="bleg_uuid" chan-var-name="bleg_uuid"/>
<field name="read_codec" chan-var-name="read_codec"/>
<field name="write_codec" chan-var-name="write_codec"/>
</table>
</tables>
</configuration>
4,代码里uncomment in modules.conf,以编译这个模块
event_handlers/mod_odbc_cdr
5,在conf里面添加load mod_odbc_cdr module
conf/autoload_configs/modules.conf.xml
<load module="mod_odbc_cdr"/>