Return a 503 when agi is unavailable

Hello,

My telephony provider will failover to our backup server as follows:


Calls will be directed to the backup URI when the server linked to the primary URI is considered unavailable. This may happen if:

  • The primary URI responds with a 503 error response
  • The primary URI does not respond with a 100 <TRYING> to Voxbones <INVITE> within 5 seconds.

We had a case where our AGI server failed, but calls were not being redirected. In the Asterisk logs we could see:

[Dec 29 03:29:53] WARNING[80384][C-00001a3c] res_agi.c: Couldn’t connect to any host. FastAGI failed.
[Dec 29 03:29:55] WARNING[80385][C-00001a3d] res_agi.c: Connecting to ‘127.0.0.1:4573’ failed for url ‘agi://127.0.0.1/line.agi’: Connection refused

The problem with the AGI we have fixed, but I’d like to ensure that failover will occur correctly. The dialplan is simply the below:

exten => _140X,1,Agi(agi://127.0.0.1/line.agi)

If that can’t be reached, should it fail with a 503 error response ?

If not, is there anyway with the Dialplan that I can enforce it to ?

Thanks for your help,
Regards,
Mark

Subject to testing, recognize the failure and have Asterisk issue Hangup(41), from the subsequent dialplan code.

Hi,

Thank you for your reply.

exten => _140X,1,Agi(agi://127.0.0.1/line.agi)
exten => _140X,n,Hangup(42)

The above does correctly allow it to failover if the AGI is down. I couldn’t though find out how to “recognise the failure”. ${DIALSTATUS } always seems to be empty to me ?

I could use the above, but I hangup in the agi script, so I might end up Hanging up twice (the second time with a 503) - so I’d prefer to only Hangup(42) specifically where the Agi had an issue.

Regards,
Mark

AGI doesn’t set DIALSTATUS. See https://wiki.asterisk.org/wiki/display/AST/Application_AGI

Thank you - this seems to work:

exten => _140X,1,Agi(agi://127.0.0.1/line.agi)
exten => _140X,n,GotoIf(["{AGISTATUS}" = “FAILURE”]?100)
exten => _140X,100,Verbose(1,AGISTATUS=${AGISTATUS})
exten => _140X,101,Hangup(42)