[Home]

Summary:ASTERISK-06299: AGI Does not complete running before terminating.
Reporter:shad (shad)Labels:
Date Opened:2006-02-13 04:30:52.000-0600Date Closed:2011-06-07 14:03:26
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Resources/res_agi
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description: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 based on 1.2.4 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.

I then ran through all the versions of Asterisk from http://ftp.digium.com/pub/asterisk/old-releases/

I found that the AGI worked untill version 1.0.10; and then breaks. I have moved my production envionment to 1.0.5 and zaptel 1.0.4 and my AGI works!

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

It is useful to be able to run an AGI for sometime after the call terminates; this allows us as the developers to develop applications that are dependend on other systems.

I appreciate all your hard work at Asterisk; great product.

Warm Regards

Shad Mortazavi
------------------------------------------------------
Nexus Group Technical Manager
n|m Nexus Management Inc


#!/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,Recording,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'");

Comments:By: Donny Kavanagh (donnyk) 2006-02-13 09:13:50.000-0600

There was a change in res_agi for apparentally a bug which asterisk not to send the script a SIGINT/SIGHUP (not sure which) when the channel hangs up. Presumably you want to continue running commands after a channel terminates.  To resolve this you need to trap these in your perl script, and ignore them so you can finish your script.

By: shad (shad) 2006-02-13 09:18:01.000-0600

Thank you for the update. How would I go about this in Perl?

By: Donny Kavanagh (donnyk) 2006-02-13 09:23:50.000-0600

see bug ASTERISK-4733

By: shad (shad) 2006-02-14 02:17:02.000-0600

Thanks.

This resolved my issue. I will add a link to this page from 4854. I think it would be a good idea to add this as a feature. i.e when using the AGI command from within Asterisk you can set the $SIG{HUP} = "IGNORE";.

This would help people who are developing applications.

By: Donny Kavanagh (donnyk) 2006-02-14 17:03:09.000-0600

Bug Marshalls, please link with 4854 and flag this as resolved.

By: Donny Kavanagh (donnyk) 2006-02-15 00:23:40.000-0600

http://bugs.digium.com/view.php?id=6491

By: Tilghman Lesher (tilghman) 2006-02-15 12:50:34.000-0600

Closed by request.