[Home]

Summary:ASTERISK-06528: Dial in AGI script exits randomly with empty status variables
Reporter:Mr. Zdeeck (mr_zdeeck)Labels:
Date Opened:2006-03-12 05:51:18.000-0600Date Closed:2011-06-07 14:02:57
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:Hi,

I've got problem with Asterisk 1.0.9 (and also with 1.2.5) and I'm just wondering if somebody experienced the same.

I've got DeadAGI script, which dials some PRI line. After that it grabs DIALSTATUS and ANSWEREDTIME variables. From time to time it happens that after executing something like

$res = $AGI->exec('Dial Zap/G1/12345|60|L(3600)");

The Dial command exits immediately, BUT:

* DIALSTATUS and ANSWEREDTIME variables are empty
* the call goes on (!)
* after the call is _really_ hangup, it's written to CDR with non-zero ANSWEREDTIME and DIALSTATUS (with correct values)

I've tried to put Hangup after Dial exits, so I'd be sure that no money is lost. It didn't help. Interesting thing is that it occurs randomly, with no followable pattern. You can imagine that this is a bit problem, because the script does second-level accounting (M$ stuff) which is unfortunatelly necessary in my configuration.
Comments:By: Mr. Zdeeck (mr_zdeeck) 2006-03-12 06:02:26.000-0600

I've just noticed that this behavior is grouped - it happens with same number (if somebody tries to call it) within small time period - ie. one hour. Most of them are cellphones (my line out is PRI) so it seems that the other end (telco) sends some strange signalling commands which ends the Dial command, but not the call.

By: Tilghman Lesher (tilghman) 2006-03-12 16:19:16.000-0600

This is not a bug.  You used DeadAGI, which is associated with a hungup channel, which is why Dial will return immediately (sensing a hangup).  If you want this associated with a live channel, please use AGI instead.

By: Mr. Zdeeck (mr_zdeeck) 2006-03-13 02:34:37.000-0600

I must oppose:

I use DeadAGI because I need to do something _before_ dial and _after_ channel is hung-up in one script. That's the whole point of DeadAGI (AFAIK) - do something even after the channel is hungup. Another thing is that it does the problem randomly - 95% of time it works as expected. This is a piece of code from the AGI script:

$fh = new IO::File "/tmp/agi.log","a";                                                  
print $fh "$starttime $uniq $cli -> $target_real\n";                                        
                                                                                               
$res = $AGI->exec('Dial',"Zap/g1/".$target_real."|60|L($maxlen)|o");                      
# Get dialstatus                                                                        
$dialstatus = $AGI->get_variable("DIALSTATUS");                                        
# Get answered time                                                                    
$answeredtime = $AGI->get_variable("ANSWEREDTIME")+0;                                  

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());              
$mon=$mon+1; $year=$year+1900;                                                          
$dialendtime = "$year-$mon-$mday $hour:$min:$sec";                                      
                                                                                               
print $fh "$dialendtime $uniq $cli -> ${target_real} $dialstatus $answeredtime\n";

This is correct log entry: (95%)
2006-3-13 9:5:51 1715110714 533312039 -> 777933325                                              
2006-3-13 9:6:9 1715110714 533312039 -> Zap/G1/777933325 ANSWER 5

This is wrong log entry:
2006-3-13 9:6:29 1718910725 533312123 -> 423534678                                    
2006-3-13 9:6:29 1718910725 533312123 -> Zap/G1/423534678  0

As you can see:
1) it exits immediately
2) there is no DIALSTATUS, which is of course nonsense - every Dial must return at least something, not an empty string
3) sometimes it happens that Dial exits BUT the call is actually done with real talk time - so I'm billed by telco but the guy is not billed by me :)

By: Tilghman Lesher (tilghman) 2006-03-13 07:38:34.000-0600

No, you must use two DIFFERENT agi scripts:  one for while the call is active and one for after the call is hungup, and you must call them at different times (DeadAGI in the h extension handler).