dsa-check-statusfile: port to python3
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-raid-3ware
index a9887b9..da298e5 100755 (executable)
@@ -1,6 +1,26 @@
 #!/usr/bin/perl -Tw
 
-# Copyright (C) 2006 Peter Palfrader <peter@palfrader.org>
+# Copyright (C) 2006,2008,2009,2016 Peter Palfrader <peter@palfrader.org>
+#
+# 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 <peter\@palfrader.org>\n";
+       print "Copyright (c) 2006,2008,2009,2016 Peter Palfrader <peter\@palfrader.org>\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=<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;