Lee Jenkins
2007-May-17 09:59 UTC
[asterisk-users] FastAGI hangs up channel if server is not available
Hi all, Running 1.2.14 When I call a FastAGI script such as this script for an incoming call: [calldirect] exten=>s,1,Answer() exten=>s,2,AGI(agi://192.168.1.175/calldirect?check&${CALLERID(num)}) exten=>s,3,Goto(check_time,s,1) and the FastAGI server is not running (Asterisk gets "connection refused" TCP error), Asterisk just terminates the call like so: May 17 12:58:00 WARNING[10154]: res_agi.c:210 launch_netscript: Connect to 'agi://192.168.1.175/calldirect?check&NNNNNNNNNN' failed: Connection refused == Spawn extension (remove_caller, s, 2) exited non-zero on 'SIP/datatrak-0978b670' The text of the relevant wiki article (http://www.voip-info.org/wiki-Asterisk+FastAGI) infers that execution should roll through to the next executable line in the context where it was called in the case of an error in executing the FastAGI: "Asterisk 1.2 Under Asterisk 1.2, if a request to a FastAGI service failed for any reason, there was no way to determine this from the dialplan. The recommended action is to set a channel variable before calling the FastAGI, setting that variable to a known value within the FastAGI, and then checking that variable once the AGI has returned..." Is there a setting/var that I am missing? Thanks for taking the time. -- Warm Regards, Lee
Tony Mountifield
2007-May-17 11:45 UTC
[asterisk-users] Re: FastAGI hangs up channel if server is not available
In article <464C8977.4020501@datatrakpos.com>, Lee Jenkins <lee@datatrakpos.com> wrote:> > Running 1.2.14 > > When I call a FastAGI script such as this script for an incoming call: > > [calldirect] > exten=>s,1,Answer() > exten=>s,2,AGI(agi://192.168.1.175/calldirect?check&${CALLERID(num)}) > exten=>s,3,Goto(check_time,s,1) > > and the FastAGI server is not running (Asterisk gets "connection > refused" TCP error), Asterisk just terminates the call like so: > > May 17 12:58:00 WARNING[10154]: res_agi.c:210 launch_netscript: Connect > to 'agi://192.168.1.175/calldirect?check&NNNNNNNNNN' failed: Connection > refused > == Spawn extension (remove_caller, s, 2) exited non-zero on > 'SIP/datatrak-0978b670' > > The text of the relevant wiki article > (http://www.voip-info.org/wiki-Asterisk+FastAGI) infers that execution > should roll through to the next executable line in the context where it > was called in the case of an error in executing the FastAGI: > > "Asterisk 1.2 > Under Asterisk 1.2, if a request to a FastAGI service failed for any > reason, there was no way to determine this from the dialplan. The > recommended action is to set a channel variable before calling the > FastAGI, setting that variable to a known value within the FastAGI, and > then checking that variable once the AGI has returned..." > > Is there a setting/var that I am missing?No, the information is wrong. You need to make a small mod to res/res_agi.c in order to trap this case. Look for the second occurrence of LOCAL_USER_REMOVE, and add the lines just before it as show by this patch extract (ignore the line numbers; I have other mods too): @@ -2065,6 +2106,9 @@ close(fds[1]); if (efd > -1) close(efd); + } else { + pbx_builtin_setvar_helper(chan, "AGISTATUS", "NOTFOUND"); + res = 0; } LOCAL_USER_REMOVE(u); return res; With this change, a refused connection will not hang up the channel, but instead will set the AGISTATUS variable to "NOTFOUND". Cheers Tony -- Tony Mountifield Work: tony@softins.co.uk - http://www.softins.co.uk Play: tony@mountifield.org - http://tony.mountifield.org
Lee Jenkins
2007-May-17 11:57 UTC
[asterisk-users] FastAGI hangs up channel if server is not available
Lee Jenkins wrote:> > Hi all, > > Running 1.2.14 > > When I call a FastAGI script such as this script for an incoming call: > > [calldirect] > exten=>s,1,Answer() > exten=>s,2,AGI(agi://192.168.1.175/calldirect?check&${CALLERID(num)}) > exten=>s,3,Goto(check_time,s,1) > > and the FastAGI server is not running (Asterisk gets "connection > refused" TCP error), Asterisk just terminates the call like so: > > May 17 12:58:00 WARNING[10154]: res_agi.c:210 launch_netscript: Connect > to 'agi://192.168.1.175/calldirect?check&NNNNNNNNNN' failed: Connection > refused > == Spawn extension (remove_caller, s, 2) exited non-zero on > 'SIP/datatrak-0978b670' > > The text of the relevant wiki article > (http://www.voip-info.org/wiki-Asterisk+FastAGI) infers that execution > should roll through to the next executable line in the context where it > was called in the case of an error in executing the FastAGI: > > "Asterisk 1.2 > Under Asterisk 1.2, if a request to a FastAGI service failed for any > reason, there was no way to determine this from the dialplan. The > recommended action is to set a channel variable before calling the > FastAGI, setting that variable to a known value within the FastAGI, and > then checking that variable once the AGI has returned..." > >Apparently, this is a standing issue with FastAGI (at least ins 1.2 branch). I found a work around using the "h". Bread Crumbs follow: Work around using "h" extension: http://lists.digium.com/pipermail/asterisk-users/2006-August/161459.html Still a PIA to have to include pseudo exception handling each time a FastAGI is referenced. There is also a bug report from '05 that I came across: http://bugs.digium.com/view.php?id=4029 But it looks like it was stalled. -- Warm Regards, Lee
JR Richardson
2007-May-17 15:11 UTC
[asterisk-users] Re: FastAGI hangs up channel if server is not available
> Running 1.2.14 > > When I call a FastAGI script such as this script for an incoming call: > > [calldirect] > exten=>s,1,Answer() > exten=>s,2,AGI(agi://192.168.1.175/calldirect?check&${CALLERID(num)}) > exten=>s,3,Goto(check_time,s,1) > > and the FastAGI server is not running (Asterisk gets "connection > refused" TCP error), Asterisk just terminates the call like so: > > May 17 12:58:00 WARNING[10154]: res_agi.c:210 launch_netscript: Connect > to 'agi://192.168.1.175/calldirect?check&NNNNNNNNNN' failed: Connection > refused > == Spawn extension (remove_caller, s, 2) exited non-zero on > 'SIP/datatrak-0978b670' > > The text of the relevant wiki article > (http://www.voip-info.org/wiki-Asterisk+FastAGI) infers that execution > should roll through to the next executable line in the context where it > was called in the case of an error in executing the FastAGI: > > "Asterisk 1.2 > Under Asterisk 1.2, if a request to a FastAGI service failed for any > reason, there was no way to determine this from the dialplan. The > recommended action is to set a channel variable before calling the > FastAGI, setting that variable to a known value within the FastAGI, and > then checking that variable once the AGI has returned..."I had a similar issue, we resolved it by calling a local agi script on the local pbx that in turn calls the fast agi on the remote host. The local agi was written in perl, which, if the remote agi does not respond, then the call is given back to the dialplan to the next priority. So for your example, do something like this: [calldirect] exten=>s,1,Answer() exten=>s,2,AGI(test.agi&${CALLERID(num)}) exten=>s,3,Goto(check_time,s,1) Perl AGI File 'test.agi' in the local asterisk agi directory: ---------------------------------------start of file----------------------------------------------------- #!/usr/bin/perl ############################################################# ##################### Modules to Use ############### ############################################################# use Asterisk::AGI; $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); # Set variables according to supplied arquments $number = $ARGV[0]; $AGI->exec("agi","agi://192.168.1.175/calldirect?check&number=$number"); ----------------------------------------end of file------------------------------------------- Also you need the asterisk perl agi modules at http://asterisk.gnuinter.net/ Good luck. JR -- JR Richardson Engineering for the Masses
Lee Jenkins
2007-May-17 17:59 UTC
[asterisk-users] Re: FastAGI hangs up channel if server is not available
JR Richardson wrote:>> Running 1.2.14 >> >> When I call a FastAGI script such as this script for an incoming call: >> >> [calldirect] >> exten=>s,1,Answer() >> exten=>s,2,AGI(agi://192.168.1.175/calldirect?check&${CALLERID(num)}) >> exten=>s,3,Goto(check_time,s,1) >>Thanks for the hint. I thought about doing this but then I would have to have another executable process just to shell out to the FastAGI which is what I use by choice to reduce load on the server ;) -- Warm Regards, Lee