dsa-check-hpacucli updates for our blades
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-hpacucli
index 7aff0c3..8bbb7eb 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
@@ -41,7 +41,7 @@ my %CODE = (
 my $EXITCODE = 'OK';
 
 $SIG{'__DIE__'} = sub {
-       print STDERR @_;
+       print @_;
        exit $CODE{'UNKNOWN'};
 };
 
@@ -64,11 +64,14 @@ sub record($) {
        };
 }
 
-my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--ignore-transfer-speed=<pd> [--ignore-transfer-speed=<pd> ...]]\n";
+my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--no-battery] [--ignore-controller=<regex>] [--no-controller-ok] [--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'},
+       '--no-controller-ok'          => \$params->{'no-controller-ok'},
+       '--ignore-controller=s'       => \$params->{'ignore-controller'},
        '--ignore-transfer-speed=s@'  => \$params->{'ignore-transfer-speed'},
        )) {
        die ($usage);
@@ -84,6 +87,7 @@ my @controllers;
 for (@$ctrlallshow) {
        chomp;
        next if /^$/;
+       next if ($params->{'ignore-controller'} && /$params->{'ignore-controller'}/);
        if (/in Slot ([0-9a-z]+)/) {
                push @controllers, $1;
                next;
@@ -92,8 +96,13 @@ for (@$ctrlallshow) {
 };
 
 if (scalar @controllers == 0) {
-       print "UNKNONW: No smartarray controllers found with hpacucli\n";
-       exit $CODE{'UNKNOWN'}
+       if ($params->{'no-controller-ok'}) {
+               print "No smartarray controllers found with hpacucli\n";
+               exit $CODE{'OK'}
+       } else {
+               print "UNKNOWN: No smartarray controllers found with hpacucli\n";
+               exit $CODE{'UNKNOWN'}
+       }
 };
 
 my @resultstr;
@@ -200,18 +209,18 @@ for my $slot (sort @controllers) {
                if ($params->{'ignore-transfer-speed'}) {
                        if (grep { $drive eq $_ } @{$params->{'ignore-transfer-speed'}}) {
                                push @{$status{'ignored transfer speed'}}, $drive."(".$value{$key}.")";
+                               next;
                        };
-                       next;
                };
                if (!defined $value{$key}) {
                        record('WARNING');
                        push @{$status{'unknown transfer speed'}}, $drive;
                } elsif (ref($expected) eq 'ARRAY') {
-                       if (scalar(grep { $value{$key} eq $_ } @$expected) == 0) {
+                       if (scalar(grep { uc($value{$key}) eq uc($_) } @$expected) == 0) {
                                record('WARNING');
                                push @{$status{'bad transfer speed'}}, $drive."(".$value{$key}.")";
                        };
-               } elsif ($value{$key} ne $expected) {
+               } elsif (uc($value{$key}) ne uc($expected)) {
                        record('WARNING');
                        push @{$status{'bad transfer speed'}}, $drive."(".$value{$key}.")";
                };
@@ -236,6 +245,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 {