Reply
 
Thread Tools Display Modes
  #11  
Old 10-08-08, 07:20 PM
klingon888 klingon888 is offline
Guru
 
Join Date: Nov 2007
Posts: 77
Philippe Lindheimer's description of how this shld work - http://www.freepbx.org/forum/freepbx...es-any-scripts

I've put the script that TDF referenced on one of my trunks and I'll let you know if it works when this trunk fails! Managed to clean out the syntax errors. Code below. Can others try it out too?

#!/bin/bash

EMAIL=xxx@xxx.com

DATE=`date "+%m-%d-%Y %Hh%M"`

HOST=`hostname`

CID=`echo $agi_callerid`
CIDNAME=`echo $agi_calleridname`
EXTENSION=`echo $agi_extension`
CHANNEL=`echo $agi_channel`

REPORT=$EXTENSION

if [ "$EXTENSION" = "s-CHANUNAVAIL" ]
then
REPORT="Channel Unavailable"
fi

# Message Formating

MSG="\n\n A call from channel [$CHANNEL] \n"
MSG="$MSG With CID : [$CIDNAME] - [$CID] \n\n"
MSG="$MSG has failed on host [$HOST] at $DATE \n\n"
MSG="$MSG with error : [$REPORT] \n\n\n"

# log

echo >> /var/log/asterisk/trunkfailure.log
echo "$MSG" >> /var/log/asterisk/trunkfailure.log

# Send an email

echo -e "$MSG" | mail -s " - Failed call on host [$HOST] -" "$EMAIL"
Reply With Quote
  #12  
Old 10-08-08, 09:21 PM
thunderheart thunderheart is offline
Senior Member
 
Join Date: Oct 2007
Posts: 253
Ok ... worked for me.
What I did was put the script in:

/var/lib/asterisk/agi-bin/trunk_monitor.agi

Then in 'Monitor Trunk Failure' I put 'trunk_monitor.agi'

Made sure the script was asterisk:asterisk and +x

Changed the secret for my trunk (to simulate a failure) and then made an outgoing call. Instantly got the email delivered.

So you don't put the full pathname in the 'Monitor Trunk Failure' field. Just the filename. FreePBX looks for it in /var/lib/asterisk/agi-bin

Seems a little stiff to me but there it is. The script posted above by Klingon is a little buggy. Try it like this:

#!/bin/bash

declare -a array
while read -e ARG && [ "$ARG" ] ; do
array=(` echo $ARG | sed -e 's/://'`)
export ${array[0]}=${array[1]}
done

EMAIL=you@your.domain

DATE=`date "+%m-%d-%Y %H:%M"`

HOST=`hostname`

CID=`echo $agi_callerid`
CIDNAME=`echo $agi_calleridname`
EXTENSION=`echo $agi_extension`
CHANNEL=`echo $agi_channel`

REPORT=$EXTENSION

if [ "$EXTENSION" = "s-CHANUNAVAIL" ]
then
REPORT="Channel Unavailable"
fi

# Message Formating

MSG="\n\n A call from channel [$CHANNEL] \n"
MSG="$MSG With CID : [$CIDNAME] - [$CID] \n\n"
MSG="$MSG has failed on host [$HOST] at $DATE \n\n"
MSG="$MSG with error : [$REPORT] \n\n"

# log

echo >> /var/log/asterisk/trunkfailure.log
echo -e "$MSG" >> /var/log/asterisk/trunkfailure.log

# Send an email

echo -e "$MSG" | mail -s " - Failed call on host [$HOST] -" "$EMAIL"

Works a bit better. Still not convinced if this really helps much. How would ya know if incoming calls were broken? Fortunately, my carrier has a fail-over number which I set to one of our ZAP DNs. As far as I know we've never had a failover though. VOIPStreet is pretty darn reliable.

Dallas

Last edited by thunderheart : 10-09-08 at 12:24 AM.
Reply With Quote
  #13  
Old 10-09-08, 01:08 AM
gbrook gbrook is offline
Member
 
Join Date: Dec 2007
Location: Brisbane Australia
Posts: 70
Originally Posted by TheShniz View Post
^^^ I'm interested
How do I attach or please provide your email address

Cheers
Garry
__________________
Location: Caboolture Australia
Reply With Quote
  #14  
Old 10-10-08, 02:51 PM
joevoirol joevoirol is offline
Junior Member
 
Join Date: Aug 2008
Location: Monroeville, Indiana
Posts: 14
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.
Reply With Quote
  #15  
Old 10-10-08, 11:11 PM
leonash07 leonash07 is offline
Junior Member
 
Join Date: May 2008
Posts: 5
Originally Posted by joevoirol View Post

....
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 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.
Joe/Anyone,
When I tested the perl script
root@pbx:/usr/sbin $ perl trunkalerts.pl
It output as follows:
sip.callwithus.com is up
proxy01.sipphone.com is up.

However, when the cron job runs I get following error message on /var/spool/mail/root file when the cron job runs.
Error:
sh: asterisk: command not found
sh: asterisk: command not found

Script output is as follows:
sip.callwithus.com trunk is not registering
proxy01.sipphone.com trunk is not registering

I'm not sure what I'm doing wrong here. It seems like when the job runs it doesn't understand asterisk command.
If you know how to fix this or guide me on this I would appreciate it.

Leo
Reply With Quote
  #16  
Old 10-11-08, 06:47 AM
jroper jroper is offline
Guru
 
Join Date: Oct 2007
Posts: 3,333
Your faith in me is touching, but probably misplaced;-)

I think it might be a permissions or ownership,either of the cron job, or the script or the conf files

Joe
Reply With Quote
  #17  
Old 10-11-08, 08:23 AM
klingon888 klingon888 is offline
Guru
 
Join Date: Nov 2007
Posts: 77
Change :

$siptrunks = `asterisk -rx "sip show registry" |grep \"$_\" | awk '{print $4}'`;

To:

$siptrunks = `/usr/sbin/asterisk -rx "sip show registry" |grep \"$_\" | awk '{print $4}'`;
Reply With Quote
  #18  
Old 10-11-08, 09:47 AM
leonash07 leonash07 is offline
Junior Member
 
Join Date: May 2008
Posts: 5
klingon888,

I made the change and it solve my problem. Thank so much!!!!
Reply With Quote
  #19  
Old 11-30-08, 11:24 PM
marv marv is offline
Member
 
Join Date: Nov 2007
Location: Atlanta, GA
Posts: 80
Great trunk monitoring script
The monitoring of the trunk registrations is exactly what I've been looking for. I have been troubleshooting and monitoring the trunk providers I have now because people have been telling me their calls were not going through. I like the proactive approach of assuring the trunk is registered versus you can't make an outbound call failure. Just makes logical sense to me. I believe if more people were to install this script and monitor their trunks, they might see that their trunks are having problems that they may not have been aware of.

I personally have it setup to run every minute right now. I had a strange occurrence yesterday where I lost all of my registrations and I didn't realize it until I tried making an outbound call today. I might tweak the script a little down the road for more bells and whistles... but it's great now. Thanks guys!
Reply With Quote
  #20  
Old 01-30-09, 10:59 PM
shane shane is offline
Junior Member
 
Join Date: Dec 2008
Location: Benicia, Ca
Posts: 29
I would love to get this script working but for the life of me cannot figure out why I am getting the following error when I try to run the script from the shell using the following command:
root@pbx:/usr/sbin $./trunkalerts.pl

I am getting the following error:
./trunkalerts.pl: line 18: syntax error near unexpected token `IAXTRUNKS,"/etc/asterisk/trunkalerts_iax.conf");

Any help would be greatly appreciated.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:03 PM.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007-2008, Ward Mundy & Associates