[Asterisk-Users] asterisk nagios plugin

leonimar cape leo_mac_ph at yahoo.com
Wed Feb 22 09:22:04 MST 2006


Hi,

I am using nagios to monitor asterisk via nrpe plugin
and it is working fine. But I want also to monitor the
status of the pri. I have found a plugin which uses
the asterisk manager configuration. But it doesnt
return the result of the command being executed. As
much as I want to include it, I can since I am just a
simple administrator. :)

Hope some can help me.

#!/usr/bin/perl -w

use strict;
use IO::Socket;
use Getopt::Long;

my (
	$host, $username, $password, $verbose, $help,
$command,
	$version,$response,$message,
	$sock,
	$readloop,
	$s
);
my $port = 5038;
my $exitcode = 0;

sub warning {
	$s = shift;
	print "WARNING: $s\n";
	exit(1);
}

sub error {
	$s = shift;
	print "ERROR: $s\n";
	exit(2);
}

sub syntax {
	$s = shift;
	unless ($s =~ /Help:/) {
		$s = "Error: (".$s.")" or $s = 'Unknown';
	}
	print "$s\n" unless ($help);
	print "Syntax: $0 -h <host> -u <username> -p
<password> [-cwv]\n";
	print "* --username -u		Username\n";
	print "* --password -p		Password\n";
	print "* --host -h		Host\n";
	print "  --port -P		Port (if not using $port)\n";
	print "  --command -c		Custom command (instead of
Status)\n";
	print "  --verbose -v		Verbose\n";
	print "  --help -h		This help\n";
	exit(3);
}

Getopt::Long::Configure('bundling');
GetOptions
	("p=s" => \$password, "password=s" => \$password,
	 "u=s" => \$username, "username=s" => \$username,
	 "h=s" => \$host,     "host=s"     => \$host,
	 "P=s" => \$port,     "port=s"     => \$port,
	 "c=s" => \$command,  "command=s"  => \$command,
	 "H" =>   \$help,     "help"       => \$help,
	 "v" =>   \$verbose,  "verbose"    => \$verbose);

syntax("Help:") if ($help);
syntax("Missing username") unless
(defined($username));
syntax("Missing password") unless
(defined($password));
syntax("Missing host") unless (defined($host));

unless ($sock = IO::Socket::INET->new(PeerAddr =>
$host, PeerPort => $port, Proto => 'tcp')) {
	print("Could not connect to asterisk server
".$host.":".$port."\n");
	exit(2);
}
$version = <$sock>;
print $version if ($verbose);

print $sock "Action: Login\r\nUsername:
$username\r\nSecret: $password\r\n\r\n";
print "Action: Login\r\nUsername: $username\r\nSecret:
$password\r\n\r\n" if ($verbose);
$response = <$sock>; $message = <$sock>; $s = <$sock>;
print $response.$message if ($verbose);
print $s if ($verbose);

if ($response =~ /Response:\s+(.*)[\r\n]/) {
	$response = $1;
	unless ($response =~ /Success/) {
		exit(1);
	}
}

print $sock "Action: Logoff\r\n\r\n";
print "Nagios responded ok.";
0


Regards,

Leonimar 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the asterisk-users mailing list