#! /usr/bin/perl -wT
#
# Check_apc_ups - Check APC UPS status via SNMP
# Shamelessly copied from check_breeze.pl
#
# To do:
# - Send SNMP queries directly, instead of forking `snmpget`.
# - Make the status less verbose. Maybe we can send an "onLine, time
# remaining: hh:mm:ss" if all is well, and a list of specific problems
# if something is broken.
use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_H $opt_T $opt_t $opt_R $opt_r
$opt_L $opt_l $PROGNAME);
use lib "/usr/local/nagios/libexec";
use utils qw(%ERRORS &print_revision &support &usage);
sub print_help ();
sub print_usage ();
sub get_snmp_int_val ($);
sub escalate_exitval ($);
$ENV{'PATH'}='';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
Getopt::Long::Configure('bundling');
GetOptions
("V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
"T=s" => \$opt_T, "temp-critical" => \$opt_T,
"t=s" => \$opt_t, "temp-warning" => \$opt_t,
"R=s" => \$opt_R, "runtime-critical" => \$opt_R,
"r=s" => \$opt_r, "runtime-warning" => \$opt_r,
"L=s" => \$opt_L, "load-critical" => \$opt_L,
"l=s" => \$opt_l, "load-warning" => \$opt_l,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1771 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
($opt_H) || ($opt_H = shift) || usage("Host name/address not specified\n");
my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
($host) || usage("Invalid host: $opt_H\n");
# Defaults
$opt_R *= 60 * 100 if (defined $opt_R); # Convert minutes to secs/100
$opt_r *= 60 * 100 if (defined $opt_R);
my $tempcrit = $opt_T || 60;
my $tempwarn = $opt_t || 40;
my $runtimecrit = $opt_R || 30 * 60 * 100; # Secs / 100
my $runtimewarn = $opt_r || 60 * 60 * 100;
my $loadcrit = $opt_L || 85;
my $loadwarn = $opt_l || 50;
if ($tempcrit !~ /\d+/) { usage ("Invalid critical temperature threshold.\n"); }
if ($tempwarn !~ /\d+/) { usage ("Invalid critical temperature threshold.\n"); }
if ($runtimecrit !~ /\d+/) {
usage ("Invalid critical run time threshold.\n");
}
if ($runtimewarn !~ /\d+/) {
usage ("Invalid warning run time threshold.\n");
}
if ($loadcrit !~ /\d+/ || $loadcrit < 0 || $loadcrit > 100) {
usage ("Invalid critical load threshold.\n");
}
if ($loadwarn !~ /\d+/ || $loadwarn < 0 || $loadwarn > 100) {
usage ("Invalid warning load threshold.\n");
}
# APC UPS OIDs
# APC MIBs are available at ftp://ftp.apcftp.com/software/pnetmib/mib
my $upsBasicOutputStatus = ".1.3.6.1.4.1.318.1.1.1.4.1.1.0";
my $upsBasicBatteryStatus = ".1.3.6.1.4.1.318.1.1.1.2.1.1.0";
my $upsAdvInputLineFailCause = ".1.3.6.1.4.1.318.1.1.1.3.2.5.0";
my $upsAdvBatteryTemperature = ".1.3.6.1.4.1.318.1.1.1.2.2.2.0";
my $upsAdvBatteryRunTimeRemaining = ".1.3.6.1.4.1.318.1.1.1.2.2.3.0";
my $upsAdvBatteryReplaceIndicator = ".1.3.6.1.4.1.318.1.1.1.2.2.4.0";
my $upsAdvOutputLoad = ".1.3.6.1.4.1.318.1.1.1.4.2.3.0";
my $upsAdvTestDiagnosticsResults = ".1.3.6.1.4.1.318.1.1.1.7.2.3.0";
my @outputStatVals = (
[ undef, undef ], # pad 0
[ undef, undef ], # pad 1
[ "onLine", $ERRORS{'OK'} ], # 2
[ "onBattery", $ERRORS{'WARNING'} ], # 3
[ "onSmartBoost", $ERRORS{'WARNING'} ], # 4
[ "timedSleeping", $ERRORS{'WARNING'} ], # 5
[ "softwareBypass", $ERRORS{'WARNING'} ], # 6
[ "off", $ERRORS{'CRITICAL'} ], # 7
=1= |