freeswitch的话单模块
作者:互联网
概述
最近因为业务需要,在看freeswitch中话单相关的一些模块。
在voip的使用过程中,话单是重要的基础模块,涉及到计费和问题查找。
呼叫话单最重要的一点是稳定,不能有错误或遗漏。
本章对fs的话单模块做整体梳理和简单介绍。
环境
centos:CentOS release 7.0 (Final)或以上版本
freeswitch:v1.8.7
GCC:4.8.5
话单模块
freeswitch中CDR相关模块较多,粗略列一下。
mod_cdr_csv
mod_cdr_mongodb
mod_cdr_pg_csv
mod_cdr_sqlite
mod_format_cdr
mod_json_cdr
mod_odbc_cdr
mod_radius_cdr
mod_xml_cdr
其中,mod_cdr_csv模块是默认编译和启动加载的cdr模块,其他模块需要用户自己根据需要编译和加载。
上面列出的模块,大部分可以根据名字猜测出模块的主要功能,比如,“mod_cdr_csv”模块表示把CDR话单写入CSV文件,“mod_cdr_mongodb”模块表示把CDR话单写入mongodb数据库。
每个模块都有自己单独的配置文件。
根据项目需求,这里主要关注CDR话单写入文件的模块,其他写数据库的模块暂时先略过。
mod_cdr_csv
freeswitch默认CDR模块,自动编译、安装、加载。
模块对应配置文件为“/usr/local/freeswitch/autoload_configs/cdr_csv.conf.xml”。
配置文件中可以设置多个CDR模板,并根据通道变量“accountcode”的值来对应模板名出话单。
CDR模板中可以使用fs会话的所有通道变量,并根据需求设置模板格式。
修改配置文件“/usr/local/freeswitch/autoload_configs/cdr_csv.conf.xml”。
<template name="example">{"data":{"ACCOUNTCODE":"${ACCOUNTCODE}","channel_va_test":"${channel_va_test}","${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}","${accountcode}","${read_codec}","${write_codec}"}}</template>
<template name="snom">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}", "${accountcode}","${read_codec}","${write_codec}","${sip_user_agent}","${call_clientcode}","${sip_rtp_rxstat}","${sip_rtp_txstat}","${sofia_record_file}"</template>
设置通道变量“ACCOUNTCODE”为“snom”,呼叫测试。
呼叫结束之后,可以在“/usr/local/freeswitch/log/cdr-csv/Master.csv”文件中找到话单如下。
{"data":{"ACCOUNTCODE":"snom","channel_va_test":"","Outbound Call","1001","1001","ext_test","2022-06-23 14:36:25","2022-06-23 14:36:27","2022-06-23 14:36:33","8","6","ALLOTTED_TIMEOUT","cdbb0266-f2be-11ec-b928-a1f80b63cfc8","","snom","PCMA","PCMA"}}
同时,在“/usr/local/freeswitch/log/cdr-csv/snom.csv”文件中找到话单如下。
"Outbound Call","1001","1001","ext_test","2022-06-23 14:36:25","2022-06-23 14:36:27","2022-06-23 14:36:33","8","6","ALLOTTED_TIMEOUT","cdbb0266-f2be-11ec-b928-a1f80b63cfc8","", "snom","PCMA","PCMA","FreeSWITCH-mod_sofia/1.6.19+git~20220408T073647Z~f81cb238da~64bit","","","",""
mod_json_cdr
mod_json_cdr模块默认不编译,不安装,不加载。
进入“freeswitch-1.6.19_master/src/mod/event_handlers/mod_json_cdr”目录,编译安装。
make install
cd /usr/local/freeswitch/mod
ll -tr
-rwxr-xr-x. 1 root root 122096 Jul 6 16:00 mod_json_cdr.so
-rwxr-xr-x. 1 root root 1289 Jul 6 16:00 mod_json_cdr.la
cd /usr/local/freeswitch/mod/autoload_configs
vi modules.conf.xml
<load module="mod_json_cdr"/>
模块对应配置文件“/usr/local/freeswitch/conf/autoload_configs/json_cdr.conf.xml”。
呼叫测试。
呼叫结束之后,可以在“/usr/local/freeswitch/log/json_cdr/49704084-fd13-11ec-8158-19509e341d8a.cdr.json”文件中找到话单如下。
{
"core-uuid":"3e74f030-fd13-11ec-8155-19509e341d8a",
"switchname":"localhost.localdomain",
"channel_data":{
"state":"CS_REPORTING",
"direction":"outbound",
"state_number":"11",
"flags":"0=1;1=1;2=1;20=1;37=1;38=1;40=1;43=1;53=1;60=1;95=1;112=1;113=1;122=1",
"caps":"1=1;2=1;3=1;4=1;5=1;6=1"
},
"callStats":Object{...},
"variables":Object{...},
"app_log":Object{...},
"callflow":Array[2]
}
mod_format_cdr
mod_format_cdr模块默认不编译,不安装,不加载。
进入“freeswitch-1.6.19_master/src/mod/event_handlers/mod_format_cdr”目录,编译安装。
make install
cd /usr/local/freeswitch/mod
ll -tr
-rwxr-xr-x. 1 root root 122096 Jul 6 16:00 mod_format_cdr.so
-rwxr-xr-x. 1 root root 1289 Jul 6 16:00 mod_format_cdr.la
cd /usr/local/freeswitch/mod/autoload_configs
vi modules.conf.xml
<load module="mod_format_cdr"/>
模块对应配置文件“/usr/local/freeswitch/autoload_configs/format_cdr.conf.xml”
呼叫测试。
呼叫结束之后,可以在“/usr/local/freeswitch/log/format_cdr”目录找到俩个话单文件。
cat a_49704084-fd13-11ec-8158-19509e341d8a.cdr.json
{
"core-uuid":"3e74f030-fd13-11ec-8155-19509e341d8a",
"switchname":"localhost.localdomain",
"channel_data":Object{...},
"callStats":Object{...},
"variables":Object{...},
"app_log":Object{...},
"callflow":Array[2]
}
cat a_49704084-fd13-11ec-8158-19509e341d8a.cdr.xml
<?xml version="1.0"?>
<cdr core-uuid="3e74f030-fd13-11ec-8155-19509e341d8a" switchname="localhost.localdomain">
<channel_data>
...
</channel_data>
<call-stats>
...
</call-stats>
<variables>
...
</variables>
<app_log>
...
</app_log>
<callflow dialplan="XML" unique-id="4b39417c-fd13-11ec-815a-19509e341d8a" clone-of="4970484a-fd13-11ec-8159-19509e341d8a" profile_index="2">
...
</callflow>
</cdr>
总结
mod_cdr_csv模块是fs的基础话单模块。
mod_format_cdr模块的功能包含了mod_json_cdr和mod_xml_cdr俩个模块的功能,是后二者的超集,具有替换作用。
空空如常
求真得真
标签:话单,模块,的话,cdr,freeswitch,local,mod 来源: https://www.cnblogs.com/qiuzhendezhen/p/16481590.html