login | register
Tue 09 of Feb, 2010 [20:45 UTC]

voip-info.org

History

Asterisk cmd ChanIsAvail

Created by: oej,Last modification on Wed 17 of Dec, 2008 [16:21 UTC] by dichis

Synopsis

Check if channel is available

Description

 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 all
  j - 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.

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 incoming call that is not answered it gets decremented and doesnt stay the same, which is a bug.
You should consider using groups instead

Limit incoming calls using DEVICE_STATE and Asterisk 1.6

To limit incoming simultaneous calls to the peer, try DEVICE_STATE.

See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ


Comments

Comments Filter
222

333ChanIsAvail only shows the PEER side

by awysocki, Thursday 12 of July, 2007 [03:48:49 UTC]
From what I'm understanding, ChanIsAvail only looks at the PEER side, If you make an outbound call (USER side) ChanIsAvail will not look at that inuse number and will say the channel is available. It only looks at the PEER side so only the incoming calls to your ip phone are look at
222

333

by Zion800, Monday 24 of July, 2006 [21:02:15 UTC]
What does ChanIsAvail do if option j is not used and the extension is unavailable?
222

333AVAILSTATUS values

by nickbilak, Tuesday 13 of December, 2005 [12:38:12 UTC]
am i right that AVAILSTATUS can have the following 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 */

};


222

333Is ChanIsAvail broken ?

by ghendershot, Tuesday 24 of August, 2004 [05:54:25 UTC]
(:sad:) was wondering if anyone else is having trouble with ChanIsAvail ??? I use it to determine which of my 2 analog and 2 IAX channels is currently available for an outbound call ... I NoOp the value of the channel I am about to use and it looks good ... however, when I issue the DIAL command, I get an error that a ZAP channel cannot be created ... have not tried it yet against an IAX channle ...

Has anyone else seen this and maybe beaten it ??? is there another method folks are using to determine which channel is available ???

thanks

GHendershot