[asterisk-bugs] [JIRA] (ASTERISK-24992) cdr_adaptive_odbc: Check the column in table is nulleable

Matt Jordan (JIRA) noreply at issues.asterisk.org
Mon Apr 27 09:46:33 CDT 2015


    [ https://issues.asterisk.org/jira/browse/ASTERISK-24992?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=226011#comment-226011 ] 

Matt Jordan commented on ASTERISK-24992:
----------------------------------------

I'm going to quote my comment on the Gerrit review, as I don't think this bug is the fault of {{cdr_adaptive_odbc}}:

{quote}
I couldn't really tell what is going here from the issue description or commit message. Looking at the issue, however, I think there is a problem in the CDR core that your patch is attempting to work around, which is not the correct solution to this problem.

Looking at what is attempting to be inserted into the table from your log:

[Apr 21 03:33:29] WARNING[30476]: cdr_adaptive_odbc.c:752 odbc_log: cdr_adaptive_odbc: Insert failed on 'asterisk:cdr'. CDR failed: INSERT INTO cdr (calldate,clid,dst,dcontext,channel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid) VALUES ({ ts '2015-04-21 03:33:24' },'"" <>','700','parkedcalls','Console/dsp','Park','default:701',5,5,'ANSWERED',3,'1429598004.6')

At first glance, nothing about that appears to be incorrect: that is, the data looks correct. However, from the columns in your table, we can see that one is missing: 'src'.
{noformat}
> Found calldate column with type 93 with len 19, octetlen 19, and numlen (0,0)
> Found clid column with type 12 with len 80, octetlen 255, and numlen (0,0)
> Found src column with type 12 with len 80, octetlen 255, and numlen (0,0)
> Found dst column with type 12 with len 80, octetlen 255, and numlen (0,0)
> Found dcontext column with type 12 with len 80, octetlen 255, and numlen (0,0)
> Found channel column with type 12 with len 80, octetlen 255, and numlen (0,0)
> Found dstchannel column with type 12 with len 80, octetlen 255, and numlen (0,0)
> Found lastapp column with type 12 with len 80, octetlen 255, and numlen (0,0)
> Found lastdata column with type 12 with len 80, octetlen 255, and numlen (0,0)
> Found duration column with type 4 with len 10, octetlen 10, and numlen (0,10)
> Found billsec column with type 4 with len 10, octetlen 10, and numlen (0,10)
> Found disposition column with type 12 with len 45, octetlen 255, and numlen (0,0)
> Found amaflags column with type 4 with len 10, octetlen 10, and numlen (0,10)
> Found accountcode column with type 12 with len 20, octetlen 255, and numlen (0,0)
> Found uniqueid column with type 12 with len 150, octetlen 255, and numlen (0,0)
> Found userfield column with type 12 with len 255, octetlen 255, and numlen (0,0)
{noformat}

The fact is, 'src' should *not* be missing. The value of 'src' is supposed to be the Party A caller number. My guess is that the value is NULL on the channel, which causes the ast_copy_string in cdr.c to simply set the CDR object being posted to the backends to be NULL as well:
{code}
/* Party A */
ast_assert(party_a != NULL);
ast_copy_string(cdr_copy->accountcode, party_a->accountcode, sizeof(cdr_copy->accountcode));
cdr_copy->amaflags = party_a->amaflags;
ast_copy_string(cdr_copy->channel, party_a->name, sizeof(cdr_copy->channel));
ast_callerid_merge(cdr_copy->clid, sizeof(cdr_copy->clid), party_a->caller_name, party_a->caller_number, "");
ast_copy_string(cdr_copy->src, party_a->caller_number, sizeof(cdr_copy->src));
ast_copy_string(cdr_copy->uniqueid, party_a->uniqueid, sizeof(cdr_copy->uniqueid));
ast_copy_string(cdr_copy->lastapp, it_cdr->appl, sizeof(cdr_copy->lastapp));
ast_copy_string(cdr_copy->lastdata, it_cdr->data, sizeof(cdr_copy->lastdata));
ast_copy_string(cdr_copy->dst, it_cdr->exten, sizeof(cdr_copy->dst));
ast_copy_string(cdr_copy->dcontext, it_cdr->context, sizeof(cdr_copy->dcontext));
{code}

This same problem could occur in other CDR backends as well, so the correct fix is to make sure that cdr_copy->src is set to an empty string if party_a->caller_number is NULL.

It probably should be:
{code}
ast_copy_string(cdr->src, S_OR(party_a->caller_number, ""), sizeof(cdr->src));
{code}

Note this is what it used to be in 11:

{code}
ast_copy_string(cdr->src, S_OR(num, ""), sizeof(cdr->src));
{code}
{quote}

I'll attach a patch that I believe fixes the issue correctly in the Asterisk core.

> cdr_adaptive_odbc: Check the column in table is nulleable
> ---------------------------------------------------------
>
>                 Key: ASTERISK-24992
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-24992
>             Project: Asterisk
>          Issue Type: Improvement
>      Security Level: None
>          Components: CDR/cdr_adaptive_odbc
>    Affects Versions: 13.3.2
>            Reporter: Rodrigo Ramirez Norambuena
>            Severity: Minor
>
> In related by documentation, example https://wiki.asterisk.org/wiki/display/AST/PostgreSQL+CDR+Backend the columns for PostgreSQL is all NOT NULL. 
> If call the any value in cdr is NULL the record is not saved.
> Example test:
> If create a call by console dial
> {code}
> *CLI> module unload cdr_adaptive_odbc.so
>  Unloading cdr_adaptive_odbc.so
>   == Unregistered 'Adaptive ODBC' CDR backend
> Unloaded cdr_adaptive_odbc.so
> *CLI> module load cdr_adaptive_odbc.so
>   == Parsing '/etc/asterisk/cdr_adaptive_odbc.conf': Found
> Loaded cdr_adaptive_odbc.so
> *CLI>     -- Found adaptive CDR table cdr at asterisk.
>     -- Found alias start for column calldate in cdr at asterisk
>        > Found calldate column with type 93 with len 19, octetlen 19, and numlen (0,0)
>        > Found clid column with type 12 with len 80, octetlen 255, and numlen (0,0)
>        > Found src column with type 12 with len 80, octetlen 255, and numlen (0,0)
>        > Found dst column with type 12 with len 80, octetlen 255, and numlen (0,0)
>        > Found dcontext column with type 12 with len 80, octetlen 255, and numlen (0,0)
>        > Found channel column with type 12 with len 80, octetlen 255, and numlen (0,0)
>        > Found dstchannel column with type 12 with len 80, octetlen 255, and numlen (0,0)
>        > Found lastapp column with type 12 with len 80, octetlen 255, and numlen (0,0)
>        > Found lastdata column with type 12 with len 80, octetlen 255, and numlen (0,0)
>        > Found duration column with type 4 with len 10, octetlen 10, and numlen (0,10)
>        > Found billsec column with type 4 with len 10, octetlen 10, and numlen (0,10)
>        > Found disposition column with type 12 with len 45, octetlen 255, and numlen (0,0)
>        > Found amaflags column with type 4 with len 10, octetlen 10, and numlen (0,10)
>        > Found accountcode column with type 12 with len 20, octetlen 255, and numlen (0,0)
>        > Found uniqueid column with type 12 with len 150, octetlen 255, and numlen (0,0)
>        > Found userfield column with type 12 with len 255, octetlen 255, and numlen (0,0)
>  Loaded cdr_adaptive_odbc.so => (Adaptive ODBC CDR backend)
> *CLI> console dial 700 at parkedcalls
> *CLI> [Apr 21 03:33:24] WARNING[30461]: chan_oss.c:495 setformat: Unable to re-open DSP device /dev/dsp: No such file or directory
> [Apr 21 03:33:24] NOTICE[30461]: console_video.c:137 console_video_start: voice only, console video support not present
>     -- Executing [700 at parkedcalls:1] Park("Console/dsp", "") in new stack
>   << Console call has been answered >> 
>     -- Parking 'Console/dsp' in 'default' at space 701
>     -- Channel Console/dsp joined 'holding_bridge' parking-bridge <bb295d4a-bc50-494a-bcdf-60b1ddd0ead0>
> [Apr 21 03:33:24] WARNING[2857][C-00000007]: chan_oss.c:786 oss_indicate: Don't know how to display condition 26 on Console/dsp
>     -- <Console/dsp> Playing 'digits/7.gsm' (language 'en')
> *CLI> [Apr 21 03:33:25] WARNING[2857][C-00000007]: chan_oss.c:495 setformat: Unable to re-open DSP device /dev/dsp: No such file or directory
>     -- <Console/dsp> Playing 'digits/0.gsm' (language 'en')
> hangup [Apr 21 03:33:26] WARNING[2857][C-00000007]: chan_oss.c:495 setformat: Unable to re-open DSP device /dev/dsp: No such file or directory
> request     -- <Console/dsp> Playing 'digits/1.gsm' (language 'en')
> Usage: channel request hangup <channel>|<all>
>        Request that a channel be hung up. The hangup takes effect
>        the next time the driver reads or writes from the channel.
>        If 'all' is specified instead of a channel name, all channels
>        will see the hangup request.
> *CLI>     -- Started music on hold, class 'default', on channel 'Console/dsp'
> [Apr 21 03:33:27] WARNING[2857][C-00000007]: chan_oss.c:495 setformat: Unable to re-open DSP device /dev/dsp: No such file or directory
> hangup request[Apr 21 03:33:28] WARNING[2857][C-00000007]: chan_oss.c:495 setformat: Unable to re-open DSP device /dev/dsp: No such file or directory
>  Console/dsp [Apr 21 03:33:29] WARNING[2857][C-00000007]: chan_oss.c:495 setformat: Unable to re-open DSP device /dev/dsp: No such file or directory
> Requested Hangup on channel 'Console/dsp'
> *CLI>     -- Stopped music on hold on Console/dsp
>     -- Channel Console/dsp left 'holding_bridge' parking-bridge <bb295d4a-bc50-494a-bcdf-60b1ddd0ead0>
>   == Spawn extension (parkedcalls, 700, 1) exited non-zero on 'Console/dsp'
>   << Hangup on console >> 
> [Apr 21 03:33:29] WARNING[30476]: res_odbc.c:649 ast_odbc_prepare_and_execute: SQL Execute returned an error -1: HY000: ERROR:  el valor null para la columna «src» viola la restricción not null;
> Error while executing the query (109)
> [Apr 21 03:33:29] WARNING[30476]: res_odbc.c:661 ast_odbc_prepare_and_execute: SQL Execute error -1! Verifying connection to asterisk [asterisk-connector]...
> [Apr 21 03:33:29] WARNING[30476]: res_odbc.c:765 ast_odbc_sanity_check: Connection is down attempting to reconnect...
> [Apr 21 03:33:29] NOTICE[30476]: res_odbc.c:1531 odbc_obj_connect: Connecting asterisk
> [Apr 21 03:33:29] NOTICE[30476]: res_odbc.c:1563 odbc_obj_connect: res_odbc: Connected to asterisk [asterisk-connector]
> [Apr 21 03:33:29] WARNING[30476]: res_odbc.c:649 ast_odbc_prepare_and_execute: SQL Execute returned an error -1: HY000: ERROR:  el valor null para la columna «src» viola la restricción not null;
> Error while executing the query (109)
> [Apr 21 03:33:29] WARNING[30476]: res_odbc.c:661 ast_odbc_prepare_and_execute: SQL Execute error -1! Verifying connection to asterisk [asterisk-connector]...
> [Apr 21 03:33:29] WARNING[30476]: res_odbc.c:765 ast_odbc_sanity_check: Connection is down attempting to reconnect...
> [Apr 21 03:33:29] NOTICE[30476]: res_odbc.c:1531 odbc_obj_connect: Connecting asterisk
> [Apr 21 03:33:29] NOTICE[30476]: res_odbc.c:1563 odbc_obj_connect: res_odbc: Connected to asterisk [asterisk-connector]
> [Apr 21 03:33:29] WARNING[30476]: cdr_adaptive_odbc.c:752 odbc_log: cdr_adaptive_odbc: Insert failed on 'asterisk:cdr'.  CDR failed: INSERT INTO cdr (calldate,clid,dst,dcontext,channel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid) VALUES ({ ts '2015-04-21 03:33:24' },'"" <>','700','parkedcalls','Console/dsp','Park','default:701',5,5,'ANSWERED',3,'1429598004.6')
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list