Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two voip providers, one free an the other paid. The free provider only allows local calls to certain area codes, so I need to fall back to the the paid provider if a call fails. At the moment, I have the following context in my extensions.conf file:

[globals]
; freephoneline.ca
PRIMARY_PROVIDER=fpl
; voip.ms
SECONDARY_PROVIDER=voipms

[local]
exten => _NXXNXXXXXX,1,Set(CALLERID(name)=${OUTGOING_NAME})
exten => _NXXNXXXXXX,n,Dial(SIP/${EXTEN}@${PRIMARY_PROVIDER})
exten => _NXXNXXXXXX,n,Set(CALLERID(num)=${OUTGOING_NUMBER})
exten => _NXXNXXXXXX,n,Dial(SIP/1${EXTEN}@${SECONDARY_PROVIDER})
exten => _NXXNXXXXXX,n,Hangup()

I checked the logs and noticed that the free provider responds with NOANSWER if a call is not allowed (Even though it plays a message). What I want is to:

  1. Try calling the ${PRIMARY_PROVIDER} first.
  2. If NOANSWER is returned by provider (not that the callee did not answer), then call with ${SECONDARY_PROVIDER}

How can I modify my dial plan to get the desired results?

EDIT : The primary provider is freephoneline.ca, and I'm using asterisk v1.8.2.3-2

share|improve this question
1  
Including the VOIP server you are using and the version number in the body of your question would be helpful in answering. – Tim Brigham Jun 1 '12 at 13:09
up vote 2 down vote accepted
+50
[local]
exten => _NXXNXXXXXX,1,Set(CALLERID(name)=${OUTGOING_NAME})
exten => _NXXNXXXXXX,n,Set(CALLERID(num)=${OUTGOING_NUMBER})
exten => _NXXNXXXXXX,n,Set(dest=${EXTEN})
exten => _NXXNXXXXXX,n,Dial(SIP/${EXTEN}@${PRIMARY_PROVIDER},20,); 20 is how much to call,in seconds
exten => _NXXNXXXXXX,n,Goto(s-${DIALSTATUS},1)

exten => s-ANSWER,1,Hangup
exten => s-ANSWERED,1,Hangup
exten => s-NOANSWER,1,Goto(dialnext,1)
exten => s-CHANUNAVAIL,1,Goto(dialnext,1)
exten => s-BUSY,1,Busy
exten => s-FAIL,1,Goto(dialnext,1)
exten => s-CONGESTION,1,Goto(dialnext,1)

exten =>dialnext,1,Dial(SIP/1${dest}@${SECONDARY_PROVIDER})
exten =>dialnext,n,Hangup()
share|improve this answer
    
Thanks for the helpful info, but that did not solve the problem. – adaptive Jun 6 '12 at 20:15
1  
This answer is technically correct but you need to detect CHANUNAVAIL. voip-info.org/wiki/view/Asterisk+variable+DIALSTATUS – jfalcon Jun 7 '12 at 21:40
    
2jfalcon user say he need NOANSWER. 2adaptive: please show output of asterisk verbose log. – arheops Jun 9 '12 at 16:01
    
@arheops doesn't matter what he needs... it's what he gets back from the VSP. – jfalcon Jun 11 '12 at 5:51
    
I haven't tested CHANUNAVAIL yet, but your answer was helpful. – adaptive Jun 12 '12 at 18:52

Here is an example of how I do this with google voice and trunks. With my setup I had to make a way to limit gv to 1 channel, also setup a rotation so the first gv trunk is not always hammered since it is first. There is a lot more to this but for just displaying failover I thought this was more than enough:

exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = ""]?15:)


exten => _1NXXNXXXXXX,15,Set(goto=$[${PRIORITY} + 15])
exten => _1NXXNXXXXXX,n,Set(thetrunk=feliciesmaty)
exten => _1NXXNXXXXXX,n,GotoIf($[${${thetrunk}}  > 0]?${goto})
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=1)
exten => _1NXXNXXXXXX,n,Dial(Motif/feliciesmaty@gmail.com/${EXTEN}@voice.google.com,,r)
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=0)
exten => _1NXXNXXXXXX,n,Verbose(0, getting staus ${DIALSTATUS} );
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "SUCCESS"]?hangup:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "FAILED"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "NOANSWER"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CANCEL"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "HANGUP"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "UNKNOWN"]?${goto}:)



exten => _1NXXNXXXXXX,30,Set(goto=$[${PRIORITY} + 20])
exten => _1NXXNXXXXXX,n,Set(thetrunk=bettyrobertson169gmailcom)
exten => _1NXXNXXXXXX,n,GotoIf($[${${thetrunk}}  > 0]?${goto})
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=1)
exten => _1NXXNXXXXXX,n,Dial(Motif/bettyrobertson169gmailcom/${EXTEN}@voice.google.com,,r)
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=0)
exten => _1NXXNXXXXXX,n,Verbose(0, getting staus ${DIALSTATUS} );
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "SUCCESS"]?hangup:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "FAILED"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "NOANSWER"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CANCEL"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "HANGUP"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "UNKNOWN"]?${goto}:)




exten => _1NXXNXXXXXX,50,Set(goto=$[${PRIORITY} + 25])
exten => _1NXXNXXXXXX,n,Set(thetrunk=swigartjosephgmailcom)
exten => _1NXXNXXXXXX,n,GotoIf($[${${thetrunk}}  > 0]?${goto})
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=1)
exten => _1NXXNXXXXXX,n,Dial(Motif/swigartjosephgmailcom/${EXTEN}@voice.google.com,,r)
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=0)
exten => _1NXXNXXXXXX,n,Verbose(0, getting staus ${DIALSTATUS} );
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "SUCCESS"]?hangup:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "FAILED"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "NOANSWER"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CANCEL"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "HANGUP"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "UNKNOWN"]?${goto}:)



exten => _1NXXNXXXXXX,75,Set(goto=$[${PRIORITY} + 25])
exten => _1NXXNXXXXXX,n,Set(thetrunk=bettyrobertson169gmailcom)
exten => _1NXXNXXXXXX,n,GotoIf($[${${thetrunk}}  > 0]?${goto})
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=1)
exten => _1NXXNXXXXXX,n,Dial(Motif/bettyrobertson169gmailcom/${EXTEN}@voice.google.com,,r)
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=0)
exten => _1NXXNXXXXXX,n,Verbose(0, getting staus ${DIALSTATUS} );
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "SUCCESS"]?hangup:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "FAILED"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "NOANSWER"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CANCEL"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "HANGUP"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "UNKNOWN"]?${goto}:)



exten => _1NXXNXXXXXX,100,Set(goto=$[${PRIORITY} + 25])
exten => _1NXXNXXXXXX,n,Set(thetrunk=sandralanago)
exten => _1NXXNXXXXXX,n,GotoIf($[${${thetrunk}}  > 0]?${goto})
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=1)
exten => _1NXXNXXXXXX,n,Dial(Motif/sandralanago@gmail.com/${EXTEN}@voice.google.com,,r)
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=0)
exten => _1NXXNXXXXXX,n,Verbose(0, getting staus ${DIALSTATUS} );
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "SUCCESS"]?hangup:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "FAILED"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "NOANSWER"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CANCEL"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "HANGUP"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "UNKNOWN"]?${goto}:)



exten => _1NXXNXXXXXX,125,Set(goto=$[${PRIORITY} + 25])
exten => _1NXXNXXXXXX,n,Set(thetrunk=sofiadugal)
exten => _1NXXNXXXXXX,n,GotoIf($[${${thetrunk}}  > 0]?${goto})
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=1)
exten => _1NXXNXXXXXX,n,Dial(Motif/sofiadugal@gmail.com/${EXTEN}@voice.google.com,,r)
exten => _1NXXNXXXXXX,n,Set(GLOBAL(${thetrunk})=0)
exten => _1NXXNXXXXXX,n,Verbose(0, getting staus ${DIALSTATUS} );
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "SUCCESS"]?hangup:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "FAILED"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "NOANSWER"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CANCEL"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "HANGUP"]?${goto}:)
exten => _1NXXNXXXXXX,n,GotoIf($["${DIALSTATUS}" = "UNKNOWN"]?${goto}:)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.