summaryrefslogtreecommitdiffstats
path: root/contrib/check_apc_ups.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_apc_ups.pl')
-rw-r--r--contrib/check_apc_ups.pl307
1 files changed, 0 insertions, 307 deletions
diff --git a/contrib/check_apc_ups.pl b/contrib/check_apc_ups.pl
deleted file mode 100644
index 6bf1766..0000000
--- a/contrib/check_apc_ups.pl
+++ /dev/null
@@ -1,307 +0,0 @@
1#! /usr/bin/perl -wT
2#
3# Check_apc_ups - Check APC UPS status via SNMP
4# Shamelessly copied from check_breeze.pl
5#
6# To do:
7# - Send SNMP queries directly, instead of forking `snmpget`.
8# - Make the status less verbose. Maybe we can send an "onLine, time
9# remaining: hh:mm:ss" if all is well, and a list of specific problems
10# if something is broken.
11
12use strict;
13use Getopt::Long;
14use vars qw($opt_V $opt_h $opt_H $opt_T $opt_t $opt_R $opt_r
15 $opt_L $opt_l $PROGNAME);
16use lib "/usr/local/nagios/libexec";
17use utils qw(%ERRORS &print_revision &support &usage);
18
19sub print_help ();
20sub print_usage ();
21sub get_snmp_int_val ($);
22sub escalate_exitval ($);
23
24$ENV{'PATH'}='';
25$ENV{'BASH_ENV'}='';
26$ENV{'ENV'}='';
27
28Getopt::Long::Configure('bundling');
29GetOptions
30 ("V" => \$opt_V, "version" => \$opt_V,
31 "h" => \$opt_h, "help" => \$opt_h,
32 "T=s" => \$opt_T, "temp-critical" => \$opt_T,
33 "t=s" => \$opt_t, "temp-warning" => \$opt_t,
34 "R=s" => \$opt_R, "runtime-critical" => \$opt_R,
35 "r=s" => \$opt_r, "runtime-warning" => \$opt_r,
36 "L=s" => \$opt_L, "load-critical" => \$opt_L,
37 "l=s" => \$opt_l, "load-warning" => \$opt_l,
38 "H=s" => \$opt_H, "hostname=s" => \$opt_H);
39
40if ($opt_V) {
41 print_revision($PROGNAME,'$Revision: 1771 $');
42 exit $ERRORS{'OK'};
43}
44
45if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
46
47($opt_H) || ($opt_H = shift) || usage("Host name/address not specified\n");
48my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
49($host) || usage("Invalid host: $opt_H\n");
50
51# Defaults
52
53$opt_R *= 60 * 100 if (defined $opt_R); # Convert minutes to secs/100
54$opt_r *= 60 * 100 if (defined $opt_R);
55
56my $tempcrit = $opt_T || 60;
57my $tempwarn = $opt_t || 40;
58my $runtimecrit = $opt_R || 30 * 60 * 100; # Secs / 100
59my $runtimewarn = $opt_r || 60 * 60 * 100;
60my $loadcrit = $opt_L || 85;
61my $loadwarn = $opt_l || 50;
62
63if ($tempcrit !~ /\d+/) { usage ("Invalid critical temperature threshold.\n"); }
64if ($tempwarn !~ /\d+/) { usage ("Invalid critical temperature threshold.\n"); }
65
66if ($runtimecrit !~ /\d+/) {
67 usage ("Invalid critical run time threshold.\n");
68}
69if ($runtimewarn !~ /\d+/) {
70 usage ("Invalid warning run time threshold.\n");
71}
72
73if ($loadcrit !~ /\d+/ || $loadcrit < 0 || $loadcrit > 100) {
74 usage ("Invalid critical load threshold.\n");
75}
76if ($loadwarn !~ /\d+/ || $loadwarn < 0 || $loadwarn > 100) {
77 usage ("Invalid warning load threshold.\n");
78}
79
80
81# APC UPS OIDs
82# APC MIBs are available at ftp://ftp.apcftp.com/software/pnetmib/mib
83my $upsBasicOutputStatus = ".1.3.6.1.4.1.318.1.1.1.4.1.1.0";
84my $upsBasicBatteryStatus = ".1.3.6.1.4.1.318.1.1.1.2.1.1.0";
85my $upsAdvInputLineFailCause = ".1.3.6.1.4.1.318.1.1.1.3.2.5.0";
86my $upsAdvBatteryTemperature = ".1.3.6.1.4.1.318.1.1.1.2.2.2.0";
87my $upsAdvBatteryRunTimeRemaining = ".1.3.6.1.4.1.318.1.1.1.2.2.3.0";
88my $upsAdvBatteryReplaceIndicator = ".1.3.6.1.4.1.318.1.1.1.2.2.4.0";
89my $upsAdvOutputLoad = ".1.3.6.1.4.1.318.1.1.1.4.2.3.0";
90my $upsAdvTestDiagnosticsResults = ".1.3.6.1.4.1.318.1.1.1.7.2.3.0";
91
92my @outputStatVals = (
93 [ undef, undef ], # pad 0
94 [ undef, undef ], # pad 1
95 [ "onLine", $ERRORS{'OK'} ], # 2
96 [ "onBattery", $ERRORS{'WARNING'} ], # 3
97 [ "onSmartBoost", $ERRORS{'WARNING'} ], # 4
98 [ "timedSleeping", $ERRORS{'WARNING'} ], # 5
99 [ "softwareBypass", $ERRORS{'WARNING'} ], # 6
100 [ "off", $ERRORS{'CRITICAL'} ], # 7
101 [ "rebooting", $ERRORS{'WARNING'} ], # 8
102 [ "switchedBypass", $ERRORS{'WARNING'} ], # 9
103 [ "hardwareFailureBypass", $ERRORS{'CRITICAL'} ], # 10
104 [ "sleepingUntilPowerReturn", $ERRORS{'CRITICAL'} ], # 11
105 [ "onSmartTrim", $ERRORS{'WARNING'} ], # 12
106);
107
108my @failCauseVals = (
109 undef,
110 "noTransfer",
111 "highLineVoltage",
112 "brownout",
113 "blackout",
114 "smallMomentarySag",
115 "deepMomentarySag",
116 "smallMomentarySpike",
117 "largeMomentarySpike",
118 "selfTest",
119 "rateOfVoltageChnage",
120);
121
122my @battStatVals = (
123 [ undef, undef ], # pad 0
124 [ undef, undef ], # pad 1
125 [ "batteryNormal", $ERRORS{'OK'} ], # 2
126 [ "batteryLow", $ERRORS{'CRITICAL'} ], # 3
127);
128
129my @battReplVals = (
130 [ undef, undef ], # pad 0
131 [ "noBatteryNeedsReplacing", $ERRORS{'OK'} ], # 1
132 [ "batteryNeedsReplacing", $ERRORS{'CRITICAL'} ], # 2
133);
134
135my @diagnosticsResultsVals = (
136 [ undef, undef ], # pad 0
137 [ "OK", $ERRORS{'OK'} ], # 1
138 [ "failed", $ERRORS{'CRITICAL'} ], # 2
139 [ "invalidTest", $ERRORS{'CRITICAL'} ], # 3
140 [ "testInProgress", $ERRORS{'OK'} ], # 4
141);
142
143my $exitval = $ERRORS{'UNKNOWN'};
144my $data;
145my $onbattery = 3;
146
147$data = get_snmp_int_val( $upsBasicOutputStatus );
148
149print "Output status: ";
150if (defined ($data) && defined ($outputStatVals[$data][0])) {
151 print "$outputStatVals[$data][0] | ";
152 escalate_exitval($outputStatVals[$data][1]);
153} else {
154 print "unknown | ";
155}
156
157$data = get_snmp_int_val( $upsAdvBatteryRunTimeRemaining );
158
159print "Rem time: ";
160if (defined ($data)) {
161 my $hrs = int($data / (60 * 60 * 100)); # Data is hundredths of a second
162 my $mins = int($data / (60 * 100)) % 60;
163 my $secs = ($data % 100) / 100;
164 printf "%d:%02d:%05.2f | ", $hrs, $mins, $secs;
165 if ($data <= $runtimecrit) {
166 escalate_exitval($ERRORS{'CRITICAL'});
167 } elsif ($data <= $runtimewarn) {
168 escalate_exitval($ERRORS{'WARNING'});
169 } else {
170 escalate_exitval($ERRORS{'OK'});
171 }
172} else {
173 print "unknown | ";
174}
175
176$data = get_snmp_int_val( $upsBasicBatteryStatus );
177
178print "Battery status: ";
179if (defined ($data) && defined ($battStatVals[$data][0])) {
180 my $failcause = "unknown";
181 my $fc = get_snmp_int_val( $upsAdvInputLineFailCause );
182 if ($data == $onbattery) {
183 if (defined ($failCauseVals[$fc])) { $failcause = $failCauseVals[$fc]; }
184 print "$battStatVals[$data][0] ($failcause) | ";
185 } else {
186 print "$battStatVals[$data][0] | ";
187 }
188 escalate_exitval($battStatVals[$data][1]);
189} else {
190 print "unknown | ";
191}
192
193$data = get_snmp_int_val( $upsAdvBatteryTemperature );
194
195print "Battery temp(C): ";
196if (defined ($data)) {
197 print "$data | ";
198 if ($data >= $tempcrit) {
199 escalate_exitval($ERRORS{'CRITICAL'});
200 } elsif ($data >= $tempwarn) {
201 escalate_exitval($ERRORS{'WARNING'});
202 } else {
203 escalate_exitval($ERRORS{'OK'});
204 }
205} else {
206 print "unknown | ";
207}
208
209$data = get_snmp_int_val( $upsAdvBatteryReplaceIndicator );
210
211print "Battery repl: ";
212if (defined ($data) && defined ($battReplVals[$data][0])) {
213 print "$battReplVals[$data][0] | ";
214 escalate_exitval($battReplVals[$data][1]);
215} else {
216 print "unknown | ";
217}
218
219$data = get_snmp_int_val( $upsAdvOutputLoad );
220
221print "Output load (%): ";
222if (defined ($data)) {
223 print "$data | ";
224 if ($data >= $loadcrit) {
225 escalate_exitval($ERRORS{'CRITICAL'});
226 } elsif ($data >= $loadwarn) {
227 escalate_exitval($ERRORS{'WARNING'});
228 } else {
229 escalate_exitval($ERRORS{'OK'});
230 }
231} else {
232 print "unknown | ";
233}
234
235$data = get_snmp_int_val( $upsAdvTestDiagnosticsResults );
236
237print "Diag result: ";
238if (defined ($data) && defined ($diagnosticsResultsVals[$data][0])) {
239 print "$diagnosticsResultsVals[$data][0]\n";
240 escalate_exitval($diagnosticsResultsVals[$data][1]);
241} else {
242 print "unknown\n";
243}
244
245
246exit $exitval;
247
248
249sub print_usage () {
250 print "Usage: $PROGNAME -H <host> -T temp -t temp -R minutes -r minutes\n";
251 print " -L percent -l percent\n";
252}
253
254sub print_help () {
255 print_revision($PROGNAME,'$Revision: 1771 $');
256 print "Copyright (c) 2001 Gerald Combs/Jeffrey Blank/Karl DeBisschop
257
258This plugin reports the status of an APC UPS equipped with an SNMP management
259module.
260
261";
262 print_usage();
263 print "
264-H, --hostname=HOST
265 Name or IP address of host to check
266-T --temp-critical
267 Battery degrees C above which a CRITICAL status will result (default: 60)
268-t --temp-warning
269 Battery degrees C above which a WARNING status will result (default: 40)
270-R --runtime-critical
271 Minutes remaining below which a CRITICAL status will result (default: 30)
272-r --runtime-warning
273 Minutes remaining below which a WARNING status will result (default: 60)
274-L --load-critical
275 Output load pct above which a CRITICAL status will result (default: 85
276-l --load-warning
277 Output load pct above which a WARNING status will result (default: 50
278
279";
280 support();
281}
282
283sub get_snmp_int_val ($) {
284 my $val=0;
285 my $oid = shift(@_);
286
287 $val = `/usr/bin/snmpget $host public $oid 2> /dev/null`;
288 my @test = split(/ /,$val,3);
289
290 return undef unless (defined ($test[2]));
291
292 if ($test[2] =~ /\(\d+\)/) { # Later versions of UCD SNMP
293 ($val) = ($test[2] =~ /\((\d+)\)/);
294 } elsif ($test[2] =~ /: \d+/) {
295 ($val) = ($test[2] =~ /: (\d+)/);
296 } else {
297 $val = $test[2];
298 }
299
300 return $val;
301}
302
303sub escalate_exitval ($) {
304 my $newval = shift(@_);
305
306 if ($newval > $exitval) { $exitval = $newval; }
307}