<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
h1
        {mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:24.0pt;
        font-family:"Times New Roman";
        font-weight:bold;}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman";}
pre
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:Arial;
        color:windowtext;}
span.EmailStyle23
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:black'>Managed to implement this on asterisk
v1.4.24.1, <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:black'>Also, Hangupcause updating to user field.
<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:black'>However, this only works on the edge of
my voice network (demarcation point) <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:black'>It does not work on my internal routing
boxes as I use IAX to route between remote sites.<o:p></o:p></span></font></p>
<p class=MsoNormal><b><font size=2 color=black face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:black;font-weight:bold'>I was
thinking of using some sort of SIP variables to transport these results over
the IAX trunk.. <o:p></o:p></span></font></b></p>
<p class=MsoNormal><b><font size=2 color=black face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:black;font-weight:bold'>Any
bright ideas folks???<o:p></o:p></span></font></b></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>[outbound]</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(dial),gotoif($[${loadbalance} = 1 ]?balance) ;at dial decide if we want
to load balance</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(50) ;if no balance then
outbound call initiated with failover</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(balance),NoOp("Load Balancing
Active")
;NoOp - display Load balancing status</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(counter1=${DB(data/counter)})
;retrieve counter value from astdb</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,NoOp(${counter1})
;display value of counter</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(counter=${MATH(${counter1}+1,int)})
; increment counter</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(DB(data/counter)=${counter})
;write incremented value back to asterisk db</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(result=${MATH(${counter}%2)})
;check for Odd/ Even using modulus of ${counter} via MATH function</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,NoOp(${result})
;Display output - 0 for even and 1 for odd</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten => _XXX.,n,GotoIf($[${result}
> 0]?50:100) ;Odd calls route to outbound-1, even calls to
outbound-2</span></font><font color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(balance),NoOp("Load Balancing
Active") ;NoOp - display
Load balancing status</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(counter1=${DB(data/counter)})
;retrieve counter value from astdb</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,NoOp(${counter1})
;display
value of counter</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(counter=${MATH(${counter1}+1,int)})
; increment counter</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten => _XXX.,n,Set(DB(data/counter)=${counter})
;write incremented value back to asterisk db</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(result=${MATH(${counter}%2)})
;check for Odd/ Even using modulus of ${counter} via MATH function</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,NoOp(${result})
;Display output - 0 for even and 1 for odd</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,GotoIf($[${result} >
0]?50:100) ;Odd calls route to
outbound-1, even calls to outbound-2</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,50,gotoif($[${dialout} > 0 ]?firstfail)</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(dialout=${MATH(${dialout}+2)})</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,NoOp(${dialout})</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,dial(${route2}/${EXTEN}@${context2})</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(after-dial)</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(firstfail),set(try=${MATH(${dialout}+2)})</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,dial(${route2}/${EXTEN}@${context2})
;attempt to dial out via route 2</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(after-dial) ;after attempting to dial, go to
after-dial</span></font><font color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,100,gotoif($[${dialout} > 0 ]?secondfail)</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,Set(dialout=${MATH(${dialout}+1))</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,NoOp(${dialout})</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,dial(${route1}/${EXTEN}@${context1})
;attempt dial out via route 1</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(after-dial)
;after attempting to dial, go to after-dial</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(secondfail),set(try=${MATH(${dialout}+2})
;If call has been dialled by other route and is failing over, set variable try
= 2</span></font><font color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,dial(${route1}/${EXTEN}@${context1})
;attempt to dial out via route 1</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(after-dial)
;after attempting to dial, go to after-dial</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:black'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(after-dial),Set(CDR(accountcode)=${DIALSTATUS})
;first step - add ${DIALSTATUS} to CDR in accountcode field</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(${DIALSTATUS})
;go to dial-status received from attempt</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(BUSY),,goto(set_cause)
;if Busy, go to set_cause</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(NOANSWER),goto(set_cause)
;if No answer, go to set_cause</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(CANCEL),goto(set_cause)
;if Cancel, go to set_cause</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(NOANSWER),goto(set_cause)
;if No Answer, go to set_cause</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(CHANUNAVAIL),gotoif($[${try} = 2
]?emergency-notify) ;If CHANUNAVAIL,check
if both routes are down. If yes, send emergency notification</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,gotoif($[${first-dial} = ${route1}
]?notify-1)
;If this was first attempt from route 1, go to notification for route 1 down</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(notify-2)
;else go to notification for route 2</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(set_cause),hangup()
;at set_cause, firstly hang up channel (if not done
already) </span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten => _XXX.,n,goto(CDRfield)
;go to CDR field mapping section</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(CDRfield),Set(CDR(userfield)=${HANGUPCAUSE})
;set Hangupcause to user field in CDR</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(notify-1),System(echo "Call redirect detected on
'${route1}'" | mail -s "Calls Fail Over"
Neeraj.chand@ocis.com.au) ;send notification route 1 down</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(100)
;attempt dial via route 2</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(notify-2),System(echo "Call redirect detected on
'${route2}'" | mail -s "Calls Fail Over"
Neeraj.chand@ocis.com.au) ;send notification route 2 down</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(50) ;attempt
dial via route 1</span></font><font color=black><span lang=EN-AU
style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
lang=EN-AU style='font-size:12.0pt;color:black'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n(emergency-notify),System(echo "Call redirect detected on BOTH
Routes!!!!!" | mail -s "Calls Fail Over"
Neeraj.chand@ocis.com.au) ;send critical - both routes</span></font><font
color=black><span lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span lang=EN-AU
style='font-size:10.0pt;font-family:Arial;color:black'>exten =>
_XXX.,n,goto(set_cause)
;attempt to hangup and set cause code.</span></font><font color=black><span
lang=EN-AU style='color:black'><o:p></o:p></span></font></p>
</div>
</body>
</html>