[asterisk-users] FW: re: Asterisk Outbound with Failover, alarm notification, dial status and hangupcause capturing to CDR from Dialplan

Neeraj Chand Neeraj.Chand at ocis.com.au
Sun Jun 28 20:45:10 CDT 2009


Managed to implement this on asterisk v1.4.24.1, 

Also, Hangupcause updating to user field. 

However, this only works on the edge of my voice network (demarcation
point) 

It does not work on my internal routing boxes as I use IAX to route
between remote sites.

I was thinking of using some sort of SIP variables to transport these
results over the IAX trunk.. 

Any bright ideas folks???

[outbound]

exten => _XXX.,n(dial),gotoif($[${loadbalance} = 1 ]?balance) ;at dial
decide if we want to load balance

exten => _XXX.,n,goto(50)       ;if no balance then outbound call
initiated with failover

exten => _XXX.,n(balance),NoOp("Load Balancing Active")
;NoOp - display Load balancing status

exten => _XXX.,n,Set(counter1=${DB(data/counter)})
;retrieve counter value from astdb

exten => _XXX.,n,NoOp(${counter1})
;display value of counter

exten => _XXX.,n,Set(counter=${MATH(${counter1}+1,int)})           ;
increment counter

exten => _XXX.,n,Set(DB(data/counter)=${counter})
;write incremented value back to asterisk db

exten => _XXX.,n,Set(result=${MATH(${counter}%2)})
;check for Odd/ Even using modulus of ${counter} via MATH function

exten => _XXX.,n,NoOp(${result})
;Display output - 0 for even and 1 for odd

exten => _XXX.,n,GotoIf($[${result} > 0]?50:100)    ;Odd calls route to
outbound-1, even calls to outbound-2

exten => _XXX.,n(balance),NoOp("Load Balancing Active")         ;NoOp -
display Load balancing status

exten => _XXX.,n,Set(counter1=${DB(data/counter)})
;retrieve counter value from astdb

exten => _XXX.,n,NoOp(${counter1})                              ;display
value of counter

exten => _XXX.,n,Set(counter=${MATH(${counter1}+1,int)})        ;
increment counter

exten => _XXX.,n,Set(DB(data/counter)=${counter})               ;write
incremented value back to asterisk db

exten => _XXX.,n,Set(result=${MATH(${counter}%2)})              ;check
for Odd/ Even using modulus of ${counter} via MATH function

exten => _XXX.,n,NoOp(${result})
;Display output - 0 for even and 1 for odd

exten => _XXX.,n,GotoIf($[${result} > 0]?50:100)        ;Odd calls route
to outbound-1, even calls to outbound-2

 

exten => _XXX.,50,gotoif($[${dialout} > 0 ]?firstfail)

exten => _XXX.,n,Set(dialout=${MATH(${dialout}+2)})

exten => _XXX.,n,NoOp(${dialout})

exten => _XXX.,n,dial(${route2}/${EXTEN}@${context2})

exten => _XXX.,n,goto(after-dial)

exten => _XXX.,n(firstfail),set(try=${MATH(${dialout}+2)})

exten => _XXX.,n,dial(${route2}/${EXTEN}@${context2})
;attempt to dial out via route 2

exten => _XXX.,n,goto(after-dial)    ;after attempting to dial, go to
after-dial

 

 

exten => _XXX.,100,gotoif($[${dialout} > 0 ]?secondfail)

exten => _XXX.,n,Set(dialout=${MATH(${dialout}+1))

exten => _XXX.,n,NoOp(${dialout})

exten => _XXX.,n,dial(${route1}/${EXTEN}@${context1})
;attempt dial out via route 1

exten => _XXX.,n,goto(after-dial)
;after attempting to dial, go to after-dial

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

exten => _XXX.,n,dial(${route1}/${EXTEN}@${context1})
;attempt to dial out via route 1

exten => _XXX.,n,goto(after-dial)
;after attempting to dial, go to after-dial

 

exten => _XXX.,n(after-dial),Set(CDR(accountcode)=${DIALSTATUS})
;first step - add ${DIALSTATUS} to CDR in accountcode field

exten => _XXX.,n,goto(${DIALSTATUS})
;go to dial-status received from attempt

 

exten => _XXX.,n(BUSY),,goto(set_cause)
;if Busy, go to set_cause

exten => _XXX.,n(NOANSWER),goto(set_cause)
;if No answer, go to set_cause

exten => _XXX.,n(CANCEL),goto(set_cause)
;if Cancel, go to set_cause

exten => _XXX.,n(NOANSWER),goto(set_cause)
;if No Answer, go to set_cause

 

 

exten => _XXX.,n(CHANUNAVAIL),gotoif($[${try} = 2 ]?emergency-notify)
;If CHANUNAVAIL,check if both routes are down. If yes, send emergency
notification

exten => _XXX.,n,gotoif($[${first-dial} = ${route1} ]?notify-1)
;If this was first attempt from route 1, go to notification for route 1
down

exten => _XXX.,n,goto(notify-2)
;else go to notification for route 2

 

exten => _XXX.,n(set_cause),hangup()
;at set_cause, firstly hang up channel (if not done already)            

exten => _XXX.,n,goto(CDRfield)
;go to CDR field mapping section

 

exten => _XXX.,n(CDRfield),Set(CDR(userfield)=${HANGUPCAUSE})
;set Hangupcause to user field in CDR

 

exten => _XXX.,n(notify-1),System(echo "Call redirect detected on
'${route1}'"  | mail -s "Calls Fail Over" Neeraj.chand at ocis.com.au)
;send notification route 1 down

exten => _XXX.,n,goto(100)          ;attempt dial via route 2

 

exten => _XXX.,n(notify-2),System(echo "Call redirect detected on
'${route2}'"  | mail -s "Calls Fail Over" Neeraj.chand at ocis.com.au)
;send notification route 2 down

exten => _XXX.,n,goto(50)          ;attempt dial via route 1

 

exten => _XXX.,n(emergency-notify),System(echo "Call redirect detected
on BOTH Routes!!!!!"  | mail -s "Calls Fail Over"
Neeraj.chand at ocis.com.au) ;send critical - both routes

exten => _XXX.,n,goto(set_cause)           ;attempt to hangup and set
cause code.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20090629/3fcbc25f/attachment.htm 


More information about the asterisk-users mailing list