[Asterisk-Users] How to get Referred-By header

Eric "ManxPower" Wieling
Sun, 13 Nov 2005 18:40:34 -0000

John E. Elkin wrote:
> Im still tring to figure out how to route my calls out of a secondary
> termination provider when my primary fails.  I have no idea how to even
> attempt this.. It seems like it would be something simple...

Something like this, which is a basic idea, not a totally working script.

[macro-dial-result]
;
; Handle Disconnect Cause Codes
;
exten => s,1,NoOp(HANGUPCAUSE is ${HANGUPCAUSE} and DIALSTATUS is
${DIALSTATUS})
;exten => s,2,AbsoluteTimeout(120)
exten => s,2,Noop
exten => s,3,GotoIf($[${HANGUPCAUSE} = 0]?s,5)
exten => s,4,Goto(cause-${HANGUPCAUSE},1)
exten => s,5,GotoIf($[${DIALSTATUS} = NOANSWER]?cause-16,1)
exten => s,6,GotoIf($[${DIALSTATUS} = BUSY]?cause-17,1)
exten => s,7,GotoIf($[${DIALSTATUS} = CHANUNAVAIL]?cause-3,1)
exten => s,8,GotoIf($[${DIALSTATUS} = ANSWER]?cause-16,1)
exten => s,9,Goto(cause-0,1)

exten => cause-0,1,NoOp(AST_CAUSE_NOTDEFINED)
exten => cause-0,2,GotoIf($["${SAVED_EXTEN}" !=
""]?cause-0,4)
exten => cause-0,3,SetVar(SAVED_EXTEN=${MACRO_EXTEN})
exten => cause-0,4,GotoIf($["${SAVED_ARG1}" !=
""]?cause-0,6)
exten => cause-0,5,SetVar(SAVED_ARG1=${ARG1})
exten => cause-0,6,GotoIf($["${ARG1}" = ""]?cause-0,11)
exten => cause-0,7,System(/bin/echo "AST_CAUSE_NOTDEFINED received when
dialing ${SAVED_EXTEN} trying again using ${SAVED_ARG1}." | /bin/mail -s
"${SITE} PBX ERROR" pbxadmin-pager)
;exten => cause-0,7,Noop
exten => cause-0,8,SetVar(ARG1=)
exten => cause-0,9,Dial(${SAVED_ARG1})
exten => cause-0,10,Macro(dial-result)
exten => cause-0,11,System(/bin/echo "AST_CAUSE_NOTDEFINED received when
dialing ${SAVED_ARG1} giving up." | /bin/mail -s "${SITE} PBX
ERROR"
pbxadmin-pager)
;exten => cause-0,11,Playback(all-circuits-busy-now)
exten => cause-0,12,Zapateller(answer)
;exten => cause-0,12,Playback(pls-try-call-later)
exten => cause-0,13,Playback(an-error-has-occured)
;exten => cause-0,13,Hangup
exten => cause-0,14,Playback(pls-try-call-later)
exten => cause-0,15,Wait(3)
exten => cause-0,16,Zapateller(answer)
exten => cause-0,17,Playback(an-error-has-occured)
exten => cause-0,18,Playback(pls-try-call-later)
exten => cause-0,19,Wait(3)
exten => cause-0,20,Congestion

exten => cause-1,1,NoOp(AST_CAUSE_UNALLOCATED)
exten => cause-1,2,Macro(number-disconnected,${MACRO_EXTEN})

exten => cause-3,1,NoOp(Channel unavailable)
;exten => cause-3,2,System(/root/aimd/sendIM.pl PBXAdmin "CHANUNAVAIL
when Dialing ${SAVED_ARG1}")
exten => cause-3,2,Playback(all-circuits-busy-now)
exten => cause-3,3,Playback(pls-try-call-later)
exten => cause-3,4,Hangup
;exten => cause-3,2,Playback(pls-wait-connect-call)
;exten => cause-3,3,Dial(${ARG1})
;exten => cause-3,4,Macro(dial-result)

exten => cause-16,1,NoOp(AST_CAUSE_NORMAL_CLEARING)
exten => cause-16,2,Hangup

exten => cause-17,1,NoOp(AST_CAUSE_USER_BUSY)
exten => cause-17,2,Busy

exten => cause-31,1,Goto(cause-1,1)
exten => _cause-.,1,NoOp(AST_UNKNOWN_ERROR)
exten => _cause-.,2,Dial(IAX2/${VNEA_AUTH}@172.17.2.7/2120,15)
exten => _cause-.,3,SetCallerID(PBX Error <${MACRO_EXTEN}>)
exten => _cause-.,4,Hangup