X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=dsa-nagios-checks%2Fchecks%2Fdsa-check-raid-3ware;h=da298e58c3ed18ed1f405bcea1ac121cca2a9b50;hb=a8af7c17337c0c2075d5147ce2a95bcaff1e8c18;hp=a9887b9fe074c3ac53118cd65a5dcf3c65f1d985;hpb=42e99da9d896a33803e763c746e9a103183b6b34;p=mirror%2Fdsa-nagios.git diff --git a/dsa-nagios-checks/checks/dsa-check-raid-3ware b/dsa-nagios-checks/checks/dsa-check-raid-3ware index a9887b9..da298e5 100755 --- a/dsa-nagios-checks/checks/dsa-check-raid-3ware +++ b/dsa-nagios-checks/checks/dsa-check-raid-3ware @@ -1,6 +1,26 @@ #!/usr/bin/perl -Tw -# Copyright (C) 2006 Peter Palfrader +# Copyright (C) 2006,2008,2009,2016 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. + # Need to allow /usr/local/bin/tw_cli info c0 u0 status in sudoers: # @@ -15,7 +35,7 @@ $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; my $TW_CLI = '/usr/local/bin/tw_cli'; -my $SVN_REVISION_STRING = '$Rev: 313 $'; +my $SVN_REVISION_STRING = '$Rev: 410 $'; my ($SVN_REVISION) = ($SVN_REVISION_STRING =~ /([0-9]+)/); $SVN_REVISION = 'unknown' unless defined $SVN_REVISION; my $VERSION = '0.0.0.'.$SVN_REVISION; @@ -51,7 +71,7 @@ if ($params->{'help'}) { if ($params->{'version'}) { print "nagios-check-raid-3ware $VERSION\n"; print "nagios check for 3ware raids\n"; - print "Copyright (c) 2006 Peter Palfrader \n"; + print "Copyright (c) 2006,2008,2009,2016 Peter Palfrader \n"; exit (0); }; @@ -65,10 +85,20 @@ unless (-e $TW_CLI) { exit $UNKNOWN; }; -my $sudo = $params->{'no-sudo'} ? '' : 'sudo '; -my $command = "$sudo $TW_CLI info c$params->{'controller'} u$params->{'unit'} status"; +for my $thing (qw{controller unit}) { + if ($params->{$thing} =~ m/^([0-9]+)$/) { + $params->{$thing} = $1; + } else { + die("Invalid $thing $1.\n"); + } +}; + +my @command; +push @command, "sudo" if $params->{'no-sudo'}; +push @command, ($TW_CLI, 'info', "c$params->{'controller'}", "u$params->{'unit'}", "status"); +my $command = join(' ', @command); print STDERR "Running $command\n" if $params->{'verbose'}; -open (TW, "$command|") or die ("Cannot run $command: $!\n"); +open (TW, "-|", @command) or die ("Cannot run $command: $!\n"); my @tw=; close TW; if ($CHILD_ERROR) { # program failed @@ -90,6 +120,9 @@ for my $line (@tw) { $status eq 'VERIFYING') { $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; $exit = $exit > $OK ? $exit : $OK; + } elsif ($status eq 'REBUILDING') { + $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; + $exit = $exit > $WARNING ? $exit : $WARNING; } elsif ($status eq 'DEGRADED') { $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; $exit = $exit > $CRITICAL ? $exit : $CRITICAL;