Swatch : Simple Log Watcher to monitor Asterisk PRI status

This will monitor the asterisk log file and check for some pattern and restart the asterisk & dahdi service. ( can be used as a work around till you find the real problem).

  • Install swatch

# yum install swatch
  • Create file daemon script

/etc/init.d/swatch

#!/bin/sh
# Simple Log Watcher Program

case "$1" in
'start')
 /usr/bin/swatch --daemon --config-file=/etc/swatch.conf --tail-file=/var/log/asterisk/full --pid-file=/var/run/swatch.pid
 ;;
'stop')
 PID=`cat /var/run/swatch.pid`
 kill $PID
 ;;
*)
 echo "Usage: $0 { start | stop }"
 ;;
esac
exit 0


  • Make it executable and enable autostart.

# sudo chmod 755 /etc/init.d/swatch
# sudo ln -s /etc/init.d/swatch /etc/rc2.d/S99swatch
# sudo ln -s /etc/init.d/swatch /etc/rc3.d/S99swatch
# sudo ln -s /etc/init.d/swatch /etc/rc5.d/S99swatch
  • Create swatch config and commands.

vi /etc/swatch.conf

watchfor /Span 1: D-channel is down!|Primary D-Channel on span 1 down/
# echo
 write root
 mail addresses=user1\@mydomain.net:user2\@mydomain.net, subject=PRI down. Trying to restart.
 exec="/usr/bin/rstast.sh"

 

  • Add commands in  script and make it executable.

vi /usr/bin/rstast.sh

#!/bin/sh
sudo asterisk -rx "logger rotate"
sleep 3
sudo /etc/init.d/asterisk stop
sleep 3
sudo /etc/init.d/dahdi restart
sleep 3
sudo /etc/init.d/asterisk start
sleep 2

# chmod 755 /usr/bin/rstast.sh
Advertisements

Elastix Recording Location to a different Hard Disk

1. Add the new formatted Hard disk.

2. Create a new mount point for the disk and make asterisk as the owner of that.

#mkdir /monitor

#chown -R asterisk:asterisk /monitor/

3. Create startup script. You can also use fstab for the same.

Edit /etc/rc.local and add the following line. Here  /dev/sdb1 is the first partition of newly attached hard disk.

/bin/mount /dev/sdb1 /monitor

4. Run the startup script.

#cd /etc

#./rc.local

5. Now if you run the below command you should see the hard disk mounted( /dev/sdb1             903G  2.9G  853G   1% /monitor).
# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3             895G  2.8G  846G   1% /

/dev/sda1             487M   23M  439M   5% /boot

tmpfs                 2.0G     0  2.0G   0% /dev/shm

/dev/sdb1             903G  2.9G  853G   1% /monitor

6. Remove the monitor folder and link it to new location.

#rm -rf /var/spool/asterisk/monitor

#/bin/ln -s /monitor /var/spool/asterisk

#chown asterisk /var/spool/asterisk/monitor

7. Change Extension settings to enable recording in Elastix GUI and check if the files are saved in new location.

OpenFire with Active Directory – Elastix

Create database for Openfire

# mysql -u root -p
mysql> create database openfire;

Goto IM tab in Elastix GUI and start the installation.

Select the MySQL DB which you have created already.

Select Profile Settings as Directory Server

Put Active Directory Credentials


Leave User Mapping as it is

Choose the admin accounts for Open Fire.

Click Continue.

If you face the “HTTP ERROR: 500 INTERNAL_SERVER_ERROR” run the following commands.

# mkdir /var/lib/php/session/cache
# chmod 777 cache

Click browser’s back button and click continue to finish the installation.

For testing install XMPP client Pandion and login with Active Directory username @ Openfire Server name and active directory password. See the screenshot.

Asterisk – How to detect a busy tone

Asterisk without “Disconnect Supervision”

It is very hard to configure an asterisk system if your telco is not providing  Disconnect supervision on your PSTN/Analog line. Even the developers of digium “Switchvox” could not solve the “great call hangup issue” on their great PBX  till now (12th Sep. 2011), because many telecom providers all over the world do not support  this method of call disconnection.

So what happens if you are using asterisk and do not have disconnect supervision on your analog line. If you have not properly configured asterisk with busydetect=yes/callprogress=yes in dahdi/zapata configuration you  will end up  “always busy analog lines”  and you may have to restart the PBX  to receive a call/make call. As an example , I’m using asterisk and if somebody calling me,the call rings my phone via asterisk and  I’m not at my desk to attend the call, so the callee hangs up his phone. But the asterisk will keep ringing my phone because it will not detect the “call disconnect tone”  which is send by the telco when the callee hangup the call. So that PSTN/Analog line remains busy until you manually pick up  phone and disconnect or restart asterisk. This may happen always when caller/callee fails to hangup the call., ie call hang up from one end will not release the line for another call.

Try the below settings before you start.  Try increasing rxgain if pbx could not detect the busytone successfully.

Add busypattern if required. If your TSP supports polarity reversal(disconnect supervision) hanguponpolarityswitch is the best option.

Edit the file /etc/asterisk/chan_dahdi.conf

rxgain=5.0

busydetect=yes

busycount=3

;busypattern=500,500

;hanguponpolarityswitch=yes

The Solution

    One easy solution is get the appropriate busy tone/disconnect tone settings from your telco(you will never get it 😉 ) or from World PSTN Tone Database. If your telco tones are different than those they have given, then you may have to record the busy/call disconnect tone(Use 3CX Phone, or DAHDIBarge). Then use Audacity/Wavesurfer to find the on/off cadence timing on the recorded call. Find the screenshots.
Audacity

Here the ON timing is around 325 millisecond and the OFF timing is also the same.

So you got the busy tone/disconnect tone pattern  325/325. For some telco there may be multiple on/off settings ,like 325 on 325 off then 400 on and 350 off, then it repeats.ie 325/325/ 400/350.

Wavesurfer

Open the recorded file in Wavesurfer and select choose Configuration as Waveform.

Zoom in the waveform.

Right click in the  Spectrogram Pane to get the Spectrogram Controls.

Put the analysis window length to maximum to get the narrow spectrum line. Mouse over the spectrum line and see the status bar to get the frequency.

Select the wave form from start to end so that you will get the ON timing as a tool tip.

Select the blank area to get the OFF timing.

PIKA – The easy PBX

If you are using pika PBX you can straight away use this settings to configure the PBX. Edit the file /etc/pika/inccpa.cfg. Add new pattern under [callpa_settings]. Create the pattern context with the new tone settings.

If you got the tone on/off pattern as 400 on,350 off, 230 on,530 of as “Call disconnect” Tone. then the configuration will be as follows.

There are more patterns.showed only newly added pattern.

[callpa_settings]
pattern4=cp_huntbusy
[cp_huntbusy]
type=4
tolerance=30
cadences=2
states=4
ignorestates=1
state0=400
state1=350
state2=230
state3=530

DAHDI Configuration for Normal PC/Server based Asterisk installation

The main configuration files are /etc/asterisk/chan_dahdi.conf &  /etc/asterisk/dahdi-channels.conf

.. to be continued..

Worth reading: http://www.fredshack.com/docs/asterisk.html

FreePBX FOP1 to FOP2

How to change FOP1 to FOP2 on Elastix

1.  Download and install FOP2

cd /usr/src
wget http://www.fop2.com/file.php?file=20
tar -zxvf fop2-2.22-centos5-i386.tgz 
cd fop2
make && make install

2. Add fop2 user to Asterisk Manager.

Edit /etc/asterisk/manager.conf

[fop2]
secret = psfop2
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
write = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate

3. Edit /usr/localfop2/fop2.cfg and change the following lines.

manager_user=fop2
manager_secret=psfop2

4.Edit /etc/amportal.conf and edit the uncomment the line starting FOPRUN and change it as following.

FOPRUN=false

5. Edit /var/www/html/panel/op_server.cfg and change listen_port.

listen_port=4444

6. Edit /etc/httpd/conf/httpd.conf and add the following line under  Aliases:

alias /panel /var/www/html/fop2

7. Add FreePBX index file and change the fop2 ownership asterisk.

cp /var/www/html/fop2/index.html /var/www/html/fop2/index_amp.php
chown -R asterisk.asterisk /var/www/html/fop2

8. Restart httpd,amportal and fop2 services.

/etc/init.d/httpd restart
chkconfig fop2 on
service fop2 start
/usr/sbin/amportal restart

Cisco SIP Configuration

Cisco 7911G/7942/7945/7962 Phone with Asterisk

Download the firmware (7911 ,79427945 , 7962) and extract it.

Download and install/extract the tftp server software.

Open the tftp server software and make the SIP firmware  extracted directory as the root directory of the tftp server.

Goto command prompt(Start>Run>CMD and press enter) and enter the following command.

C:\Users\user>tftp <tftp-server-ip-address> get dialplan.xml

You should get the message starting “Transfer Successful”.(If your OS is Win7/Vista you have to install tftp client from the Add/Remove Programs)

C:\Users\shyju>tftp 192.168.20.124 get dialplan.xml
Transfer successful: 258 bytes in 1 second(s), 258 bytes/s

Open your dhcp server configuration and add  TFTP server IP address as the boot server in DHCP scope Options. Refer this article to configure DHCP Options.

Rename the  with SEP<MAC-ADDRESS-OF-YOUR-PHONE>.cnf.xml. Then open that file and change the following lines to match with your IP PBX details.

<processNodeName>
<featureLabel>
<proxy>
<port>
<name>
<displayName>
<authName>
<authPassword>

Edit your Asterisk SIP configuration and add nat = no below the user context.

This step is important otherwise the phones will not register and on the phone’s display you can see the message Registering..

If you are using FreePBX the file will be /etc/asterisk/sip_additional.conf, In the case of Asterisk-GUI file is /etc/asterisk/users.conf

[610]
deny=0.0.0.0/0.0.0.0
type=friend
secret=jbsdf7h4ks
qualify=yes
port=5060
pickupgroup=
permit=0.0.0.0/0.0.0.0
nat=no
mailbox=610@device
host=dynamic
dtmfmode=rfc2833
dial=SIP/610
context=from-internal
canreinvite=no
callgroup=
callerid=device <610>
allow=all
accountcode=
call-limit=50