Trunk not registered.
The script provided and the Monitor Trunk Failure feature work OK but it only notifies you when a call fails on everything except BUSY and CANCEL. I need to know before a call fails, like when the trunk is not registered.
Here is the perl script we used for that and the configuration file that goes with it (and Jim Hribnak, thank you):
#!/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 domain nucleus.com
####
###############################################################################################################################
####
#### Create the following 2 files in /etc/asterisk
####
#### if 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.conf");
open(SIPTRUNKS,"</etc/asterisk/trunkalerts_sip.conf");
###############################################################################################################################
####
#### SIP Related Code
####
#print "============================================================\n";
#print "SIP Trunk information\n";
#print "============================================================\n";
while (<SIPTRUNKS>) {
chomp;
$siptrunks = `asterisk -rx "sip show registry" |grep \"$_\" | awk '{print $4}'`;
#print "siptrunks = $siptrunks\n";
if ($siptrunks =~ "Registered") {
# print "$_ is up\n" ;
} else {
mailalert();
print "houston we have a problem\n";
print "$_ trunk is not registering\n";
}
} #end of while loop (read SIP file)
###############################################################################################################################
####
#### IAX Related Code
####
#print "\n\n============================================================\n";
#print "IAX2 Trunk information\n";
#print "============================================================\n";
while (<IAXTRUNKS>) {
chomp;
$iaxtrunks = `/usr/sbin/asterisk -rx "iax2 show registry" |/bin/grep \"$_\" | awk '{print $5}'`;
#$iaxtrunks = `asterisk -rx "iax2 show registry" |grep \"$_\" | awk '{print $5}'`;
#print "iaxtrunks = $iaxtrunks\n";
if ($iaxtrunks =~ "Registered") {
#print "$_ is up\n" ;
} else {
mailalert();
print "houston we have a problem\n";
print "$_ trunk is not registering\n";
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: <user\@domain.com>\n";
my $reply_to = "Reply-to: <user\@domain.com\n";
my $subject = "Subject: $_ is DOWN!!!!\n";
my $content = "TRUNK $_ is DOWN!!!!\n";
my $send_to = "To:<user\@domain.com>\n";
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);
print "An email has been sent!\n\n";
}
trunkalerts_iax.conf and trunkalerts_sip.conf are text files and contain the IP address : port of your provider (SIP or IAX)
xx.xx.xx.xx:4569
Each trunk is on a separate line.
The file is trunkalerts.pl placed in the /usr/sbin. The iax and sip files are trunkalerts_iax.conf and trunkalerts_sip.conf placed in the /etc/asterisk so they can be edited in the FreePBX, Tools, Config Edit screen.
I had problems with this script at first but eventually my boss got it working on his TB machine at home and we cloned it to our PIAF machine at the office and it works.
I have it going to my cell phone so I know when it is down. You create a cron job and run it at whatever interval you think is appropriate for your situation.
Thanks for all of the insightful information.