[Asterisk-Users] if outgoing call fails with provider 1 then auto
try provider 2
Andrew Kohlsmith
akohlsmith-asterisk at benshaw.com
Fri Apr 22 20:01:52 MST 2005
On April 22, 2005 10:38 pm, Thomas Miller wrote:
> When someone teminates a call with my softphone to my
> asterisk server i want asterisk to try provider 1
> first and if the call does not go through because the
> provider is having problems then it will try provider
> 2 gracefully.
This is a simple dialplan macro and context that will try to call through
nufone and, failing that, dial through my PRI. It takes two arguments.
${ARG1} = number to call, no leading 1 or 0.
${ARG2} = optional account code for billing.
It needs to be expanded upon. I plan on adding a little AstDB lookup to force
an immediate failover and some other undisclosed magic to periodically test
the connection through nufone's echo username. Also with a proper rate
engine you can dynamically determine the order of VOIP providers to try.
It's really not too difficult once you understand contexts, context ordering
and have a little experience under your belt.
All my "final path" macros work this way and have trivial little dialplan
contexts to route the call to the macro. The only gotcha is in
${DIALSTATUS}=CONGESTION -- If Dial() can't reach an IAX client it will
return CONGESTION, and my argument is that CONGESTION should *only* be
returned by Dial() if the far end SAYS it's congested. The inability to
reach a destination should return CHANUNAVAIL. I will post a patch to fix
this one of these days.
Of course to "chain" providers, you simply Macro(nextprovider-dial,${ARG1},
${ARG2}) and so on and so on; I only use Nufone and fall through to the PRI,
so that's what you see here. If the PRI fails there are bigger
troubles. :-)
The dialplan snippet that follows works too well; I need to add some logging
and alerting because I've had calls fail through and dial out my PRI (at my
telco's full LD rate) for a full week before I realized that my nufone
settings had changed; the dialplan just seamlessly routed the calls to the
failover, which is *exactly* what it should have done. :-)
In your dialplan proper you will have your context that users can dial long
distance (and international) through. You simply include => nufone to have
it attempt to dial nufone in the right order that you want it to be attempted
in.
Example:
[trunk-ld]
exten => _NXXNXXXXXX,1,Macro(pri-dial,${EXTEN})
exten => _1NXXNXXXXXX,1,Macro(pri-dial,${EXTEN:1})
[trunk-int]
exten => _011.,1,Macro(pri-dial,${EXTEN})
exten => _1011.,1,Macro(pri-dial,${EXTEN:1})
[nufone]
exten => _NXXNXXXXXX,1,Macro(nufone-dial,${EXTEN})
exten => _1NXXNXXXXXX,1,Macro(nufone-dial,${EXTEN:1})
[nufone-int]
exten => _011.,1,Macro(nufone-dial,${EXTEN})
exten => _1011.,1,Macro(nufone-dial,${EXTEN:1})
; longdistance dialplan. Order is top-down and implies cheaper paths above
more expensive ones.
[longdistance]
include => local
include => voctel
include => nufone
include => trunk-ld
[international]
include => longdistance
include => nufone-int
include => trunk-int
[trusted]
include => nine11
include => international
[macro-nufone-dial]
exten => s,1,GotoIf($[$ACCOUNTCODE != ""],s,gotac)
exten => s,n,SetVar(ACCOUNTCODE=${ARG2})
exten => s,n,GotoIf($[{$ARG2} != ""],s,gotac)
exten => s,n,SetVar(ACCOUNTCODE=benshaw)
exten => s,n(gotac),SetAccount(${ACCOUNTCODE})
exten => s,n,GotoIf($[${LEN(${ARG1})} = 10]?s,add1)
exten => s,n,Dial(IAX2/username at nufone-1/${ARG1},,g)
exten => s,n(postdial),NoOp(NUFONE: HANGUPCAUSE is ${HANGUPCAUSE} and
DIALSTATUS is ${DIALSTATUS})
exten => s,n,Goto(dial-${DIALSTATUS},1)
exten => s,n(add1),Dial(IAX2/username at nufone-1/1${ARG1},,g)
exten => s,n,Goto(postdial,1)
exten => dial-CANCEL,1,Hangup
exten => dial-ANSWER,1,Hangup
exten => dial-NOANSWER,1,Hangup
exten => dial-BUSY,1,Busy
exten => dial-CONGESTION,1,Macro(pri-dial,${ARG1},${ARG2})
exten => dial-CHANUNAVAIL,1,Macro(pri-dial,${ARG1},${ARG2})
-A.
More information about the asterisk-users
mailing list