diff options
Diffstat (limited to 'web/attachments/66456-nagios-plugins-1.3.1-check-apc-ups.patch')
| -rw-r--r-- | web/attachments/66456-nagios-plugins-1.3.1-check-apc-ups.patch | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/web/attachments/66456-nagios-plugins-1.3.1-check-apc-ups.patch b/web/attachments/66456-nagios-plugins-1.3.1-check-apc-ups.patch new file mode 100644 index 0000000..ec5f72b --- /dev/null +++ b/web/attachments/66456-nagios-plugins-1.3.1-check-apc-ups.patch | |||
| @@ -0,0 +1,220 @@ | |||
| 1 | diff -ruN nagios-plugins-1.3.1/contrib/check_apc_ups.pl nagios-plugins-1.3.1-new/contrib/check_apc_ups.pl | ||
| 2 | --- nagios-plugins-1.3.1/contrib/check_apc_ups.pl 2002-08-14 20:02:31.000000000 +0100 | ||
| 3 | +++ nagios-plugins-1.3.1-new/contrib/check_apc_ups.pl 2003-07-14 18:39:57.000000000 +0100 | ||
| 4 | @@ -9,11 +9,19 @@ | ||
| 5 | # remaining: hh:mm:ss" if all is well, and a list of specific problems | ||
| 6 | # if something is broken. | ||
| 7 | |||
| 8 | +BEGIN { | ||
| 9 | + if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { | ||
| 10 | + $runtimedir = $1; | ||
| 11 | + $PROGNAME = $2; | ||
| 12 | + } | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +require 5.004; | ||
| 16 | +use POSIX; | ||
| 17 | use strict; | ||
| 18 | use Getopt::Long; | ||
| 19 | -use vars qw($opt_V $opt_h $opt_H $opt_T $opt_t $opt_R $opt_r | ||
| 20 | - $opt_L $opt_l $PROGNAME); | ||
| 21 | -use lib utils.pm; | ||
| 22 | +use vars qw($opt_V $opt_h $opt_H $opt_T $opt_t $opt_R $opt_r $opt_L $opt_l $community $PROGNAME); | ||
| 23 | +use lib $main::runtimedir; | ||
| 24 | use utils qw(%ERRORS &print_revision &support &usage); | ||
| 25 | |||
| 26 | sub print_help (); | ||
| 27 | @@ -24,18 +32,24 @@ | ||
| 28 | $ENV{'PATH'}=''; | ||
| 29 | $ENV{'BASH_ENV'}=''; | ||
| 30 | $ENV{'ENV'}=''; | ||
| 31 | +$ENV{'CDPATH'}=''; | ||
| 32 | |||
| 33 | -Getopt::Long::Configure('bundling'); | ||
| 34 | +my $verbose = 0; | ||
| 35 | +$community="public"; | ||
| 36 | + | ||
| 37 | +Getopt::Long::Configure('no_ignore_case'); | ||
| 38 | GetOptions | ||
| 39 | - ("V" => \$opt_V, "version" => \$opt_V, | ||
| 40 | - "h" => \$opt_h, "help" => \$opt_h, | ||
| 41 | - "T=s" => \$opt_T, "temp-critical" => \$opt_T, | ||
| 42 | - "t=s" => \$opt_t, "temp-warning" => \$opt_t, | ||
| 43 | - "R=s" => \$opt_R, "runtime-critical" => \$opt_R, | ||
| 44 | - "r=s" => \$opt_r, "runtime-warning" => \$opt_r, | ||
| 45 | - "L=s" => \$opt_L, "load-critical" => \$opt_L, | ||
| 46 | - "l=s" => \$opt_l, "load-warning" => \$opt_l, | ||
| 47 | - "H=s" => \$opt_H, "hostname=s" => \$opt_H); | ||
| 48 | + ("V|version" => \$opt_V, | ||
| 49 | + "h|help" => \$opt_h, | ||
| 50 | + "T|temp-critical:i" => \$opt_T, | ||
| 51 | + "t|temp-warning:i" => \$opt_t, | ||
| 52 | + "R|runtime-critical:i" => \$opt_R, | ||
| 53 | + "r|runtime-warning:i" => \$opt_r, | ||
| 54 | + "L|load-critical:i" => \$opt_L, | ||
| 55 | + "l|load-warning:i" => \$opt_l, | ||
| 56 | + "H|hostname=s" => \$opt_H, | ||
| 57 | + "C|community=s" => \$community, | ||
| 58 | + "v|verbose:+" => \$verbose); | ||
| 59 | |||
| 60 | if ($opt_V) { | ||
| 61 | print_revision($PROGNAME,'$Revision: 1.2 $'); | ||
| 62 | @@ -51,7 +65,7 @@ | ||
| 63 | # Defaults | ||
| 64 | |||
| 65 | $opt_R *= 60 * 100 if (defined $opt_R); # Convert minutes to secs/100 | ||
| 66 | -$opt_r *= 60 * 100 if (defined $opt_R); | ||
| 67 | +$opt_r *= 60 * 100 if (defined $opt_r); | ||
| 68 | |||
| 69 | my $tempcrit = $opt_T || 60; | ||
| 70 | my $tempwarn = $opt_t || 40; | ||
| 71 | @@ -140,7 +154,8 @@ | ||
| 72 | [ "testInProgress", $ERRORS{'OK'} ], # 4 | ||
| 73 | ); | ||
| 74 | |||
| 75 | -my $exitval = $ERRORS{'UNKNOWN'}; | ||
| 76 | +my $sep = ", "; | ||
| 77 | +my $exitval = $ERRORS{'OK'}; | ||
| 78 | my $data; | ||
| 79 | my $onbattery = 3; | ||
| 80 | |||
| 81 | @@ -148,10 +163,10 @@ | ||
| 82 | |||
| 83 | print "Output status: "; | ||
| 84 | if (defined ($data) && defined ($outputStatVals[$data][0])) { | ||
| 85 | - print "$outputStatVals[$data][0] | "; | ||
| 86 | + print "$outputStatVals[$data][0]$sep"; | ||
| 87 | escalate_exitval($outputStatVals[$data][1]); | ||
| 88 | } else { | ||
| 89 | - print "unknown | "; | ||
| 90 | + print "unknown$sep"; | ||
| 91 | } | ||
| 92 | |||
| 93 | $data = get_snmp_int_val( $upsAdvBatteryRunTimeRemaining ); | ||
| 94 | @@ -161,7 +176,7 @@ | ||
| 95 | my $hrs = int($data / (60 * 60 * 100)); # Data is hundredths of a second | ||
| 96 | my $mins = int($data / (60 * 100)) % 60; | ||
| 97 | my $secs = ($data % 100) / 100; | ||
| 98 | - printf "%d:%02d:%05.2f | ", $hrs, $mins, $secs; | ||
| 99 | + printf "%d:%02d:%05.2f$sep", $hrs, $mins, $secs; | ||
| 100 | if ($data <= $runtimecrit) { | ||
| 101 | escalate_exitval($ERRORS{'CRITICAL'}); | ||
| 102 | } elsif ($data <= $runtimewarn) { | ||
| 103 | @@ -170,7 +185,7 @@ | ||
| 104 | escalate_exitval($ERRORS{'OK'}); | ||
| 105 | } | ||
| 106 | } else { | ||
| 107 | - print "unknown | "; | ||
| 108 | + print "unknown$sep"; | ||
| 109 | } | ||
| 110 | |||
| 111 | $data = get_snmp_int_val( $upsBasicBatteryStatus ); | ||
| 112 | @@ -181,20 +196,20 @@ | ||
| 113 | my $fc = get_snmp_int_val( $upsAdvInputLineFailCause ); | ||
| 114 | if ($data == $onbattery) { | ||
| 115 | if (defined ($failCauseVals[$fc])) { $failcause = $failCauseVals[$fc]; } | ||
| 116 | - print "$battStatVals[$data][0] ($failcause) | "; | ||
| 117 | + print "$battStatVals[$data][0] ($failcause)$sep"; | ||
| 118 | } else { | ||
| 119 | - print "$battStatVals[$data][0] | "; | ||
| 120 | + print "$battStatVals[$data][0]$sep"; | ||
| 121 | } | ||
| 122 | escalate_exitval($battStatVals[$data][1]); | ||
| 123 | } else { | ||
| 124 | - print "unknown | "; | ||
| 125 | + print "unknown$sep"; | ||
| 126 | } | ||
| 127 | |||
| 128 | $data = get_snmp_int_val( $upsAdvBatteryTemperature ); | ||
| 129 | |||
| 130 | print "Battery temp(C): "; | ||
| 131 | if (defined ($data)) { | ||
| 132 | - print "$data | "; | ||
| 133 | + print "$data$sep"; | ||
| 134 | if ($data >= $tempcrit) { | ||
| 135 | escalate_exitval($ERRORS{'CRITICAL'}); | ||
| 136 | } elsif ($data >= $tempwarn) { | ||
| 137 | @@ -203,24 +218,24 @@ | ||
| 138 | escalate_exitval($ERRORS{'OK'}); | ||
| 139 | } | ||
| 140 | } else { | ||
| 141 | - print "unknown | "; | ||
| 142 | + print "unknown$sep"; | ||
| 143 | } | ||
| 144 | |||
| 145 | $data = get_snmp_int_val( $upsAdvBatteryReplaceIndicator ); | ||
| 146 | |||
| 147 | print "Battery repl: "; | ||
| 148 | if (defined ($data) && defined ($battReplVals[$data][0])) { | ||
| 149 | - print "$battReplVals[$data][0] | "; | ||
| 150 | + print "$battReplVals[$data][0]$sep"; | ||
| 151 | escalate_exitval($battReplVals[$data][1]); | ||
| 152 | } else { | ||
| 153 | - print "unknown | "; | ||
| 154 | + print "unknown$sep"; | ||
| 155 | } | ||
| 156 | |||
| 157 | $data = get_snmp_int_val( $upsAdvOutputLoad ); | ||
| 158 | |||
| 159 | print "Output load (%): "; | ||
| 160 | if (defined ($data)) { | ||
| 161 | - print "$data | "; | ||
| 162 | + print "$data$sep"; | ||
| 163 | if ($data >= $loadcrit) { | ||
| 164 | escalate_exitval($ERRORS{'CRITICAL'}); | ||
| 165 | } elsif ($data >= $loadwarn) { | ||
| 166 | @@ -229,19 +244,25 @@ | ||
| 167 | escalate_exitval($ERRORS{'OK'}); | ||
| 168 | } | ||
| 169 | } else { | ||
| 170 | - print "unknown | "; | ||
| 171 | + print "unknown$sep"; | ||
| 172 | } | ||
| 173 | |||
| 174 | $data = get_snmp_int_val( $upsAdvTestDiagnosticsResults ); | ||
| 175 | |||
| 176 | print "Diag result: "; | ||
| 177 | if (defined ($data) && defined ($diagnosticsResultsVals[$data][0])) { | ||
| 178 | - print "$diagnosticsResultsVals[$data][0]\n"; | ||
| 179 | + print "$diagnosticsResultsVals[$data][0]$sep"; | ||
| 180 | escalate_exitval($diagnosticsResultsVals[$data][1]); | ||
| 181 | } else { | ||
| 182 | - print "unknown\n"; | ||
| 183 | + print "unknown$sep"; | ||
| 184 | } | ||
| 185 | |||
| 186 | +foreach my $key (keys %ERRORS) { | ||
| 187 | + if ($ERRORS{$key} == $exitval) { | ||
| 188 | + print "Status $key\n"; | ||
| 189 | + last; | ||
| 190 | + } | ||
| 191 | +} | ||
| 192 | |||
| 193 | exit $exitval; | ||
| 194 | |||
| 195 | @@ -263,6 +284,8 @@ | ||
| 196 | print " | ||
| 197 | -H, --hostname=HOST | ||
| 198 | Name or IP address of host to check | ||
| 199 | +-C, --community=string | ||
| 200 | + Community string to use to query UPS (default: public) | ||
| 201 | -T --temp-critical | ||
| 202 | Battery degrees C above which a CRITICAL status will result (default: 60) | ||
| 203 | -t --temp-warning | ||
| 204 | @@ -284,7 +307,7 @@ | ||
| 205 | my $val=0; | ||
| 206 | my $oid = shift(@_); | ||
| 207 | |||
| 208 | - $val = `/usr/bin/snmpget $host public $oid 2> /dev/null`; | ||
| 209 | + $val = `/usr/bin/snmpget -v 1 -c $community $host $oid 2> /dev/null`; | ||
| 210 | my @test = split(/ /,$val,3); | ||
| 211 | |||
| 212 | return undef unless (defined ($test[2])); | ||
| 213 | @@ -297,6 +320,7 @@ | ||
| 214 | $val = $test[2]; | ||
| 215 | } | ||
| 216 | |||
| 217 | + chomp($val); | ||
| 218 | return $val; | ||
| 219 | } | ||
| 220 | |||
