This is a Nagios check utility to check the status of your APC InfrastruXure gear.
#!/usr/bin/perl -w
use strict;
use lib "/usr/local/nagios/libexec" ;
use utils qw($TIMEOUT %ERRORS &print_revision &support);
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_C $opt_H);
$PROGNAME = "check_apc";
sub print_help ();
sub print_usage ();
$ENV{'PATH'}='';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
Getopt::Long::Configure('bundling');
GetOptions
("V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
"C=s" => \$opt_C, "Community=s" => \$opt_C,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.0 $'); #'
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
print_usage() unless ($opt_H);
my $host = $1 if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0]+(\.[a-zA-Z][-a-zA-Z0]+)*)$/);
print_usage() unless ($host);
$opt_C = shift unless ($opt_C);
unless($opt_C) { $opt_C = "public"; }
my $comm=$opt_C;
my $res = `/usr/local/nagios/libexec/check_snmp -H $host -o SNMPv2-SMI::enterprises.318.1.1.1.4.1.1.0 -C $comm`;
chomp $res;
unless($res =~ /^SNMP OK/) {
# It's not responding properly
printf("APC CRITICAL - Bad");
exit(2);
} elsif ($res =~ /2$/) {
# It's responding ok, and returning a 2
printf("APC OK - 2");
exit(0);
} else {
# Hmmm, it's responding ok, but not returning a 2
$res =~ /(\d+)$/;
printf("APC CRITICAL - $1");
exit(2);
}
sub print_usage () {
print "Usage: $PROGNAME -H <host> [-C <community>]\n";
exit(0);
}
sub print_help () {
print_revision($PROGNAME,'$Revision: 1.0 $');
print "Check the power status of your APC Symmetra/InfraStruXure\n";
print "Copyright (c) 2005 Matthew Keller\n";
print "\n";
print_usage();
print "\n";
print "<community> = SNMP Read Community.\n\n";
support();
}