Brute your trunks, dial out

A small snippet of dialplan how to dial if some trunk is not reachable.

Imagine, we have two SIP-trunks to dial out – [trunk1] and [trunk2]. You have to set ‘qualify=yes’ for both, otherwise this method will not work.
We’ll use the SIPPEER function with the ‘status’ argument:

; Func SIPPEER
exten => 401040,NoOp
    same => n,NoOp( [trunk1] SIPPEER info: ${SIPPEER(trunk1,status)})
    same => n,NoOp( ;===================================== )
    same => n,NoOp( [trunk2] SIPPEER info: ${SIPPEER(trunk2,status)})
    same => n,NoOp( ;===================================== )
    same => n,GotoIf($[${SIPPEER(trunk1,status)}= "OK"]?t1dial:t2)
    same => n(t1dial),Dial(SIP/trunk1/${EXTEN},5)
    same => n,Hangup
    same => n(t2),NoOp( [trunk1] is UNREACHABLE, trying [trunk2] in 1 second ... )
    same => n,Wait(1)
    same => n,GotoIf($[${SIPPEER(trunk2,status)}= "OK"]?t2dial:hang)
    same => n(t2dial),Dial(SIP/trunk2/${EXTEN},5)
    same => n,Hangup
    same => n(hang),Playback(have-a-rest)
    same => n,Hangup

Tags: , ,

Comments are closed.