Friday, August 27, 2010
Watchdog Script for the Linux Processes (Asterisk)
#!/bin/bash
#script file: astSvcControl.sh
PROCESS="asterisk"
PROCCHK=$(ps aux|grep -c $PROCESS)
if [ $PROCCHK -eq 1 ]
then
/usr/sbin/asterisk
echo "Started Asterisk Service at $(date)" >> /var/log/asterisk/asterisk-check.log
else
echo "$PROCESS is running $PROCCHK processes" >> /var/log/asterisk/asterisk-check.log
fi
[Note: In SuSE linux, ps aux|grep -c < process name > returns 1 if the process is not running and returns 2 or more if the process is running
In SuSE linux, grep < process name > also returns grep < process name > as one of the process, thus it always returns 1
But some flavors of linux, it returns 0 if the process is not running and returns 1 or more if the process is running
]
2. Make sure that script is executable
#chmod 770 astSvcControl.sh
3. Run the script periodically using cronjobs
#crontab -e
* * * * * bash /root/astSvcControl.sh
(run every minute)
If you want to run the script every 5 mintutes , do this
#crontab -e
*/5 * * * * bash /root/astSvcControl.sh
More on cronjobs for Linux/Unix:
http://www.cyberciti.biz/faq/disable-the-mail-alert-by-crontab-command/
http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_crontab/
Wednesday, August 11, 2010
Asterisk PRI Trunk Group customization - Top-Down/Bottom-Up Hunting
You might be wondering, what the hell is 'a glare condition'?
A glare condition is the situation when the when a outbound call finds a clear channel and a new inbound call arrives at the very same instant, the inbound call wins, the outbound call gets "all circuts are busy"or vice versa.
So, how to fix it?
Let's say we have 23 channel PRI with D channel - 24. Telco is sending the inbound calls to hunt from channel 1 -> 23. So, I need to set outbound calls to hunt from channel 23 -> 1 to avoid the Channel Busy before ANY possibility of call collision.
How can I do that in Asterisk?
You specify which of four methods the Zap channel module is to use to select a non-busy channel from the channel group by prefixing the group number with one of the letters g, G, r, or R:
g: select the lowest-numbered non-busy Zap channel (aka. ascending sequential hunt group).
G: select the highest-numbered non-busy Zap channel (aka. descending sequential hunt group).
r: use a round-robin search, starting at the next highest channel than last time (aka. ascending rotary hunt group).
R: use a round-robin search, starting at the next lowest channel than last time (aka. descending rotary hunt group). [/color]
Create a new ZAP trunk and specify G0 as the trunk ID, go to your outbound routes. replace any routes calling for the trunk g0 and replace with new trunk G0. Go back and delete the g0 trunk so it will not be accidently selected as it is going to be the first trunk in the pull down list.
Wednesday, May 26, 2010
PRI/T1 having issues.... follow some of the checkpoints
A. Phyical Connection Issues
1. cabling
2. smart jack : It is the jack that can be used by Telco provider to do the loopback test remotely. With that said, it is not the mandatory device to put in the customer side, but Telco installs it on customer side so that they can do loopback test from their end remotely.
3. demarc : Telco line terminates to demarc of the customer primises.
Make a loop back plug. Simply take RJ-45 plug, loop a wire from pin1 to pin4 and another from pin2 to pin 5 and crip down the RJ-45.
If the circuit or the PRI/T1 card showing RED alarm, plug the loopback plug, if the circuit goes green then it says that hardware is good and configuration might also be good. But not 100% sure.
Plug the loopback plug on the smart jack to see if the Telco is having the issue. If the circuit goes green on the smart jack too, then jump to step B.
B. Protocol/signalling/configuration issues
1. Check if you are in sync on the physical layer - one of your T1 endpoints should provide clocking and another end should take clocking from the line
#/etc/zaptel.conf or /etc/dahdi/system.conf
span=<span num>,<clocking>,<LBO>,<framing>,<encoding>
e.g span=1,0,0,esf,b8zs
Here, clocking is set to 0 so it is using internal clock for clocking. So, it's configured like master clock source. The other end should be configured as slave for clocking ( i.e set second parameter to 1). If you are using T1 line from Telco provider, make sure that you set clocking to '0' as Telco is always configured as master for clocking.
esf,b8zs is widely accepted framing and encoding in North America.
2. Then, check if you have the same protocol running by both parties on the D-channel
#/etc/asterisk/zapata.conf or /etc/asterisk/chan_dahdi.conf
switchtype=<specify switchtype>
e.g switchtype=national
3. Finally, check if you have the right master/slave relationship on ISDN level. One side of the link should be set as network while another end should be set as user/slave.
#/etc/asterisk/zapata.conf or /etc/asterisk/chan_dahdi.conf
signalling=<specify signalling>
e.g signalling=pri_cpe #user-side configuration (Slave/User)
e.g signalling=pri_net #network-side configuration (Master)
If you are unsure how the other side is configured just try to set pri_net on Asterisk side. If it works with Telco provider, make sure that you contact them and tell them to change their configuration to NETWORK so that you can change your Asterisk as USER (pri_cpe).
Some bonus information:
Framing:
ESF
D4
CAS
CCS
Encoding:
B8ZS
AMI
HDB3
NCRC2
Signalling:
pri_cpe
pri_net
fxs_ks
fxs_ls
fxs_gs
fxo_ks
fxo_ls
fxo_gs
em (E&M)
em_w (E&M Wink)
em_e1
Switchtype:
Only used for PRI
national --> National ISDN 2 (default)
dms100 --> Nortel DMS100
4ess --> AT&T 4ESS
5ess --> Lucent 5ESS
euroisdn --> EuroISDN (common in Europe)
ni1 --> Old National ISDN 1
qsig --> Q.SIG
Tuesday, May 4, 2010
I have multiple T1 cards on the Asterisk Server. How do I know which T1 card will load first?
Card 0 has Span1-4 as it is loaded first
Card 1 has Span5-8 as it is loaded second
However, what will happen if Card1 loads first. You are in trouble as Card1 will host Span1-4, not the Card0.
To prevent this disaster to happen, Digium has Ident Dial that makes the driver load on the card in specific order. Ident Dial has range from '0-9' 'A-F'.
Now, I would do this
Card0 with Ident set to 0
Card1 with Ident set to 1
This will ensure that Card0 will have Span1-4
and Card1 will have Span5-8
Setting all cards to zero should cause the driver to automatically number the cards. The dial should only be used if a specific order is needed.
http://kb.digium.com/entry/106/
Wednesday, April 28, 2010
Benefits of using trunk group instead of multiple T1/E1 trunks
- Less programming of trunk groups in the CO to manipulate overflow whether it be in or out. That is, if 1 trk group is busy there will be no need for overflow to the other trunk group. If it is one trunk group all the channels will hunt to next channel if they are in use whether it is inbound or outbound. Traditionally, incoming starts from trk member 1, outbound starts from trk member 46.
- You will also get a backup d-channel that wil be available if the primary has a problem. If for some reason another span is needed, depending if the Asterisk is capable of doing this, it can be set-up as a full T1 rather than a PRI. This will get you an additional b-channel for voice and the full T1 can be a rider AND use the the d-channel signaling form the other spans.
Q: How can we achieve that in asterisk?
Ans: NFAS (Non-Facilities Associated Signaling) is an ISDN feature for sharing one ISDN D channel accross multiple ISDN PRI lines.
Thursday, April 15, 2010
SIP trunk between two Asterisk Servers
; ****************
; *** SIP.CONF ***
; ****************
;
; Summary:
; - Configuration for SIP protocol
; - All phone registration information resides here
;
; Server: R01
; File location: /etc/asterisk/sip.conf
; *****************
;
[general]
disallow=all
allow=ulaw
canreinvite=no
register => trunk-S01-R01:welcome@[IP-add-of-S01]/trunk-S01-R01
[trunk-R01-S01]
type=friend
secret=welcome
host=dynamic
context=from-S01
;username=trunk-S01-R01
[1000]
type=friend
context=phones
host=dynamic
username=1000
secret=abc123
; ****************
; *** SIP.CONF ***
; ****************
;
; Summary:
; - Configuration for SIP protocol
; - All phone registration information resides here
;
; Server: S01
; File location: /etc/asterisk/sip.conf
; ***************
;
[general]
disallow=all
allow=ulaw
canreinvite=no
register => trunk-R01-S01:welcome@[IP-add-of-R01]/trunk-S01-R01
[trunk-S01-R01]
type=friend
secret=welcome
host=dynamic
context=from-R01
;username=trunk-R01-S01
[2000]
type=friend
context=phones
host=dynamic
username=2000
secret=abc123
DIALPLAN
;******************
;extensions.conf
;
;Server: R01
;******************
[globals]
[general]
autofallthrough=yes
[Internal]
exten => _1XXX,1,NoOp()
exten => _1XXX,n,Dial(SIP/${EXTEN},30);
exten => _1XXX,n,Playback(the-party-you-are-calling)
exten => _1XXX,n,Hangup()
[External]
exten => _2XXX,1,NoOp()
exten => _2XXX,n,Dial(SIP/trunk-R01-S01/${EXTEN},30)
exten => _2XXX,n,Hangup()
[phones]
include => Internal
include => External
[from-S01]
include => Internal
;******************
;extensions.conf
;
;Server: S01
;******************
[globals]
[general]
autofallthrough=yes
[Internal]
exten => _2XXX,1,NoOp()
exten => _2XXX,n,Verbose(1,I am in Internal)
exten => _2XXX,n,Dial(SIP/${EXTEN},30)
exten => _2XXX,n,Hangup()
[External]
exten => _1XXX,1,NoOp()
exten => _1XXX,n,Verbose(1,I am in External)
exten => _1XXX,n,Dial(SIP/trunk-S01-R01/${EXTEN},30);
exten => _1XXX,n,Playback(the-party-you-are-calling)
exten => _1XXX,n,Hangup()
[phones]
include => Internal
include => External
[from-R01]
include => Internal
>Start Asterisk #asterisk
>Go to Asterisk Console #asterisk -rv
CLI> sip show peers
CLI> sip show registry
Friday, April 9, 2010
SPAN in details (for Asterisk)
Trunk can be T1/E1.
span = [span num], [timing], [line build out], [framing], [coding]
e.g span = 1,0,0,esf,b8zs
This means, the specified trunk is mapped to SPAN 1 of the T1 card. It uses internal clock of card as time source as second parameter is 0. LBO is 0 and it doesn't require to be changed most of the time as cable is not going to be more than 133ft from smart jack. Framing is esf. Coding is b8zs.
[ Also remember, each PRI card should have their own independent clock source ]
In brief, you can say, this particular trunk is esf,b8zs with internal clock as time source.
I would like to write about some other parameters defined in /etc/dahdi/system.conf
span = 1,0,0,esf,b8zs
bchan=1-23 #B-Channel defination
dchan=24 #D-Channel defination
Since bchan+dchan=24, it is T1 trunk configuration.
For E1 trunk, bchan+dchan=31
Also note that FRAMING and CODING is main factor that can distinguish between T1 and E1 trunk.
--------------T1----------------------E1
Framing -- esf / d4------------ ccs / cas
Coding ---- b8zs / ami -------- hdb3 / ami
-----------------------------------------
When you talk about Trunk, you also need to specify the switch type. Switchtype parameter is defined in /etc/asterisk/chan_dahdi.conf . It can be National or dms100 or 5ess
Default Switch: National
Nortel Switch : dms100 [ but it's weird that in my case, i had to use 5ess switchtype to interface my Asterisk Server with Nortel Switch]
Dialogic Fax Server Switch : dms100
So, PRI with following configuration can be said as T1 trunk with esf,b8zs signalling and National switchtype.
#/etc/dahdi/system.conf
span = 1,0,0,esf,b8zs
#/etc/asterisk/dahdi.conf
switchtype = National
Wonderful explaination at :
http://www.asteriskguru.com/tutorials/pri_zaptel.html
http://www.asteriskguru.com/tutorials/pri.html