From: Peter Palfrader Date: Sun, 28 Jun 2009 14:31:43 +0000 (+0200) Subject: Add dsa-check-raid-aacraid X-Git-Url: https://wiki.adam-barratt.org.uk/gitweb/?a=commitdiff_plain;h=0c28424359fbab9c5662c9b60766c8236e2c0cc1;p=mirror%2Fdsa-nagios.git Add dsa-check-raid-aacraid --- diff --git a/dsa-nagios-checks/checks/dsa-check-raid-aacraid b/dsa-nagios-checks/checks/dsa-check-raid-aacraid new file mode 100755 index 0000000..0b82c47 --- /dev/null +++ b/dsa-nagios-checks/checks/dsa-check-raid-aacraid @@ -0,0 +1,140 @@ +#!/usr/bin/perl -w + +# Copyright (c) 2008,2009 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. + +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 = ; + 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}; diff --git a/dsa-nagios-checks/debian/changelog b/dsa-nagios-checks/debian/changelog index 9508f8a..e926bb3 100644 --- a/dsa-nagios-checks/debian/changelog +++ b/dsa-nagios-checks/debian/changelog @@ -1,3 +1,9 @@ +dsa-nagios-checks (77) stable; urgency=low + + * Add checks/dsa-check-raid-aacraid. + + -- Peter Palfrader 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. diff --git a/dsa-nagios-checks/debian/copyright b/dsa-nagios-checks/debian/copyright index 300ca52..fbd517c 100644 --- a/dsa-nagios-checks/debian/copyright +++ b/dsa-nagios-checks/debian/copyright @@ -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