MYSQL: Duplicate CDR entries

HI All,

I wanted to use MySQL as the CDR database, so I configured Asterisk as per this web site: http://www.mikeslab.net/?p=363

Now, when ever I make a call, I get two duplicate entries into the database. These entries are created when the call is hung up.

I saw that there are other people that had this issue (Each call generates 2 CDR records but it was back in '08) and they made changes to [macro-hangupcall]. This doesn’t seem to exist anymore, as I’m sure much has changed since then!

I’m not posting configuration, as mine is exactly the same as the first link above.

The extensions.conf for my example is simply:
`exten => _5000,1,Log(NOTICE, Dialing from ${CALLERID(num)} voicemail)
exten => _5000,2,VoiceMailMain(${CALLERID(num)}@internal)
exten => _5000,3,Hangup()
``

The only thing in the log is:
– Executing [5000@from-internal:3] Hangup(“SIP/1000-00000000”, “”) in new stack

which I don’t think adds any value to this.

Does anyone have any ideas why this would be?

What version of Asterisk are you using and what is the complete console output of a call?

Hi!

I’m running Asterisk on Debian and the version is
Asterisk 11.13.1~dfsg-2+b1 built by buildd @ brahms on a x86_64 running Linux on 2015-01-05 21:34:10 UTC

The complete console output is:
– Executing [5000@from-internal:1] Log(“SIP/1000-00000000”, “NOTICE, Dialing from 1000 voicemail”) in new stack
[2016-03-14 22:15:41] NOTICE[29065][C-00000000]: Ext. 5000:1 @ from-internal: Dialing from 1000 voicemail
– Executing [5000@from-internal:2] VoiceMailMain(“SIP/1000-00000000”, “1000@internal”) in new stack
[2016-03-14 22:15:41] NOTICE[29065][C-00000000]: res_rtp_asterisk.c:4364 ast_rtp_read: Unknown RTP codec 95 received from ‘xxx.xxx.xxx.xxx:56322
– <SIP/1000-00000000> Playing ‘vm-password.gsm’ (language ‘en’)
– Incorrect password ‘’ for user ‘1000’ (context = internal)
– <SIP/1000-00000000> Playing ‘vm-incorrect.gsm’ (language ‘en’)
– <SIP/1000-00000000> Playing ‘vm-password.gsm’ (language ‘en’)
– Incorrect password ‘’ for user ‘1000’ (context = internal)
– <SIP/1000-00000000> Playing ‘vm-incorrect.gsm’ (language ‘en’)
– <SIP/1000-00000000> Playing ‘vm-password.gsm’ (language ‘en’)
– Incorrect password ‘’ for user ‘1000’ (context = internal)
– <SIP/1000-00000000> Playing ‘vm-incorrect.gsm’ (language ‘en’)
– <SIP/1000-00000000> Playing ‘vm-goodbye.gsm’ (language ‘en’)
– Executing [5000@from-internal:3] Hangup(“SIP/1000-00000000”, “”) in new stack
== Spawn extension (from-internal, 5000, 3) exited non-zero on ‘SIP/1000-00000000’

Hello.
Can you show us the output from console?

Enter the Asterisk CLI and type ‘core set verbose 15’.
Then make some call and post the output of inserting CDR to MySQL here.

HI!

Thanks for the response. Below is what I see when calling voicemail @ extension 5000:

== Using SIP RTP CoS mark 5 -- Executing [5000@from-internal:1] Log("SIP/1000-00000023", "NOTICE, Dialing from 1000 voicemail") in new stack [2016-03-17 22:01:27] NOTICE[29162][C-00000022]: Ext. 5000:1 @ from-internal: Dialing from 1000 voicemail -- Executing [5000@from-internal:2] VoiceMailMain("SIP/1000-00000023", "1000@internal") in new stack [2016-03-17 22:01:27] WARNING[29162][C-00000022]: res_rtp_asterisk.c:4145 ast_rtp_read: RTP Read too short [2016-03-17 22:01:27] WARNING[29162][C-00000022]: res_rtp_asterisk.c:4145 ast_rtp_read: RTP Read too short [2016-03-17 22:01:27] WARNING[29162][C-00000022]: res_rtp_asterisk.c:4145 ast_rtp_read: RTP Read too short [2016-03-17 22:01:27] WARNING[29162][C-00000022]: res_rtp_asterisk.c:4145 ast_rtp_read: RTP Read too short > 0x7f45e40ae5c0 -- Probation passed - setting RTP source address to 192.168.1.5:20436 -- <SIP/1000-00000023> Playing 'vm-password.gsm' (language 'en') > 0x7f45e40ae5c0 -- Probation passed - setting RTP source address to 192.168.1.5:20436 [2016-03-17 22:01:35] WARNING[29162][C-00000022]: app_voicemail.c:10587 vm_authenticate: Unable to read password > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid) VALUES ({ ts '2016-03-17 22:01:27' },'1000','1000','5000','from-internal','SIP/1000-00000023','VoiceMailMain','1000@internal',8,8,'ANSWERED',3,'1458212487.35')]

This inserted two records into the database:
mysql> select calldate,src,dst from cdr where calldate = "2016-03-17 22:01:27"; +---------------------+------+------+ | calldate | src | dst | +---------------------+------+------+ | 2016-03-17 22:01:27 | 1000 | 5000 | | 2016-03-17 22:01:27 | 1000 | 5000 | +---------------------+------+------+ 2 rows in set (0.00 sec)

So I recreated the table with a few extra fields. Not sure if this gives any further visibility on what is happening:

I created this table:

CREATE TABLE `cdr` (
   `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
   `calldate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
   `clid` VARCHAR(80) NOT NULL DEFAULT '',
   `src` VARCHAR(80) NOT NULL DEFAULT '',
   `dst` VARCHAR(80) NOT NULL DEFAULT '',
   `dcontext` VARCHAR(80) NOT NULL DEFAULT '',
   `lastapp` VARCHAR(200) NOT NULL DEFAULT '',
   `lastdata` VARCHAR(200) NOT NULL DEFAULT '',
   `duration` FLOAT UNSIGNED NULL DEFAULT NULL,
   `billsec` FLOAT UNSIGNED NULL DEFAULT NULL,
   `disposition` ENUM('ANSWERED','BUSY','FAILED','NO ANSWER','CONGESTION') NULL DEFAULT NULL,
   `channel` VARCHAR(50) NULL DEFAULT NULL,
   `dstchannel` VARCHAR(50) NULL DEFAULT NULL,
   `amaflags` VARCHAR(50) NULL DEFAULT NULL,
   `accountcode` VARCHAR(20) NULL DEFAULT NULL,
   `uniqueid` VARCHAR(32) NOT NULL DEFAULT '',
   `userfield` FLOAT UNSIGNED NULL DEFAULT NULL,
   `answer` DATETIME NOT NULL,
   `end` DATETIME NOT NULL,
   PRIMARY KEY (`id`),
   INDEX `calldate` (`calldate`),
   INDEX `dst` (`dst`),
   INDEX `src` (`src`),
   INDEX `dcontext` (`dcontext`),
   INDEX `clid` (`clid`),
)

This is the output from mysql:

mysql> select id,calldate,src,dst,dstchannel,answer,end from cdr;
+----+---------------------+------------+-------------+------------+---------------------+---------------------+
| id | calldate            | src        | dst         | dstchannel | answer              | end                 |
+----+---------------------+------------+-------------+------------+---------------------+---------------------+
|  1 | 2016-03-18 16:41:42 | 1000| 5000 | NULL       | 2016-03-18 16:41:42 | 2016-03-18 16:41:45 |
|  2 | 2016-03-18 16:41:42 | 1000 | 5000 |            | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
+----+---------------------+------------+-------------+------------+---------------------+---------------------+

Notice that the dstchannel, answer and end fields are different. Any ideas?

So I think its been fixed, but not sure why.

I deleted the columns userfield, accountcode, dstchannel from the cdr table and now I only get single entries.

I’m not sure why that makes a difference, but it did for me!