[Asterisk-Users] * Call Monitoring

Daniel Corbe daniel.junkmail at gmail.com
Mon Feb 21 07:40:37 MST 2005


Okay

here's a quick and dirty little perl script to monitor the PRI Status
and mimic nagios plugin output.

-Daniel


On Mon, 21 Feb 2005 07:50:45 -0600, Brian Roy <mister.roy at gmail.com> wrote:
> On Mon, 21 Feb 2005 08:00:40 -0500, Daniel Corbe
> <daniel.junkmail at gmail.com> wrote:
> > I need to make sure the PRIs connected to my box stay up and I need to
> > make sure calls are not failing for any reason.  Are there any *
> > monitoring packages like this?
> 
> There aren't any specific tools that do exactly what you want afaik.
> It wouldn't take much to taylor a few things yourself though.
> 
> As for the PRI processing calls. You could always drop a call file in
> from the cron every 10 minutes that makes a call out and back in. Then
> you you can run a script that looks over your CDR to verify that the
> call was received. Have it call a specific context or application to
> look for.
> 
> As for calls "failing" this could be a challange. What do you consider
> failing? You could use something like my-swatch to tail the log file
> looking for certain patterns. PRI alarms would be an obvious.
> 
> Might take you a day or so to get these things going, but it would be
> well worth your time and piece of mind.
> 
> -Chuji
>
-------------- next part --------------
#!/usr/bin/perl

###############################################################################
# Michael Jastremski
# Monitor Asterisk PBX via Manager Interface
# http://megaglobal.net/docs/
###############################################################################

# Based upon:
#
# TACI - Trivial Asterisk Call Interface v.02
# Last update 3/30/2004 
# Tony Wasson wasson at azxws.com
#
#
# Modified by Daniel Corbe to monitor PRI spans
# dcorbe at voipinc.com
#
# -Daniel
#

$ENV{'PATH'}='';
$ENV{'BASH_ENV'}=''; 
$ENV{'ENV'}='';
$| = 1; 

use Net::Telnet ();
use File::Basename;
use lib "/usr/local/nagios/libexec"; 
use utils qw(%ERRORS);

my $mgr_user = "nagios";
my $mgr_secret = "XyXyXyXyXy";
my $failed = 0;
my $reason = undef;
my $server_ip = "127.0.0.1";

my $prispan = $ARGV[0];

$tn = new Net::Telnet (Port => 5038,
		       Prompt => '/.*[\$%#>] $/',
		       Output_record_separator => '',
		       Errmode    => 'return'
		       );

$tn->open($server_ip);
$tn->waitfor('/0\n$/');                  	
$tn->print("Action: Login\nUsername: $mgr_user\nSecret: $mgr_secret\n\n");
unless($tn->waitfor('/Authentication accept*/'))
{
    $failed = 1;
    $reason = "Failed Connect";
}
else
{
    $tn->print("Action: Command\n");
    $tn->print("Command: pri show span $prispan\n\n");
    #Response: Follows
    #Primary D-channel: 24
    #Status: Provisioned, Up, Active
    unless($tn->waitfor('/Response: Follows\nPrimary D-channel: (.*)?\nStatus: Provisioned, Up, Active/'))
    {
	$failed = 1;
	$reason = "PRI Span #" . $prispan . " is down";
    }
    else
    {
	$tn->print("Action: Logoff\n\n");
    }
}

print "PRI Span #$prispan is up\n" unless $failed;
print "$reason\n" if $failed;

exit $ERRORS{'CRITICAL'} if $failed;
exit $ERRORS{'OK'};


exit 0;


__END__


TODO:  
    -- Maybe check other variables?


More information about the asterisk-users mailing list