freeswitch — cdr в mysql базе. mod_odbc_cdr

По умолчанию при сборке freeswitch ставится mod_csv_cdr, который пишет в csv файлы данные, можно конечно делать ротацию файлов, но это происходит не в реальном времени, и такой вариант не очень удобен. Для freeswitch есть модуль mod_odbc_cdr, который пишет в odbc cdr записи. Внимание! Перед сборкой freeswitch необходимо установить unixODBC, иначе freeswitch не сможет обращаться к ODBC. ключ
./configure --enable-core-odbc-support
 
yum install unixODBC mysql-connector-odbc
Если модуль mod_odbc_cdr не был собран при компиляции freeswitch, то необходимо установить его.
cd /usr/src/freeswitch/src/mod/event_handlers/mod_odbc_cdr
make 
make install
Настройка производится в файле /usr/local/freeswitch/conf/autoload_configs/odbc_cdr.conf.xml,
<configuration name="odbc_cdr.conf" description="ODBC CDR Configuration">
 <settings>
 <!-- <param name="odbc-dsn" value="database:username:password"/> -->
 <param name="odbc-dsn" value="odbc://DRIVER=mysql;SERVER=localhost;UID=user;PWD=password;DATABASE=dbname;OPTION=67108864"/>
<!-- 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="/usr/local/freeswitch/log/odbc_cdr"/>
 <!-- if "csv-path-on-fail" is set, failed INSERTs will be placed here as CSV files otherwise they will be placed in "csv-path" -->
 <param name="csv-path-on-fail" value="/usr/local/freeswitch/log/odbc_cdr/failed"/>
 <!-- dump SQL statement after leg ends -->
<param name="debug-sql" value="true"/>
 </settings>
 <tables>
<!-- only a-legs will be inserted into this table -->
 <table name="cdr_table_a_leg" log-leg="a-leg">
 <field name="CallId" chan-var-name="call_uuid"/>
 <field name="uuid" chan-var-name="uuid"/>
 <field name="term_id" chan-var-name="sip_call_id"/>
 <field name="ClientId" chan-var-name="uuid"/>
 <field name="IP" chan-var-name="sip_network_ip"/>
 <field name="IPInternal" chan-var-name="sip_via_host"/>
 <field name="CODEC" chan-var-name="read_codec"/>
 <field name="directGateway" chan-var-name="sip_req_host"/>
 <field name="redirectGateway" chan-var-name="sip_redirect_contact_host_0"/>
 <field name="CallerID" chan-var-name="sip_from_user"/>
 <field name="TelNumber" chan-var-name="sip_req_user"/>
 <field name="TelNumberFull" chan-var-name="sip_to_user"/>
 <field name="sip_endpoint_disposition" chan-var-name="endpoint_disposition"/>
 <field name="sip_current_application" chan-var-name="current_application"/>
 <field name="billsec" chan-var-name="billsec"/>
 <field name="duration" chan-var-name="duration"/>
 <field name="start_time" chan-var-name="start_time"/>
 <field name="domain" chan-var-name="domain_name"/>
 <field name="destination_number" chan-var-name="destination_number"/>
 <field name="caller_id_number" chan-var-name="caller_id_number"/>
 </table>
<!-- only b-legs will be inserted into this table -->
 <table name="cdr_table_b_leg" log-leg="b-leg">
 <field name="CallId" chan-var-name="call_uuid"/>
 <field name="orig_id" chan-var-name="uuid"/>
 <field name="term_id" chan-var-name="sip_call_id"/>
 <field name="ClientId" chan-var-name="uuid"/>
 <field name="IP" chan-var-name="sip_network_ip"/>
 <field name="IPInternal" chan-var-name="sip_via_host"/>
 <field name="CODEC" chan-var-name="read_codec"/>
 <field name="directGateway" chan-var-name="sip_req_host"/>
 <field name="redirectGateway" chan-var-name="sip_redirect_contact_host_0"/>
 <field name="CallerID" chan-var-name="sip_from_user"/>
 <field name="TelNumber" chan-var-name="sip_req_user"/>
 <field name="TelNumberFull" chan-var-name="sip_to_user"/>
 <field name="sip_endpoint_disposition" chan-var-name="endpoint_disposition"/>
 <field name="sip_current_application" chan-var-name="current_application"/>
 </table>
<!-- both legs will be inserted into this table -->
 <table name="cdr_table_both">
 <field name="CallId" chan-var-name="call_uuid"/>
 <field name="uuid" chan-var-name="uuid"/>
<field name="term_id" chan-var-name="sip_call_id"/>
 <field name="ClientId" chan-var-name="uuid"/>
 <field name="IP" chan-var-name="sip_network_ip"/>
 <field name="IPInternal" chan-var-name="sip_via_host"/>
 <field name="CODEC" chan-var-name="read_codec"/>
 <field name="directGateway" chan-var-name="sip_req_host"/>
 <field name="redirectGateway" chan-var-name="sip_redirect_contact_host_0"/>
 <field name="CallerID" chan-var-name="sip_from_user"/>
 <field name="TelNumber" chan-var-name="sip_req_user"/>
 <field name="TelNumberFull" chan-var-name="sip_to_user"/>
 <field name="sip_endpoint_disposition" chan-var-name="endpoint_disposition"/>
 <field name="sip_current_application" chan-var-name="current_application"/>
 <field name="billsec" chan-var-name="billsec"/>
 <field name="duration" chan-var-name="duration"/>
 <field name="start_stamp" chan-var-name="start_stamp"/>
 <field name="domain" chan-var-name="domain_name"/>
 <field name="destination_number" chan-var-name="destination_number"/>
 <field name="caller_id_number" chan-var-name="caller_id_number"/>
 </table>
 </tables>
</configuration>
Доступ к базе указывается в параметре odbc-dsn: <param name="odbc-dsn" value="odbc://DRIVER=mysql;SERVER=localhost;UID=user;PWD=password;DATABASE=dbname;OPTION=67108864"/>, в этом случае не требуется указывать базу в файле /etc/odbc.ini