Asterisk cmd ChanIsAvail
Created by: oej,Last modification on Fri 18 of Jul, 2008 [15:38 UTC] by JustRumours
Synopsis
Check if channel is availableDescription
ChanIsAvail (Technology/resource[&Technology2/resource2...][|options])Checks if any of the requested channels are available.
The following variables will be set by this application:
- ${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.
Options (new in Asterisk v1.2?):
s - Consider the channel unavailable if the channel is in use at allj - Support jumping to priority n+101 if no channel is available
Details
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.
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.
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.
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 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'.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.
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
; See if line 2 is available. If not, try line 1.
exten => s,1,ChanIsAvail(Zap/2&Zap/1)
; ${AVAILCHAN} might now contain the value: Zap/2-1
; 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^
User comments
SIP and ChanIsAvail (Dec 2005)
According to bug 4506 Chanisavail is not intended to detect if a phone is in use or not at all, it's only intended to check if asterisk could send the call there.I tried using call-limit and Chanisavail, but it's broken in SIP. inuse gets applied only to peers, and when it gets an incomming call that is not answered it gets decremented and doesnt stay the same, which is a bug.
You should consider using groups instead.
See also
- hint: How to use SIP SUBSCRIBE/NOTIFY to inform about device state
- Asterisk cmd Page: Includes an example using ChanIsAvail
- Asterisk variables
- Asterisk func Cut
- Asterisk func sippeer: You may wish to just check a peer's status, instead of using ChanIsAvail
- Asterisk variable DIALSTATUS: Can be used as an alternative to ChanIsAvail()
- Asterisk func GROUP: Count channels (to check for availability or similar purposes)
Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ
Comments
333ChanIsAvail only shows the PEER side
333
333AVAILSTATUS values
static const char *devstatestring= {
/* 0 AST_DEVICE_UNKNOWN */ "Unknown", /* Valid, but unknown state */
/* 1 AST_DEVICE_NOT_INUSE */ "Not in use", /* Not used */
/* 2 AST_DEVICE IN USE */ "In use", /* In use */
/* 3 AST_DEVICE_BUSY */ "Busy", /* Busy */
/* 4 AST_DEVICE_INVALID */ "Invalid", /* Invalid - not known to Asterisk */
/* 5 AST_DEVICE_UNAVAILABLE */ "Unavailable", /* Unavailable (not registred) */
/* 6 AST_DEVICE_RINGING */ "Ringing" /* Ring, ring, ring */
};
333Is ChanIsAvail broken ?
Has anyone else seen this and maybe beaten it ??? is there another method folks are using to determine which channel is available ???
thanks
GHendershot