现在的位置: 首页 > 综合 > 正文

asterisk 使用Queue 的模式实现分机hunting 模式

2014年01月26日 ⁄ 综合 ⁄ 共 4471字 ⁄ 字号 评论关闭

        在asterisk 中,直线进入系统后,如果希望要多部分机轮流接听电话,如1001分机不通,再呼1002.

利用到的应用:

dailplan:

 extensions.conf

 

exten => _X., 1,Set(DYNAMIC_FEATURES=onhold#offhold)
exten => _X., n, macro(record-mcd)
exten => _X., n, Playback(silence/1)
exten => _X., n, ChanIsAvail(SIP/1001|s)
exten => _X., n, set(stat1001a=${AVAILSTATUS})
exten => _X., n, ChanIsAvail(SIP/1002|s)
exten => _X., n, set(stat1002a=${AVAILSTATUS})
exten => _X., n, ExecIf($["${stat1001a}" = "0"]|UnpauseQueueMember|q-a|SIP/1001)
exten => _X.,n, ExecIf($["${stat1002a}" = "0"]|UnpauseQueueMember|q-a|SIP/1002)
exten => _X.,n, queue(q-a|tr|||30)
exten => _X.,n, Hangup

 

 queue.conf

 [q-a]

strategy=rrmemory
timeout=15
retry=1
wrapuptime=0
maxlen = 0
announce-frequency = 0
announce-holdtime = no
joinempty = no
leavewhenempty = yes
member => SIP/1001,1
member => SIP/1002,2
 

   

ChanIsAvail功能:

检查指定的通道是否可用。

Checks if any of the requested channels are available.

语法:

ChanIsAvail (Technology/resource[&Technology2/resource2...][|options])

可选项 (new in Asterisk v1.2?):

  s – 设置该选项表示通道如果在使用中,将被认真为不可用。

Consider the channel unavailable if the channel is in use at all (buggy with SIP, always returning 0?!)
  j – 如果没有通道可用,支持跳转到n+101

Support jumping to priority n+101 if no channel is available

 

如下的变量会被该命令设置:

${AVAILCHAN} – 可用通道的名称。the name of the available channel, if one exists

${AVAILORIGCHAN} - the canonical channel name that was used to create the channel

${AVAILSTATUS} – 可用通道的状态代码。the status code for the available channel (see "devicestate.c")

0 AST_DEVICE_UNKNOWN - "Unknown"; 通道有效但是未知状态。channel is valid, but unknown state.

1 AST_DEVICE_NOT_INUSE – 通道没有被使用"Not in use"

2 AST_DEVICE IN USE - "In use"; 通道正在被使用。channel is in use.

3 AST_DEVICE_BUSY - "Busy"; 通道忙.channel is busy.

4 AST_DEVICE_INVALID - "Invalid", not known to Asterisk.

5 AST_DEVICE_UNAVAILABLE - "Unavailable"; 通道不可用,没有被注册.channel is unavailable (not registred)

6 AST_DEVICE_RINGING - "Ringing";通道在响铃. ring, ring, ring.

 

描述:

当前ChanIsAvail仅仅对ZAP,IAX2,mISDN,SIP通道有效,对于MGCP通道没有用。如果指定的被检测通道没有可用的,将跳转到n+101(除非n+101不存在),如果有可用的通道,下一个优先级将是n+1,通道变量${AVAILCHAN}将设置为可用通道的名称。通道是按照给出的顺序被检查的,返回第一个被找到的可用的通道到${AVAILCHAN}.

注意ChanIsAvail()不仅返回可用通道的名称,同时附加了通道的会话ID。你很可能需要去掉这个 会话ID,下面的示例会有介绍。

  Currently, ChanIsAvail only works with ZAP, IAX2, mISDN and SIP channels. MGCP channels are not supported. If none of the requested channels are available the new priority will be n+101 (unless such a priority does not exist). If any of the requested channels are available, the next priority will be n+1, the channel variable ${AVAILCHAN} will be set to the name of the available channel. The channels are checked in the order listed, returning the first available channel in the list in ${AVAILCHAN}. Note that ChanIsAvail() returns not only the name of the channel in $AVAILCHAN, but also appends the channel's session ID. You will probably need to strip the session ID off, as illustrated in the example below.

SIP, IAX

ChanIsAvail不是用来告诉你通道是否忙,它主要用来告诉你是否可以呼叫该通道。

ChanIsAvail is not a solution to tell you conclusively whether the channel is busy or not, it is primarily to tell you whether it would be possible to send a call there. Whether that call would end up being accepted or not is entirely up to the peer that we send the call to, and they could easily reject the call even though they do not appear to be 'busy'.

所以如果你想知道SIP peer是否被注册, ChanIsAvail是比较好的选择。如果你想用它来限制同时呼入的电话,它也行不会使你满意。不过在asterisk 1.6版本中可以使用DEVICE_STATE来满足你的需求.

So: If you want to use ChanIsAvail to determine whether the SIP peer is known and registered, it will work fine. If you want to use it for limiting simultaneous calls to the peer, it will not work reliably for you.

为了判断Sip peers是否在线,你可以用sippeer(‘’name’:status)函数。ChanIsAvail貌似不会帮你判断一个sip peer在线或离线。示例如下

For telling if Sip peers are online or not, when you are using qualify, then you may wish to just use the SipPeer('name':status) function, and jump based on that. ChanIsAvail doesn't seem to tell you the difference between a Sip peer that's online, and one that's offline. Example snippet:

exten => s,n,Set(VOIPCHECK=0)       exten => s,n,Set(PEERCHECK1=myprovider-out)  ; SIP peer name as defined in sip.conf
 ; 确保SIP 分机属性 qualify=yes Make sure to have qualify=yes enabled for this SIP peer!

 exten => s,n,NoOp(-- ${PEERCHECK1} status: ${SIPPEER(${PEERCHECK1}:status)} --)
 exten => s,n,ExecIf($["${SIPPEER(${PEERCHECK1}:status):0:2}" = "OK"]|Set|VOIPCHECK=1)
 ; Now route and dial any way you like based on the value of VOIPCHECK

示例2

先判断线路2是否可用,不可用则继续检查线路1.See if line 2 is available. If not, try line 1.
exten => s,1,ChanIsAvail(Zap/2&Zap/1)
; ${AVAILCHAN}里面的值应该是Zap/2-1 ${AVAILCHAN} might now contain the value: Zap/2-1
我们需要把会话IDAVAILCHAN 中去掉并且在Zap/2上拨打'12345678'

; We need to strip off the session ID and Dial '12345678' at Zap/2
exten => s,2,Dial(${CUT(AVAILCHAN||1)}/12345678)
exten => s,3,Hangup
如果两条线路都不可用,播放一段信息音。If neither line 2 nor line 1 is available, play a message
exten => s,102,Playback(all-circuits-busy-now)
exten => s,103,Hangup

抱歉!评论已关闭.