Monitoring VoIP Trunks

Using VoIP lines to save on long distance and/or international calls is smart but real savings come in when you are able to dump your landline and go all the way with VoIP.

Over the years the technology has matured to the point where its possible to provide reliable phone service over the Internet. Vonage being a pioneer in this market and recently major telcos offering this service to their existing client base has begun to erode the excepticism on VoIP.

When migrating for landline to VoIP its very important for the service to just work. People expect the phone to have a dial tone when its picked up just as they expect the lights to come on when the switch is flipped. It has become a utility.

Even though VoIP has come a long way, its important to keep an eye on it. Because voice now travels the same path that data those, there is a wide variety of tools available to measure and monitor performance and availability.

The script below allows you to e-mail you the status of a SIP or IAX trunk on an asterisk based VoIP phone system. The script scheduled every 5 minutes would check the status of the registration status for the specific trunk.

We being by creating two files in the /etc/asterisk directory.

  • trunkalerts_iax.txt
  • trunkalerts_sip.txt

Each file contains the registration domain and port as shown when querying sip and iax registrations.

Example of trunkalerts_sip.txt

sip.broadvoice.com:5060

Script: (download here)

#!/usr/bin/perl

################################################## #############################
##################### ###########################
####
#### Trunk Alerts script written by Jim Hribnak Oct 7th 2007
#### if there is any questions please feel free to drop me an email at jimh at d
omain nucleus.com
#### Called using Cron job

################################################## #############################
##################### ###########################
####
#### Create the following 2 files in /etc/asterisk
####
#### in the files below add the hosts entry from asterisk -rx “sip show registry
” and
#### from asterisk -rx “iax2 show registry”.
####

open(IAXTRUNKS,”/etc/asterisk/trunkalerts_iax.txt”);
open(SIPTRUNKS,”/etc/asterisk/trunkalerts_sip.txt”);

################################################## #############################
##################### ###########################
####
#### SIP Related Code
####

#print “================================================= ===========n”;
#print “SIP Trunk information”;
#print “================================================= ===========n”;

while (<SIPTRUNKS>) {
chomp;
$siptrunks = `/usr/sbin/asterisk -rx “sip show registry” |grep “$_” | awk ‘{pr
int $4}’`;

#print “siptrunks = $siptrunks”;
if ($siptrunks =~ “Registered”) {
#print “$_ is upn” ;

} else {
#print “We have a problem”;
print “$_ trunk is not registering”;
mailalert();

}
} #end of while loop (read SIP file)

################################################## #############################
##################### ###########################
####
#### IAX Related Code
####

#print “nn============================================= ===============n”;
#print “IAX2 Trunk information”;
#print “================================================= ===========n”;

while (<IAXTRUNKS>) {
chomp;
$iaxtrunks = `/usr/sbin/asterisk -rx “iax2 show registry” |/bin/grep “$_” | aw
k ‘{print $5}’`;

#print “iaxtrunks = $iaxtrunks”;

if ($iaxtrunks =~ “Registered”) {
#print “$_ is upn” ;

} else {
mailalert();
print “We have a problem”;
print “$_ trunk is not registering”;
my $subject = “Subject: TRUNK $iaxtrunks is DOWN!!!!n”;
my $content = “TRUNK $iaxtrunks is DOWN!!!!n”;

}
} #end of while loop (read SIP file)

################################################## ########################
####
#### Email Subroutines
#### Change anywhere below where there is an email address an email addres
#### must have @ as perl needs to escape the @ symbol
####
################################################## ########################

sub mailalert {

my $sendmail = “/usr/sbin/sendmail -t”;
my $from= “FROM: <pbx@domain.com>n”; #replace xxx with your FROM email ID
my $reply_to = “Reply-to: <support@domain.com”;
my $subject = “Subject: $_ is DOWN!!!!n”;
my $content = “TRUNK $_ is DOWN!!!!n”;
my $send_to = “To:<support@domain.com>n”; #replace xxx with your TO email ID
open(SENDMAIL, “|$sendmail”) or die “Cannot open $sendmail: $!”;
print SENDMAIL $from;
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $send_to;
print SENDMAIL $content;
close(SENDMAIL);

#log
my $logfile = “/var/log/asterisk/trunkfailure.log”;
my $date = localtime();
my $logmsg = “$date TRUNK $_ is down”;
open LOGFILE, “>>$logfile” or die “cannot open logfile $logfile for append: $!”;
print LOGFILE $logmsg, “n”;
close LOGFILE;

print “An email has been sent!nn”;
}

[ad]

Connecting Two Asterisk @Home Servers via IAX2

I have found very scattered and little documentation on connecting two asterisk servers via IAX2, so I decided to put these words together. IAX2 is a protocol that plays nice with NAT and very powerful.

The most important thing to keep in mind is the client/server relationship when calling/forwarding from one server to another. So when you are calling from Server A to Server B, then Server A is the “Client” and Server B is the “Server” and of course if you are calling from Server B to Server A, then Server B would be the “Client” and Server A would be the “Server”.

MORE…

The next thing to know is that “Trunks” allow endpoints to establish a communication channel between each other, but Outbound & Inbound Routes also need to be established.

Home Server:

TRUNKS:

Add IAX2 Trunk

OUTGOING SETTINGS

Trunk name: SOHO
Peer Details:
auth=rsa
context=from-pstn
host=Office server IP address/dns address
inkeys=otherserver
secret=
type=friend
username=home

INCOMING SETTINGS

User Context: office
User Details:
context=from-pstn
host=dynamic
outkey=otherservervoip
secret=
type=friend
username=office

Registration String:
home:@

OUTBOUND ROUTING:

Dial Patterns:
7|.

Trunk Sequence:
Select trunk just built.

Office Server:

TRUNKS:

Add IAX2 Trunk

OUTGOING SETTINGS

Trunk name: SOHO
Peer Details:
auth=rsa
context=from-pstn
host=home server IP address/dns address
inkeys=otherserver
secret=
type=friend
username=office

INCOMING SETTINGS

User Context: home
User Details:
context=from-pstn
host=dynamic
outkey=otherservervoip
secret=
type=friend
username=home

Registration String:
office:@

OUTBOUND ROUTING:

Dial Patterns:
7|.

Trunk Sequence:
Select trunk just built.