[Asterisk-Users] Possible AGI Bug in Asterisk?

Shad Mortazavi Shad.Mortazavi at nexusmgmt.com
Wed Feb 8 04:28:13 MST 2006


Dear All,

I seem to have stumbled across an AGI problem;

I have written an AGI Script (bottom of this email);

The script does the following;

Makes a CDR entry when called
Records the call
Updates the CDR
Finds a corresponding DNIS from the SMDR table (captured via a serial
port logger)
Matches up the record and updates the CDR.

The script works perfectly in my test lab and has been doing so for
months. I have moved the script over to the production environment and
the script stops after;

$AGI->record_file($fname,'gsm',9,-1);...

Since the test environment was different to the production environment;
I upgraded my test environment from Asterisk V1 and RedHat 9 to V1.2.4
and CentOS.

Now in the test environment my script stops after;

$dbh ->do("Update CDR SET Recording='0',GSM_File_Size='$size' WHERE
GSM_File = '$finame'"); 

In both instances there are no perl errors and no errors reported in the
CLI. In fact the CLI comes back and tells me everything is OK.

Is this a known issue? Has someone else run into this? Is there a fix or
patch?

It looks to me like some type of timing issue with the AGI?

Any help would be appreciated. I have a production deadline.


Warm Regards

Shad Mortazavi


#!/usr/bin/perl

# CCVR Recording Module Shad Mortazavi December 15, 2005

use Asterisk::AGI;
use DBI;

#Create a DB-DNS
my $dbh = DBI
->connect('DBI:mysql:CCVR;192.168.6.56','CCVR_User','****');
my $dbh1 = DBI
->connect('DBI:mysql:CCVR_ADMIN;192.168.6.56','CCVR_User','****');
my $dbh3 = DBI ->connect('DBI:mysql:CCVR;172.16.1.233','user1','****');

#Create AGI
$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();

# Capture the extension dialed
my $extn = $input {'extension'};

#Answer the Call
$AGI->answer();
	
#generate a file name based on the time and extension dialed
$ti = time();
$dir = "/vol/recordings/";
$finame = $ti."_".$extn;
$fname = $dir.$finame;
$finame = $finame.".gsm";

# populate the DB with the required information
# Agent, Filename, date, time

# Get the Date and Time
$gdate = $dbh->selectrow_array ("SELECT current_date()");
$gtime = $dbh->selectrow_array ("SELECT current_time()");
$date_time = "$gdate $gtime";

# Cross reference the Agent Phone with extension
$phone = $dbh1->selectrow_array ("SELECT phone from map where extn =
'$extn'");
$agent = $dbh1->selectrow_array ("SELECT UserID from agent where phone =
'$phone'");

# Put data in DB
$dbh ->do("INSERT INTO CDR
(recording_date,Extension,Phone,Agent,GSM_File,GSM_File_Size,State,Recor
ding,Telco_DNIS,Assigned_DNIS,Campaign) VALUES
('$date_time','$extn','$phone','$agent','$finame','$size','0','1','++++'
,'++++','++++')");

# Log Transaction
$dbh1 ->do("INSERT INTO agent_log (date, action,agent, note) VALUES
('$date_time','Recording','$loginname','Agent $agent Recording $GSM_File
on phone $phone')");


# Start Recording
$AGI->record_file($fname,'gsm',9,-1);

# Get the file size
$fname = $fname.".gsm";
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat($fname);

# Put data in DB
$dbh ->do("Update CDR SET Recording='0',GSM_File_Size='$size' WHERE
GSM_File = '$finame'");


########################################################################
################
### This code is for people using the serial_logger to extract
information #### from a PBX
########################################################################
################


$agi_sleep_time = $dbh1->selectrow_array ("SELECT agi_sleep_time from
system_variables where id = '1'");
$SMDR_log_Variance = $dbh1->selectrow_array ("SELECT SMDR_log_Variance
from system_variables where id = '1'");


# Sleep to make sure we get the serial input we need following the call

sleep $agi_sleep_time;

# Get the date from the SMDR table

# Get the Date and Time
$gdate = $dbh->selectrow_array ("SELECT current_date()");
$gtime = $dbh->selectrow_array ("SELECT current_time()");
$date_time = "$gdate $gtime";


# Get information from SMDR DB
$Telco_DNIS = $dbh3->selectrow_array ("SELECT DNIS from SMDR where Extn
= '$phone' and CCVR_Date_Time >= ('$date_time' - INTERVAL
$SMDR_log_Variance SECOND)");
$Digits = $dbh3->selectrow_array ("SELECT Digits from SMDR where Extn =
'$extn' and CCVR_Date_Time >= ('$date_time' - INTERVAL
$SMDR_log_Variance SECOND)");


if ($Telco_DNIS){
# Get information from DNIS Table
$Campaign_ID = $dbh1->selectrow_array ("SELECT Campaign_ID from DNIS
where Telco_DNIS = '$Telco_DNIS'");
$Assigned_DNIS = $dbh1->selectrow_array ("SELECT DNIS from DNIS where
Telco_DNIS = '$Telco_DNIS'");
$Campaign = $dbh1->selectrow_array ("SELECT Campaign from campaign where
id = '$Campaign_ID'");

}else{
$Telco_DNIS = "****";
$Campaign = "****";
$Assigned_DNIS = "****";
}

# Update the call record
$dbh ->do("Update CDR SET Telco_DNIS ='$Telco_DNIS', Assigned_DNIS
='$Assigned_DNIS', Campaign = '$Campaign', DDID = '$Digit' WHERE
GSM_File = '$finame'");





More information about the asterisk-users mailing list