Add dsa-check-raid-aacraid
authorPeter Palfrader <peter@palfrader.org>
Sun, 28 Jun 2009 14:31:43 +0000 (16:31 +0200)
committerPeter Palfrader <peter@palfrader.org>
Sun, 28 Jun 2009 14:31:43 +0000 (16:31 +0200)
dsa-nagios-checks/checks/dsa-check-raid-aacraid [new file with mode: 0755]
dsa-nagios-checks/debian/changelog
dsa-nagios-checks/debian/copyright

diff --git a/dsa-nagios-checks/checks/dsa-check-raid-aacraid b/dsa-nagios-checks/checks/dsa-check-raid-aacraid
new file mode 100755 (executable)
index 0000000..0b82c47
--- /dev/null
@@ -0,0 +1,140 @@
+#!/usr/bin/perl -w
+
+# Copyright (c) 2008,2009 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.
+
+use strict;
+use File::Temp qw/ tempdir /;
+
+# 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 arcconf $cmd";
+       open(FH, $cmd."|") or die ("Cannot run $cmd: $!");
+       my @lines = <FH>;
+       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;
+       };
+}
+
+# arcconf puts crap into a $PWD/UcliEvt.log file.
+my $dir = tempdir( "check-aacraid-XXXXXXX", CLEANUP => 1 );
+chdir ($dir) or die ("Cannot chdir $dir: $!\n");
+
+my $ctrl = 1;
+my @resultstr;
+my $numcontrollers = 1;
+while ($ctrl <= $numcontrollers) {
+       my $lds = runcmd("GETCONFIG $ctrl LD");
+       my %status;
+       my $ld = "unknown";
+       my @extrastatus = ();
+       for (@$lds) {
+               chomp;
+               if (/^Controllers found: *([0-9]+)/) {
+                       $numcontrollers = $1;
+               } elsif (/^Logical device number (.*)/) {
+                       $ld = "LD$1";
+               } elsif (/^ *Status of logical device *: *(.*)/) {
+                       my $status = $1;
+                       if ($status ne 'Optimal') {
+                               record('WARNING');
+                       };
+                       push @{$status{$status}}, $ld;
+               };
+       };
+
+       my $adi = runcmd("GETCONFIG $ctrl AD");
+       for (@$adi) {
+               chomp;
+               if (/^ *Controller Status *: *(.*)/) {
+                       my $status = $1;
+                       if ($status ne 'Optimal') {
+                               record('WARNING');
+                       };
+                       push @{$status{$status}}, "controller";
+               } elsif (/^ *Defunct disk drive count *: *(.*)/) {
+                       my $count  = $1;
+                       if ($count > 0) {
+                               record('WARNING');
+                               push @extrastatus, "$count defunct drives";
+                       }
+               } elsif (m#^ *Logical devices/Failed/Degraded *: (.*)/(.*)/(.*)#) {
+                       my $total = $1;
+                       my $failed = $2;
+                       my $degraded = $3;
+                       push @extrastatus, "$total/$failed/$degraded LDs total/failed/degraded";
+                       if ($failed > 0) {
+                               record('CRITICAL');
+                       } elsif ($degraded > 0) {
+                               record('WARNING');
+                       }
+               } elsif (/.*Controller Battery Information/) {
+                       last;
+               };
+       };
+       # in Controller Battery Information
+       for (@$adi) {
+               chomp;
+               if (/^ *Status *: *(.*)/) {
+                       my $status = $1;
+                       if ($status eq 'Not Installed') {
+                               next;
+                       } elsif ($status ne 'Optimal') {
+                               record('WARNING');
+                       };
+                       push @{$status{$status}}, 'Battery';
+               }
+       }
+
+       my $status = join(" - ", (map { $_.": ".join(", ", @{$status{$_}}) } keys %status));
+       if (scalar @extrastatus > 0) {
+               $status .= ", ".join(", ", @extrastatus);
+       }
+       push @resultstr, "Ctrl $ctrl: $status";
+       $ctrl++;
+};
+
+print "$EXITCODE: ", join(" --- ", @resultstr), "\n";
+exit $CODE{$EXITCODE};
index 9508f8a..e926bb3 100644 (file)
@@ -1,3 +1,9 @@
+dsa-nagios-checks (77) stable; urgency=low
+
+  * Add checks/dsa-check-raid-aacraid.
+
+ -- Peter Palfrader <weasel@debian.org>  Sun, 28 Jun 2009 16:31:13 +0200
+
 dsa-nagios-checks (76) stable; urgency=low
 
   * Ship with an /etc/nagios/obsolete-packages-ignore.d directory.
index 300ca52..fbd517c 100644 (file)
@@ -80,3 +80,8 @@ dsa-check-packages:
 dsa-check-soas:
   Copyright: 2006 Peter Palfrader
   License: MIT
+
+########################################################################
+dsa-check-raid-aacraid:
+  Copyright: 2008,2009 Peter Palfrader
+  License: MIT