nrpe is bad about reading stderr
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-hpacucli
index 52e0ebb..8f62bb9 100755 (executable)
@@ -5,7 +5,7 @@
 #
 # does _not_ check raid status.  use arrayprobe for that.
 
-# Copyright (c) 2008,2009 Peter Palfrader <peter@palfrader.org>
+# Copyright (c) 2008,2009,2010,2011 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
@@ -27,6 +27,8 @@
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 use strict;
+use English;
+use Getopt::Long;
 
 # nagios exit codes
 my %CODE = (
@@ -39,7 +41,7 @@ my %CODE = (
 my $EXITCODE = 'OK';
 
 $SIG{'__DIE__'} = sub {
-       print STDERR @_;
+       print @_;
        exit $CODE{'UNKNOWN'};
 };
 
@@ -62,6 +64,21 @@ sub record($) {
        };
 }
 
+my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--no-battery] [--ignore-transfer-speed=<pd> [--ignore-transfer-speed=<pd> ...]]\n";
+my $params;
+Getopt::Long::Configure('bundling');
+if (!GetOptions (
+       '--help'                      => \$params->{'help'},
+       '--no-battery'                => \$params->{'no-battery'},
+       '--ignore-transfer-speed=s@'  => \$params->{'ignore-transfer-speed'},
+       )) {
+       die ($usage);
+};
+if ($params->{'help'}) {
+       print $usage;
+       exit (0);
+};
+die ($usage) unless (scalar @ARGV == 0);
 
 my $ctrlallshow = runcmd("controller all show");
 my @controllers;
@@ -92,6 +109,7 @@ for my $slot (sort @controllers) {
                next if /^$/;
                next if (/^\S.*in Slot $slot/);
                next if /^ *array [A-Z]$/;
+               next if /^ *unassigned/;
                if (/^ *(array [A-Z]) \(Failed\)$/) {
                        record('CRITICAL');
                        push @{$status{'Failed'}}, $1;
@@ -163,29 +181,29 @@ for my $slot (sort @controllers) {
                                push @{$status{'unknown transfer mode'}}, $drive."(".$value{'Transfer Mode'}.")";
                                next;
                        };
-               } elsif ($type eq 'SAS') {
+               } elsif ($type eq 'SAS' || $type eq 'SAS+') {
                        $key = 'PHY Transfer Rate';
                        if ($value{'PHY Count'} eq '2') {
                                if (defined($value{'Redundant Path(s)'})) {
-                                       $expected = '3.0GBPS, 3.0GBPS';
+                                       $expected = [ '3.0GBPS, 3.0GBPS', '6.0GBPS, 6.0GBPS' ];
                                } else {
-                                       $expected = [ '3.0GBPS, Unknown', 'Unknown, 3.0GBPS' ];
+                                       $expected = [ '3.0GBPS, Unknown', 'Unknown, 3.0GBPS',
+                                                     '6.0GBPS, Unknown', 'Unknown, 6.0GBPS' ];
                                }
                        } else {
-                               $expected = '3.0GBPS';
-                       }
-               } elsif ($type eq 'SAS+') {
-                       $key = 'PHY Transfer Rate';
-                       if ($value{'PHY Count'} eq '2') {
-                               $expected = '6.0GBPS, Unknown';
-                       } else {
-                               $expected = '6.0GBPS';
+                               $expected = [ '3.0GBPS', '6.0GBPS' ];
                        }
                } else {
                        warn "Should not be here.  Do not know what to do with type '$type'\n";
                        next;
                }
 
+               if ($params->{'ignore-transfer-speed'}) {
+                       if (grep { $drive eq $_ } @{$params->{'ignore-transfer-speed'}}) {
+                               push @{$status{'ignored transfer speed'}}, $drive."(".$value{$key}.")";
+                               next;
+                       };
+               };
                if (!defined $value{$key}) {
                        record('WARNING');
                        push @{$status{'unknown transfer speed'}}, $drive;
@@ -219,6 +237,8 @@ for my $slot (sort @controllers) {
                        my $status = $2;
                        push @{$status{$status}}, $system;
                        if ($status ne 'OK') {
+                               next if ($params->{'no-battery'} && $system eq 'Cache');
+                               next if ($params->{'no-battery'} && $system eq 'Battery/Capacitor');
                                record('WARNING');
                        };
                } else {