#!/usr/bin/perl
# modified copy of check_raid_amrstat
# quick and dirty, stripe size set to 64K !!!
use warnings;
use strict;
#use Switch;
my %NAGIOS_API_ECODES = ( 'OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3 );
my $_mfiutilPath = "/usr/sbin/mfiutil";
my $_intLDCount = 0;
my $_intDegCount = 0;
my @_arrLDStatus;
my $_intFailedComponentCount = 0;
my @_arrFailedComponent;
my $_boolVerbose = 0;
# This abosolute path might need [to be] adjusted
# Gee I wonder if it should be a variable you declare
if (! open(MFI, "$_mfiutilPath show config |") ) {
die "Cannot locate mfiutil binary in \$PATH\n";
exit $NAGIOS_API_ECODES{UNKNOWN};
}
my $_intBus = 0;
my $_intID = 0;
while (my $line = <MFI>) {
if ($line =~ m/^([\s]+)volume\ mfid([0-5]+)\ ([0-9TG\(\)]+) RAID([\-0-5]+) 64K (OPTIMAL|DEGRADED|OFFLINE|REBUILD) /) {
$_arrLDStatus[$_intLDCount][0] = $2;
$_arrLDStatus[$_intLDCount][1] = $5;
if ($5 =~ "DEGRADED") { $_intDegCount++; }
if ($5 =~ "OFFLINE") { $_intDegCount++; }
if ($5 =~ "REBUILD") { $_intDegCount++; }
$_intLDCount++;
}
}
close(MFI);
# Goal: The make the output about as easily parseable as
# AMI/LSI/Dell have made that of megarc(8)
if ($_intLDCount < 1 ) {
print "No logical drives found"; exit $NAGIOS_API_ECODES{WARN};
} else {
print "$_intLDCount LDs; $_intDegCount degraded";
if ($_boolVerbose) {
print "; $_intFailedComponentCount components failed";
}
print "::";
}
my $_intCount = 0;
foreach (@_arrLDStatus) {
print "(LD$_arrLDStatus[$_intCount][0] ";
print "Status: $_arrLDStatus[$_intCount][1] )";
print "\n";
$_intCount++;
}
if ($_boolVerbose && @_arrFailedComponent > 0) {
my $_intBadCounter = 0;
foreach (@_arrFailedComponent) {
#print "DEBUG: $_intBadCounter\n";
print " Drive @ Bus[$_arrFailedComponent[$_intBadCounter][0]]-ID[$_arrFailedComponent[$_intBadCounter][1]] OFFLINE!";
$_intBadCounter++;
}
}
if ($_intDegCount > 0) {
exit $NAGIOS_API_ECODES{CRITICAL};
} else {
exit $NAGIOS_API_ECODES{OK};
}