• News
  • Idefisk
  • Tools
  • Tutorials
  • Forum
  • Reviews
  • VoIP Providers
  • Archives
  • Gallery
ZOIPER SIP softphone
Back to Tutorials

10.1. Automatically call all phones to check if they work

1. Description:

The purpose of this system is the automated testing of all accounts which can receive calls, with the Echo() application. It is based on a bash script which creates a call file and an extension in the dialplan. Basically when the system is started the script selects all users, starts calling (via call files) them one after another. This is very basic example of the "reverse application manipulation".


2. Pre-setup:

Before running through the core of this tutorial, let's make some small preparations for it.
* Ensure that you have a working Asterisk server.
* Ensure that you have rights to read/write at /var/spool/asterisk directory.
* Ensure that you have rights to write in /etc/asterisk/extensions.conf file.
* Make a recording of the following announcement: "This is an automated test. Excuse us for the inconvenience. After the signal you will be able to hear your voice like an echo. If you are unable to hear your voice, please press the pound key. By pressing the pound key we will be notified for your problem."
* Make a recording of the following announcement: "We have been notified for your problem. We will contact you with more information."


3. Setup:

The setup that we are going to use has the following properties: the system should find all users for curtain channel (iax2 or sip). Every user is been called by the Asterisk and is been greeted with announcement one. We will set an absolute timeout to two minutes (120 seconds). After that the Echo() application is going to start in order to make the test. If the user hangs up, Asterisk will do nothing, and the system is going to call the next user. If the user press the pound key, the system is going to run a program or script which will notify us for the problem.

Step 3.1: Creating the needed extensions
Let's create the extension that we are going to use. Since we are going to use a call file, there is no significance where (at which context) the extension will be placed. For this tutorial we will create a special context named `echotest`. Here what you have to do:
	Open your extensions.conf using a text redactor.
	At the bottom of the file (on new line) add new context by typing `[echotest]` (without the quotes).
	Add the following extension:
		exten => echo,1,Answer()
			; Answer the line
		exten => echo,n,Set(TIMEOUT(absolute)=120)
			; Sets maximum length of the call to two minutes (if someone forgets to hang up)
		exten => echo,n,Playback(file1)
			; Playbacks file named `f1`. The user will hear the contents of `f1`
			; In our tutorial `f1` is the first announcement that we have recorded.
		exten => echo,n,Echo()
			; starting Echo() application which will create the echo effect
		exten => echo,n,Playback(f2)
			; Playbacks file named `f2`. The user will hear the contents of `f2`
			; In our tutorial `f2` is the first announcement that we have recorded.
		exten => echo,n,System(/bin/notify_us ${CUR})
			; Notification script which will notify us that curtain user is experiencing problems.
		exten => echo,n,HangUp()
			; Hangs up the call.

Here is an screenshot of what it should look like:
extensions.gif

This extension is very usefull even if you use it alone (without the script). If the user follows the instructions, there are two possible outcomes:
* the user hears his voice and hangs up the call. In this case Asterisk will terminate the call and the second part of the extension won't execute (the part with second playback and running notification program/script). The user may not hang up the call, but because of the absolute timeout that we have set, the call will be termincated in 120 seconds. If we look at Asterisk console, the output should be something like this:
normal.gif
* the user doesn't hear his voice, and presses the pound key. In this case, Asterisk will continue with the next priority of the extension (which is the run of the notification program/script). If we look at Asterisk console, the output should be something like this:
problematic.gif


Remark: if you have only write access to /etc/asterisk/extensions.conf , create somewhere a file in which write the context and the extension. Then run the command:
		`cat /route/to/somewhere/file >> /etc/asterisk/extensions.conf`
where `/route/to/somewhere/file` is the path and the file in which you have written the thing.


Step 3.2: Preparation for the creation of call files
Now let's create a prototype for our call files. We will create it in /var/spool/asterisk/ directory. However the location of the prototype is not important for script (the location have to differs important dirs like `/dev`, `/boot`, `/var/spool/asterisk/outgoing`, etc...).
	Context: echotest
		# Asterisk will execute extension in this string
	Extension: echo
		# Name of the extension
	Priority: 1
		# At which priority Asterisk will begin the execution
	Callerid: Automated Test System <>
		# Setting the CallerID to the specified string.
If you copy/paste the protoype file, notice that you have to remove the comments marked with #. Asterisk will not escape those comments, and their might lead to unexpected results. The file should look like this one:
prototype.gif
You may notice that the only not optional keyword for the call files (Channel: CHAN/USER) is missing. Don't worry we will not make with this file. We will just use it for creation of the actual call files. We will use this prototype call file with the filename `echotest.org.call` at the following directory: /var/spool/asterisk/ echotest-$i.call;

Step 3.3: Making a list of people to call
Now let's create a small bash script which will make the whole work for us.
We will need to get all users which are added to our configuration files. There are two ways to do this:

1. parsing sip.conf or accordingly iax.conf - you have to have read access to those files if you want to proceed in this way.

cat /etc/asterisk/$1.conf | grep -a '[' | grep -a ']' | grep -va ';[' | cut -d[ -f 2 | cut -d] -f 1


2. parsing the console output for the actually loaded users into the memory of our Asterisk server.

asterisk -rx "$1 list users" | grep -va Username | grep -va Verbosity | grep -va "UNIX Connection" | cut -d -f 1


Both methods have both pros and cons:
* parsing the configuration files - we will write a bash script for this method. We will name it `example1`.
- configuration files might be very long (parsing them might be a slow task)
- there might be more than one configuration file
- there might be some account which are not activated (if someone made changes in them, but haven't reloaded Asterisk)
+ configuration files are more predictable and there are less things that you should escape


* parsing console output - we will write a bash script for this method. We will name it `example2`.
- you have to mess with the verbose level of Asterisk in order to escape the NOTICES and ERRORS. This might escape important events.
+ console output is far shorter (as length of the information) than the configuration files


`example1`
#! /bin/bash

cd /var/spool/asterisk;

for i in $(cat /etc/asterisk/$1.conf | grep -a '[' | grep -a ']' | grep -va ';[' | cut -d[ -f 2 | cut -d] -f 1); do
echo "Channel: $1/$i" >> echotest-$i.call;
cat echotest.org.call >> echotest-$i.call;
echo "SetVar: CUR=$1/$i" >> echotest-$i.call;
echo " -- Makeing echo test with $1/$i";
sleep 120;
mv echotest-$i.call outgoing/
done;


Run the script in the following way:
./echotest iax to test IAX2 users
./echotest sip to test SIP users

 

`example2`

#! /bin/bash

cd /var/spool/asterisk;

for i in $(asterisk -rx "$1 list users" | grep -va Username | grep -va Verbosity | grep -va "UNIX Connection" | cut -d -f 1); do
echo "Channel: $1/$i" >> echotest-$i.call;
cat echotest.org.call >> echotest-$i.call;
echo "SetVar: CUR=$1/$i" >> echotest-$i.call;
echo " -- Makeing echo test with $1/$i";
sleep 120;
mv echotest-$i.call outgoing/
done;


Run the script in the following way:
./echotest IAX2 to test IAX2 users
./echotest SIP to test SIP users

Step 3.4: Improve the scripts to reduce the amount of extensions we forgot to call

`example1`

#! /bin/bash

cd /var/spool/asterisk;

for i in $(cat /etc/asterisk/$1.conf | grep -a '[' | grep -a ']' | grep -va ';[' | cut -d[ -f 2 | cut -d] -f 1); do
echo "Channel: $1/$i" >> echotest-$i.call;
cat echotest.org.call >> echotest-$i.call;
echo "SetVar: CUR=$1/$i" >> echotest-$i.call;
echo " -- Makeing echo test with $1/$i";
sleep 121;
mv echotest-$i.call outgoing/
done;

for j in $(cat iax.conf | grep -a "include" | cut -d -f 3); do
echo " --- Parsing included file $j";
for f in $(cat $j | grep -a '[' | grep -a ']' | grep -va ';[' | cut -d[ -f 2 | cut -d] -f 1); do
echo "Channel: $1/$f" >> echotest-$i.call;
cat echotest.org.call >> echotest-$i.call;
echo "SetVar: CUR=$1/$f" >> echotest-$i.call;
echo " -- Makeing echo test with $1/$i";
sleep 121;
mv echotest-$i.call outgoing/
done;
done;


Run the script in the following way:
./echotest iax to test IAX2 users
./echotest sip to test SIP users

 

`example2`

#! /bin/bash

cd /var/spool/asterisk;

OldVerbose=`asterisk -rx "set verbose 1" | grep was | cut -d -f 3`

echo Verbose will be set to 0. Old Verbose (equal to $OldVerbose) will be restored later;

asterisk -rx "set verbose 0";

cd /var/spool/asterisk;

for i in $(asterisk -rx "$1 list users" | grep -va Username | grep -va Verbosity | grep -va "UNIX Connection" | cut -d -f 1); do

echo "Channel: $1/$i" >> echotest-$i.call;
cat echotest.org.call >> echotest-$i.call;
echo "SetVar: CUR=$1/$i" >> echotest-$i.call;
echo " -- Makeing echo test with $1/$i";
sleep 121;
mv echotest-$i.call outgoing/
done;
asterisk -rx "set verbose $OldVerbose";


Run the script in the following way:
./echotest IAX2 to test IAX2 users
./echotest SIP to test SIP users


 

The second version of those scripts were upgraded in some ways:
configuration file parsing - recurse search and parse of included files
configuration file parsing - script will place a message on the console for every user it calls
configuration file parsing - script will place a message on the console for file it starts to parse
console output - escape most of the messages by temporally setting the VERBOSE level to 0
configuration file parsing - script will place a message on the console for every user it calls

I am sure that the reader of this tutorial will try to modify these scripts. That's why I will leave some notifications which will help you:
SetVar: CUR=$1/$i - is setting a variable in the dialplan so Asterisk will be able to notify (in some way) that a problem occurred with curtain user
sleep 121; - removing this line may case the following problem - Asterisk will try to dial too much calls and might crash.
sleep 121; - setting a different value to the sleep command may cause the following bug - Asterisk will change the ${CUR} variable and if the user presses the pound key, you might be notified for an other user.



Enjoy your testing!

 
User Comments
Ahmed (khattabi007 at gmail dot com)
16 July 2008 17:31:55
Hi
i tray to use the script, but rearly i have no idea how to use it, i inderstound that it will make a call files into a directory /outgoing but how that????

thanks
Erik de Wild (info at tripple-o dot nl)
28 February 2007 02:31:03
Just another approach:

With
asterisk -rx "SIP list users" > siplist
You can get the available sip extensions in a file

I'm not much of scripter but it can't be so hard reading this file line by line and store the numbers into a variable with other relevant info to pass it over to another script.

With the script below you can replace an standard string in a template file for the value of the variable.
##############
#!/bin/sh
# based on info on http://www.tldp.org/LDP/abs/html/othertypesv.html
# erik de wild Tripple-o 28 december 2005
#############
variable1=$1
export variable1
#######
#copying the template file
#######
#dir is just an exmple from debian system
#######
cp /var/spool/asterisk/script/template /var/spool/asterisk/berichtenservice/$1
########
# cd to the dir where the template is copied
########
cd /var/spool/asterisk/berichtenservice

########
# replace the xxxxx in the template with the
# extension number to be tested
#######
grep -r -l 'xxxxx' . | xargs perl -pi -e"s/bxxxxxb/${variable1}/g"

#

Use the template file below. (just an example)


Channel: SIP/xxxxx
MaxRetries: 24
RetryTime: 3600
WaitTime: 45
Context: testtest
Extension: s
Priority: 1

With the script you end up with a call file with the proper number and with the file named after the number. The last thing to do is to schedule the actual calling using the at command to copy it into the outgoing directory. Tis way you handle the number of cuncurrent calls simple by changing the planned time with every max number of scheduled calls.

With the line below you can schedule the callstraighforward. Using a variable instead of the 1 in 1 minute will prevent overloading the system by planning all the calls in very narrow timeframe

exten => s,2,System(echo cp /var/spool/asterisk/berichtenservice/${INPUTNUMMER} /var/spool/asterisk/outgoing/${INPUTNUMMER}|at now+ 1 minutes)

If anyone knows the script for reading a file line by line and store the extension number into a variabel please add it. That is the missing piece.
leo (me at me dot com)
26 January 2007 01:06:06
none of the scripts work in CentOS

;-(
 
Add Comment
Name:
Email:
Comment:
In order to prevent automatic posting on our website, we kindly request you to type in the number you see in the picture below.
Image Verification:
 

Latest Headlines:

  • T.38 faxing with Zoiper 2.15 is now easier than ever
    section: voip software
  • Asterisk 1.4.21 Released
    section: Asterisk
  • Asterisk 1.4.20 Released
    section: Asterisk
  • Asterisk 1.4.20-rc2 Released
    section: Asterisk
  • Asterisk 1.4.20-rc1 Now Available
    section: Asterisk
  • News Archives (older news)

Latest Tutorials:

  • Sending Fax from Zoiper to Zoiper using T.38
    added 08/Dec/2008 18:16
  • VMAuthenticate (dialplan application)
    added 01/Mar/2008 15:57
  • Siptronic ST-530
    added 06/Nov/2007 17:57
  • Siemens C455 IP hardphone
    added 05/Nov/2007 10:24
  • Zoiper
    added 22/Oct/2007 17:53

Latest Comments:

  • nice...
    tutorial: X-Lite - SIP softphone
  • Badly need your help. Things are only im...
    tutorial: Grandstream HandyTone-486 - SIP Analog Telephone Adapter (ATA)
  • how do i rectify this problem? all incom...
    tutorial: Troubleshooting
  • How are you. Summer afternoon - Summer a...
    tutorial: Cisco 7960 IP Phone - SIP firmware version
  • where is the tar file you mention above ...
    tutorial: Cisco 7960 IP Phone - SIP firmware version
 
contact us at: support@asteriskguru.com - asterisKGuru.com © all rights reserved   |   *asterisk is registered trademark of © Digium™