Where in the dial plan is the CDR called?

I’ve searched this forum and run a few googles. But wanted a little more detail and some claification on somethings if anyone could help me out it would greatly be appreciated. I’m wanting to know at what point in the dial plan or in what config file is the CDR being written to the MySQL table. I believe this is happening in the cdr_addon_mysql.c file bur am not 100% and even if this is the case where in the dial plan is or should this file be called. All this works on my system so it’s not a matter of functionality but me just trying to understand how asterisk is actually working as I will eventually have to upgrade this system and make some major modifications later to the dialplan. As little or as much detail as anyone is willing to provide would be appreciated. Thanks.

These links weren’t too much help:
voip-info.org/wiki-Asterisk+cdr+mysql
voip-info.org/wiki/view/Asterisk+cdr+csv

It’s not called from any configurations telling it when to write the CDR, it is all built into Asterisk to automatically do this.

Hmmm…Well if that’s the case and I would like to post a primary key from one of my tables in the the asterisk CDR table where would I need to define the {CDR(userfield)} using SetCDRUserfield within the dial plan to accomplish this?

I believe you will want to execute the app before a dial or when the call comes in. Or you can specify it in the ‘h’ extension.

exten => s,12,SetCDRUserField(011,${ARG1},${CALLERIDNUM},${ARG1})

This is roughly what mine looks like, just make sure that you set the cdruserfield BEFORE the final leg of the call is dialed.
the cdr logs as soon as the hangup is made

so set all of your cdr variables FIRST, (like accountcode and crap)

then make the dial

Ok I’ve been able to use SetCDRuserField within the dial plan with no problem, that is reletively easy. But I’ve been working for a while with trying to use the same command with in an AGI script. From my research on the wiki and Googling you should be able to call SetCDRUserField from within an AGI script. But I’ve tried alot of different syntax to get it to work with no success.
Sample AGI Script called StoreAppID.PHP:

[code]
#!/usr/bin/php -q

<?php # turn off output buffering ob_implicit_flush(false); # turn off error reporting, as it will most likely interfere with # the AGI interface error_reporting(0); SetCDRUserField(test); execute ("EXEC Set CDR(userfield) = testing"); write ("SET CONTEXT ext-did"); write ("EXEC GoTO $agi_dnid|3"); exit; ?> [/code]

This was just a sample program to try and get this to work. I call it in the dial plan with:

exten => 2146440102,1,SetVar(FROM_DID=2146440102)
exten => 2146440102,2,agi(storeappid.php)
exten => 2146440102,3,Goto(aa_6,s,1)

Where everything works just as it should except nothing is added to the user field.

Any assistance or general guidance would be appreciated. I’m sure my syntax is off.

Making some progress. I can get the SetCDRUserField to post to the CDR with no problem when using the command in extenstions.conf. But as stated above I’ve been trying to call the command in an AGI script and have been having some problems. My current test program:

#!/usr/bin/php -q
<?php
set_time_limit(30);
include("phpagi.php");
$agi = new AGI();
require_once('phpagi-asmanager.php');
$asm = new AGI_AsteriskManager();

// main program

$agi->verbose("Here we go!");

if ($res = $asm->connect("localhost", "admin", "amp111"))
        {
                echo "Connection established.\n";
                $asm->SetCDRUserField(test);
        }
        elseif($res == FALSE)
        {
                echo "Connection failed.\n";
        }
$asm->disconnect();

// clean up file handlers etc.
fclose($in);
fclose($stdlog);

exit;
?>

This program gives me the output of:

Nov 29 14:56:48 VERBOSE[14745] logger.c: -- Launched AGI Script /var/lib/asterisk/agi-bin/storeappid.php
Nov 29 14:56:48 VERBOSE[14745] logger.c: storeappid.php: Here we go!
Nov 29 14:56:48 DEBUG[14748] manager.c: Manager received command 'login'
Nov 29 14:56:48 VERBOSE[14748] logger.c: == Parsing '/etc/asterisk/manager.conf': Nov 29 14:56:48 VERBOSE[14748] logger.c: == Parsing '/etc/asterisk/manager.conf': Found
Nov 29 14:56:48 VERBOSE[14748] logger.c: == Parsing '/etc/asterisk/manager_custom.conf': Nov 29 14:56:48 VERBOSE[14748] logger.c: == Parsing '/etc/asterisk/manager_custom.conf': Found
Nov 29 14:56:48 DEBUG[14748] acl.c: 0.0.0.0/0.0.0.0/0.0.0.0 appended to acl for peer
Nov 29 14:56:48 DEBUG[14748] acl.c: 127.0.0.1/255.255.255.0/255.255.255.0 appended to acl for peer
Nov 29 14:56:48 DEBUG[14748] acl.c: ##### Testing 127.0.0.1 with 0.0.0.0
Nov 29 14:56:48 DEBUG[14748] acl.c: ##### Testing 127.0.0.1 with 127.0.0.0
Nov 29 14:56:48 VERBOSE[14748] logger.c: == Manager 'admin' logged on from 127.0.0.1
Nov 29 14:56:48 DEBUG[14748] manager.c: Manager received command 'SetCDRUserField'
Nov 29 14:56:48 DEBUG[14748] manager.c: Manager received command 'Logoff'
Nov 29 14:56:48 VERBOSE[14748] logger.c: == Manager 'admin' logged off from 127.0.0.1
Nov 29 14:56:48 VERBOSE[14745] logger.c: -- AGI Script storeappid.php completed, returning 0

Asterisk Manager states it received the command ‘SetCDRUserField’ but it still does not place anything in the CDR.

Can anyone point me in the right direction?

anyone?