[Asterisk-Users] How to check if a phone / line is used?

Colin Anderson ColinA at landmarkmasterbuilder.com
Wed Apr 5 08:20:45 MST 2006


ChanIsAvail allows you to see if a channel can *accept* calls, not if it is
currently in use. Here is a script that will fix you up:

checkchannel.agi - returns number of channels in use on a SIP peer
Sets a variable in the dialplan, MYCHANNELS, indicating number of channels
in use


#!/bin/bash

#Connect to the Asterisk console and dump a SIP SHOW CHANNELS command to
grep
#and filter out everything except the peer we are looking for


CHANNEL=`asterisk -rx "SIP SHOW CHANNELS" | grep -a -A0 ".201"`    #Replace
.201 with the IP address of your SIP peer

#In this example, we have 4 registrations to the peer, you can carve out
unnessisary logic
#Initialize variables - here we are cutting out parts of the output to
create the variables
#You may have to change the location of the cut in order to make it work for
your install - this is for 1.0.9

CURRENTCHANNEL1=${CHANNEL:55:7}
CURRENTCHANNEL2=${CHANNEL:118:7}
CURRENTCHANNEL3=${CHANNEL:181:7}
CURRENTCHANNEL4=${CHANNEL:244:7}

TOTALCHANNELS=0

#If channel 1 is not an empty string and the string equals the ulaw codec,
it must be in use
#therefore increment the TOTALCHANNELS variable
#Replace the string 'ulaw' with the expected codec
#Optionally you could search for the string 'unknown' in order to determine
that a channel is NOT in use


if [ "${CHANNEL:55:7}" != "" ]
then
if [ $CURRENTCHANNEL1 = "ulaw" ]
then
TOTALCHANNELS=$((TOTALCHANNELS+1))
fi
fi

#And so on - for 1 channel only, delete these 3 other if-fi's

if [ "${CHANNEL:118:7}" != "" ]
then
if [ $CURRENTCHANNEL2 = "ulaw" ]
then
TOTALCHANNELS=$((TOTALCHANNELS+1))
fi
fi


if [ "${CHANNEL:181:7}" != "" ]
then
if [ $CURRENTCHANNEL3 = "ulaw" ]
then
TOTALCHANNELS=$((TOTALCHANNELS+1))
fi
fi



if [ "${CHANNEL:244:7}" != "" ]
then
if [ $CURRENTCHANNEL4 = "ulaw" ]
then
TOTALCHANNELS=$((TOTALCHANNELS+1))
fi
fi

#finally, dump a variable back to Asterisk indicating the number of channels
in use

echo "SET VARIABLE MYCHANNELS \"$TOTALCHANNELS\""

hth

-----Original Message-----
From: Paul Zimm [mailto:pbzinc at dejazzd.com]
Sent: Wednesday, April 05, 2006 8:41 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [Asterisk-Users] How to check if a phone / line is used?


In the dialplan you can use ChanIsAvail command
> Show channels?
>
>
> On Mar 31, 2006, at 2:09 AM, Ronald Wiplinger wrote:
>
>> In the past I used SetGroup and CheckGroup to figure out if my 
>> allowed providers lines are all used or not.
>> Since most of my provider have given me a single line anyway, I 
>> wonder if there is a way to check if this (provider) line is taken 
>> already.
>>
>> How can I do that?
>>
>> Same is with the phone. How can I see in CLI if a phone is now in use 
>> or not?
>> "Sip show peers" shows me just if it is on-line, but not if it is in 
>> a call or not.
>> In the dialplan I could dial the number and if it is busy, it would 
>> go to the Voicemail for unavailable or busy. I expect that there is 
>> just a test function as well, without trying to call.
>>
>>
>> bye
>>
>> Ronald Wiplinger
>>
>>
>> _______________________________________________
>

_______________________________________________
--Bandwidth and Colocation provided by Easynews.com --

Asterisk-Users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users



More information about the asterisk-users mailing list