dOpensource / dsiprouter

UI Interface for implementing Kamailio to provide PBX Hosting and SIP Trunking Services
https://dsiprouter.org
Apache License 2.0
197 stars 105 forks source link

CDR's causes errors #312

Closed mackhendricks closed 2 years ago

mackhendricks commented 3 years ago

Sometimes Kamailio will create ACC records that doesn't have value for calltype,src_gwgroupid,dst_gwgroupid which causes errors in the logs

Sep  1 08:39:05 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [SET_CALLINFO] <ED7VCcW3T2pqkMlznyvlaA..> ip auth - gwgroupid: 25, gatewaytype: 9

Sep  1 08:39:05 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [NEXTHOP] <ED7VCcW3T2pqkMlznyvlaA..> The call coming from 172.16.1.2 is from a pbx

Sep  1 08:39:05 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [RELAY-CALLLIMIT] <ED7VCcW3T2pqkMlznyvlaA..> Call limit for src endpoint group 25 is 32

Sep  1 08:39:05 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [RELAY] <ED7VCcW3T2pqkMlznyvlaA..> Attempting to route call to sip:+4917661116664@213.41.124.20:5060

Sep  1 08:39:11 pbx01-ham /usr/sbin/kamailio[11608]: ERROR: db_mysql [km_dbase.c:122]: db_mysql_submit_query(): driver error on query: Incorrect integer value: '' for column `kamprod`.`acc`.`dst_gwgroupid` at row 1 (1366)

Sep  1 08:39:11 pbx01-ham /usr/sbin/kamailio[11608]: ERROR: <core> [db_query.c:244]: db_do_insert_cmd(): error while submitting query

Sep  1 08:39:11 pbx01-ham /usr/sbin/kamailio[11608]: ERROR: acc [acc.c:477]: acc_db_request(): failed to insert into database

Sep  1 08:39:11 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [SET_CALLINFO] <jijJZlwTv9KcBgU3mZLyMg..> ip auth - gwgroupid: 25, gatewaytype: 9

Sep  1 08:39:11 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [NEXTHOP] <jijJZlwTv9KcBgU3mZLyMg..> The call coming from 172.16.1.2 is from a pbx

Sep  1 08:39:11 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [RELAY-CALLLIMIT] <jijJZlwTv9KcBgU3mZLyMg..> Call limit for src endpoint group 25 is 32

Sep  1 08:39:11 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [RELAY] <jijJZlwTv9KcBgU3mZLyMg..> Attempting to route call to sip:+494231677330@212.36.166.244:5060

Sep  1 08:39:11 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [RELAY] <ED7VCcW3T2pqkMlznyvlaA..> Attempting to route call to sip:+4917661116664@213.41.124.20:5060

Sep  1 08:39:14 pbx01-ham /usr/sbin/kamailio[11608]: INFO: <script>: [RELAY] <ED7VCcW3T2pqkMlznyvlaA..> Attempting to route call to sip:+49421377000@172.16.1.2:5060

Sep  1 08:39:14 pbx01-ham /usr/sbin/kamailio[11608]: ERROR: db_mysql [km_dbase.c:122]: db_mysql_submit_query(): driver error on query: Incorrect integer value: '' for column `kamprod`.`acc`.`src_gwgroupid` at row 1 (1366)

Sep  1 08:39:14 pbx01-ham /usr/sbin/kamailio[11608]: ERROR: <core> [db_query.c:244]: db_do_insert_cmd(): error while submitting query

Sep  1 08:39:14 pbx01-ham /usr/sbin/kamailio[11608]: ERROR: acc [acc.c:477]: acc_db_request(): failed to insert into database

Here are the sql statement to reproduce the issue

insert into `acc` (`method`,`from_tag`,`to_tag`,`callid`,`sip_code`,`sip_reason`,`time`,`src_user`,`src_domain`,`src_ip`,`dst_ouser`,`dst_user`,`dst_domain`,`calltype`,`src_gwgroupid`,`dst_gwgroupid` ) values ('INVITE','61ddc75a','gK00b415a3','ED7VCcW3T2pqkMlznyvlaA..','200','OK','2020-09-01 08:39:11','+49421377002','sip.q-telecom.net','172.16.1.2','+4917661117774','+4917661116665','213.41.124.20','outbound','25','')

insert into `acc` (`method`,`from_tag`,`to_tag`,`callid`,`sip_code`,`sip_reason`,`time`,`src_user`,`src_domain`,`src_ip`,`dst_ouser`,`dst_user`,`dst_domain`,`calltype`,`src_gwgroupid`,`dst_gwgroupid` ) values ('BYE','gK00b415a3','61ddc75a','ED7VCcW3T2pqkMlznyvlaA..','200','OK','2020-09-01 08:39:14','+4917661116674','sip.q-telecom.net','213.41.124.20','+49421377001','+49421377001','172.16.1.2','','','')
devopsec commented 3 years ago

For INVITE's, this relates to the conversation we had about dispatcher / drouting module usage in our kamailio config.
The summary is that drouting has a way we can figure out the dst_gwgroupid after matching a destination whereas dispatcher does not.

For BYE's, the avp's we set are not available because its a new transaction (new call ID etc..)
To work around this we could track the variables in dialog instead, i.e.)

We set the gwgroup variables using $dlg_var(), then
In RELAY route for initial INVITE's we call dlg_manage() right before relaying

mackhendricks commented 2 years ago

There are probably many use cases where CDR's are not working. But, I focused on implementing support for CDR's for DOMAIN AUTH. Basically, the src_gwgroupid was not being set because the SET_CALLINFO function was not being set. So, now completed calls and attempted calls will show up in the CDR. A future enhancement will consist of showing the SIP code and SIP Message. That data is currently available in the kamailio.acc table. But, we don't expose this information via the dSIPRouter GUI.