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.

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

Call Forwarding from outside the office

See the previous call forward setup.  Use the same setup and append the below lines to /etc/asterisk/extensions_custom.conf , change the numbers to where you want to enable call forwarding(ie. the your mobile number from where you pick up the forwarded call)  and reload asterisk. Dial your office number from your mobile when you reach IVR dial 9 which will enable call forwarding . Now all calls to your office are forwarded to your mobile.

[ivr-5-custom]
exten => 9,1,NoOP(${CALLERID(num)})
exten => 9,n,GotoIf($["${CALLERID(num)}" = "0X5X8X0X2X" || "${CALLERID(num)}" = "05X9X4X8XX"]?cact)
exten => 9,n,Goto(ivr-5,s,1)
exten => 9,n(cact),Goto(from-internal,*${CALLERID(num)},1)

Asterisk 1.4:Call forwarding(Follow Me) – With Music On Hold-MeetMe-Without delay

When we use follow-me in FreePBX with our mobile number as the follow-me extension, the caller will hear the ring back sound when the PBX dials our mobile number.  If we are using analog lines to forward the calls even the Dial command with m option(Music On Hold) will not work in this situation.

Here I’m using  meet-me application asterisk call file  and some dial plan manipulation to do the task. All the calls from PSTN(analog lines) to IVR will be forwarded to mobile number. Create conference extension from FreePBX GUI ,create IVR and route the calls to conference number from IVR. Add a 3rd IVR and route the calls from that to same conference number., In third IVR you can add some voice menu like “You have received a call please dial 0 to accept the call” so that when we receive the forwarded call we can dial 0 and connect caller. The forward number will be dialed as soon as the  incoming call reaches PBX. So the call connection delay will be minimum.

First I’ve made a dial plan to Activate/Deactivate call forwarding. To enable/disable (toggle) call forwarding you have to dial * followed by your mobile number from your extension. Find below the dialplan. Put this into /etc/asterisk/extension.conf under [from-internal] context. Here it is 10 digit number starting with a preceding 0.

[from-internal]
exten => _*0XXXXXXXXX,1,NoOP(${DB(AMPUSER/followme)})
exten => _*0XXXXXXXXX,n(start),Answer
exten => _*0XXXXXXXXX,n,Wait(1)
exten => _*0XXXXXXXXX,n,Macro(user-callerid,)
exten => _*0XXXXXXXXX,n,GotoIf($["${DB(AMPUSER/followme)}" = "0"]?activate)
exten => _*0XXXXXXXXX,n(deactivate),Set(DB(AMPUSER/followme)=0)
exten => _*0XXXXXXXXX,n,Playback(followme&de-activated)
exten => _*0XXXXXXXXX,n(end),Macro(hangupcall,)
exten => _*0XXXXXXXXX,n(activate),Set(DB(AMPUSER/followme)=${EXTEN:1})
exten => _*0XXXXXXXXX,n,Playback(followme&activated)
exten => _*0XXXXXXXXX,n(end),Macro(hangupcall,)

Create a sh script make it executable,make asterisk as its owner and save it as “/va/lib/asterisk/bin/clfwd.sh” . This file make a call to your mobile when a new call arrives.

#!/bin/bash
echo -e "Channel: DAHDI/16/$1\nMaxRetries: 2\nRetryTime: 60\nWaitTime: 45\nContext: ivr-7\nExtension: s" > /tmp/$1.call
chmod 777 /tmp/$1.call
mv /tmp/$1.call /var/spool/asterisk/outgoing/

Edit the file /etc/asterisk/extension_additional.conf and add the below line under the context [from-pstn-custom]. Create the context [ from-pstn-custom] if it doesn’t exists.

[from-pstn-custom]
exten => s,1,Noop(Entering FAX Detection)
exten => s,n,Ringing()
exten => s,n,Set(DID=${IF($["${DID**"= ""]?s:${DID**)**)
exten => s,n,Noop(DID is now ${DID**)
exten => s,n,Set(CHAN=${CHANNEL:6})
exten => s,n,Set(CHAN=${CUT(CHAN,-,1)})
exten => s,n,GotoIf($["${CHAN}" = "18"]?fax:ivr)
exten => s,n(fax),Goto(ext-fax-custom,s,1)
exten => s,n(ivr),NoOP(${DB(AMPUSER/followme)})
;exten => s,n,Set(CFNO = "${DB(AMPUSER/followme)}")
exten => s,n,GotoIf($["${DB(AMPUSER/followme)}" != "0"]?active)
exten => s,n,Goto(ivr-5,s,1)
exten => s,n,Hangup()
exten => s,n(active),Wait(2)
exten => s,n,ChanIsAvail(DAHDI/16)  ;checks if the line to forward the call is already busy.
exten => s,n,Set(CHANAV=${AVAILORIGCHAN})
exten => s,n,GotoIf($["${CHANAV}" = ""]?active)
exten => s,n,system(/var/lib/asterisk/bin/clfwd.sh ${DB(AMPUSER/followme)})
exten => s,n,Goto(ivr-7,s,1)
exten => s,n,Hangup()
exten => fax,1,Goto(ext-fax-custom,s,1)

Enable call forwarding by dialing your number with preceding *.

Make a call to your PBX . The PBX makes a call to your mobile. Accept the call and dial 0 to connect the caller.

Find below the other configurations by FreePBX GUI.

;extension_additional.conf

[ext-meetme]
include => ext-meetme-custom
exten => STARTMEETME,1,MeetMe(${MEETME_ROOMNUM},${MEETME_OPTS},${PIN})
exten => STARTMEETME,n,Hangup
exten => h,1,Hangup
exten => 696,1,Macro(user-callerid,)
exten => 696,n,Set(MEETME_ROOMNUM=696)
exten => 696,n,Set(MEETME_RECORDINGFILE=${ASTSPOOLDIR}/monitor/meetme-conf-rec-${MEETME_ROOMNUM}-${UNIQUEID})
exten => 696,n,GotoIf($["${DIALSTATUS}" = "ANSWER"]?USER)
exten => 696,n,Answer
exten => 696,n,Wait(1)
exten => 696,n(USER),Set(MEETME_OPTS=qMsr)
exten => 696,n,Goto(STARTMEETME,1)
exten => 696,hint,MeetMe:696
[ivr-5]
include => ivr-5-custom
include => from-did-direct-ivr
include => app-directory
exten => #,1,dbDel(${BLKVM_OVERRIDE})
exten => #,n,Set(__NODEST=)
exten => #,n,Goto(app-directory,#,1)
exten => h,1,Hangup
exten => s,1,Set(MSG=custom/ePillars_IVR)
exten => s,n,Set(LOOPCOUNT=0)
exten => s,n,Set(__DIR-CONTEXT=default)
exten => s,n,Set(_IVR_CONTEXT_${CONTEXT}=${IVR_CONTEXT})
exten => s,n,Set(_IVR_CONTEXT=${CONTEXT})
exten => s,n,GotoIf($["${CDR(disposition)}" = "ANSWERED"]?begin)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(begin),Set(TIMEOUT(digit)=3)
exten => s,n,Set(TIMEOUT(response)=10)
exten => s,n,Set(__IVR_RETVM=)
exten => s,n,ExecIf($["${MSG}" != ""],Background,${MSG})
exten => s,n,WaitExten(,)
exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup
exten => 0,1,dbDel(${BLKVM_OVERRIDE})
exten => 0,n,Set(__NODEST=)
exten => 0,n,Goto(from-did-direct,603,1)
exten => 1,1,dbDel(${BLKVM_OVERRIDE})
exten => 1,n,Set(__NODEST=)
exten => 1,n,Goto(from-did-direct,603,1)
exten => 2,1,dbDel(${BLKVM_OVERRIDE})
exten => 2,n,Set(__NODEST=)
exten => 2,n,Goto(from-did-direct,603,1)
exten => 3,1,dbDel(${BLKVM_OVERRIDE})
[ivr-6]
include => ivr-6-custom
include => from-did-direct-ivr
include => app-directory
exten => #,1,dbDel(${BLKVM_OVERRIDE})
exten => #,n,Set(__NODEST=)
exten => #,n,Goto(app-directory,#,1)
exten => h,1,Hangup
exten => s,1,Set(MSG=custom/ePillars_IVR)
exten => s,n,Set(LOOPCOUNT=0)
exten => s,n,Set(__DIR-CONTEXT=default)
exten => s,n,Set(_IVR_CONTEXT_${CONTEXT}=${IVR_CONTEXT})
exten => s,n,Set(_IVR_CONTEXT=${CONTEXT})
exten => s,n,GotoIf($["${CDR(disposition)}" = "ANSWERED"]?begin)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(begin),Set(TIMEOUT(digit)=3)
exten => s,n,Set(TIMEOUT(response)=10)
exten => s,n,Set(__IVR_RETVM=)
exten => s,n,ExecIf($["${MSG}" != ""],Background,${MSG})
exten => s,n,WaitExten(,)
exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup
exten => 0,1,dbDel(${BLKVM_OVERRIDE})
exten => 0,n,Set(__NODEST=)
exten => 0,n,Goto(ext-meetme,696,1)
exten => 1,1,dbDel(${BLKVM_OVERRIDE})
exten => 1,n,Set(__NODEST=)
exten => 1,n,Goto(ext-meetme,696,1)
exten => 2,1,dbDel(${BLKVM_OVERRIDE})
exten => 2,n,Set(__NODEST=)
exten => 2,n,Goto(ext-meetme,696,1)

[ivr-7]
include => ivr-7-custom
include => from-did-direct-ivr
include => app-directory
exten => #,1,dbDel(${BLKVM_OVERRIDE})
exten => #,n,Set(__NODEST=)
exten => #,n,Goto(app-directory,#,1)
exten => h,1,Hangup
exten => s,1,Set(MSG=custom/Call)
exten => s,n,Set(LOOPCOUNT=0)
exten => s,n,Set(__DIR-CONTEXT=default)
exten => s,n,Set(_IVR_CONTEXT_${CONTEXT}=${IVR_CONTEXT})
exten => s,n,Set(_IVR_CONTEXT=${CONTEXT})
exten => s,n,GotoIf($["${CDR(disposition)}" = "ANSWERED"]?begin)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(begin),Set(TIMEOUT(digit)=3)
exten => s,n,Set(TIMEOUT(response)=3)
exten => s,n,Set(__IVR_RETVM=)
exten => s,n,ExecIf($["${MSG}" != ""],Background,${MSG})
exten => s,n,WaitExten(,)
exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup
exten => 0,1,dbDel(${BLKVM_OVERRIDE})
exten => 0,n,Set(__NODEST=)
exten => 0,n,Goto(ext-meetme,696,1)
exten => 1,1,dbDel(${BLKVM_OVERRIDE})
exten => 1,n,Set(__NODEST=)
exten => 1,n,Goto(ext-meetme,696,1)
exten => 2,1,dbDel(${BLKVM_OVERRIDE})
exten => 2,n,Set(__NODEST=)
exten => 2,n,Goto(ext-meetme,696,1)

meetme_additional.conf

conf => 696,

Asterisk – Skill Based Routing

**skills or specialties = priority 1 / priority 2 / priority 3

agent 1 = mac

agent 2 = linux

agent 3 = linux

agent 4 = mac / linux

agent 5 = linux / mac

When agent 1 is busy, next call should go to agent 4. But when both agent 1 and 4 is busy (both have priority skill for MAC), call should go to agent 5 (can accept calls for MAC) because it has priority 2 for MAC. Is this possible?

Asterisk doesn’t really have skills based routing yet, but you can do the same thing with multiple queues. Each queue being a skill. Below you will find my interpretation of your requirements. In your example, agent 4 and 5 are members of both queues, but have their penalties set appropriately.

queues.conf

[general]
autofill=yes 

[linux]
; Put whatever other queue options you want here
strategy=rrmemory
member => Agent/agent2,1
member => Agent/agent3,1
member => Agent/agent4,3
member => Agent/agent5,2 

[mac]
; Put whatever other queue options you want here
strategy=rrmemory
member => Agent/agent1,1
member => Agent/agent4,2
member => Agent/agent5,3

http://forums.digium.com/viewtopic.php?t=19527