From: Peter Palfrader Date: Tue, 24 Aug 2010 11:02:56 +0000 (+0200) Subject: Add dsa-check-hpacucli-enclosure X-Git-Url: https://wiki.adam-barratt.org.uk/gitweb/?a=commitdiff_plain;h=fa7d10d6ee9b5011a2f43feb099564922580323c;p=mirror%2Fdsa-nagios.git Add dsa-check-hpacucli-enclosure --- diff --git a/dsa-nagios-checks/checks/dsa-check-hpacucli-enclosure b/dsa-nagios-checks/checks/dsa-check-hpacucli-enclosure new file mode 100755 index 0000000..0be0b89 --- /dev/null +++ b/dsa-nagios-checks/checks/dsa-check-hpacucli-enclosure @@ -0,0 +1,119 @@ +#!/usr/bin/perl -w + +# check enclosure status + +# Copyright (c) 2008,2009,2010 Peter Palfrader +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +use strict; +use English; +use Getopt::Long; + +# nagios exit codes +my %CODE = ( + 'OK' => 0, + 'WARNING' => 1, + 'CRITICAL' => 2, + 'UNKNOWN' => 3 +); + +my $EXITCODE = 'OK'; + +$SIG{'__DIE__'} = sub { + print STDERR @_; + exit $CODE{'UNKNOWN'}; +}; + +sub runcmd($) { + my ($cmd) = @_; + $cmd = "sudo hpacucli $cmd"; + open(FH, $cmd."|") or die ("Cannot run $cmd: $!"); + my @lines = ; + close FH; + die ("no results from $cmd\n") if (scalar @lines == 0); + return \@lines; +} + +sub record($) { + my ($newexit) = @_; + die "code $newexit not defined\n" unless defined $CODE{$newexit}; + + if ($CODE{$newexit} > $CODE{$EXITCODE}) { + $EXITCODE = $newexit; + }; +} + +my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME \n"; +my $params; +Getopt::Long::Configure('bundling'); +if (!GetOptions ( + '--help' => \$params->{'help'}, + )) { + die ($usage); +}; +if ($params->{'help'}) { + print $usage; + exit (0); +}; +die ($usage) unless (scalar @ARGV == 2); +my $slot = shift; +my $enc = shift; + +my @resultstr; +my %status; +my $status = runcmd("controller slot=$slot enclosure $enc show detail"); +for (@$status) { + chomp; + next if /^$/; + next if (/^\S.*in Slot $slot/); + next if (/^ \S.*at Port/); + last if (/^ \S/); + + if (m/^ (Fan Status|Temperature Status):\s*(.*?)\s*$/) { + my $system = $1; + my $status = $2; + push @{$status{$status}}, $system; + if ($status ne 'OK') { + record('WARNING'); + }; + } elsif (m/^ (Power Supply Status):\s*(.*?)\s*$/) { + my $system = $1; + my $status = $2; + push @{$status{$status}}, $system; + if ($status ne 'Redundant') { + record('WARNING'); + }; + } elsif (m/^ (Active Path|Standby Path):\s*(.*?),\s*(.*?)\s*$/) { + my $system = $1; + my $detail = $2; + my $status = $3; + push @{$status{$status}}, $system."($detail)"; + if ($status ne 'OK') { + record('WARNING'); + }; + } + +}; +$status = join(" - ", (map { $_.": ".join(", ", @{$status{$_}}) } keys %status)); +push @resultstr, "Slot $slot: $status"; + +print "$EXITCODE: ", join(" --- ", @resultstr), "\n"; +exit $CODE{$EXITCODE}; diff --git a/dsa-nagios-checks/debian/changelog b/dsa-nagios-checks/debian/changelog index 76d7f3c..5d52b0d 100644 --- a/dsa-nagios-checks/debian/changelog +++ b/dsa-nagios-checks/debian/changelog @@ -4,8 +4,9 @@ dsa-nagios-checks (8x) xnstable; urgency=low transfer speed in addition to '3.0GBPS, Unknown'. * dsa-check-hpacucli add --ignore-transfer-speed option. * Add dsa-check-ups. + * Add dsa-check-hpacucli-enclosure. - -- Peter Palfrader Tue, 24 Aug 2010 12:36:56 +0200 + -- Peter Palfrader Tue, 24 Aug 2010 13:02:38 +0200 dsa-nagios-checks (87) unstable; urgency=low