#!/usr/bin/perl -w # # $Id: //depot/Projects/Nagios/amrstat/check_raid_amrstat#4 $ # ####################################### ### check_raid_amrstat.pl ########## ### hacked together by: ########## ### Steve Polyack ########## ### check_raid_megarc.pl ########## ### by Brian A. Seklecki for ######### ### Collaborative Fusion, Inc. ###### ####################################### ### This program parses the output #### ### of ports/sysutils/amrstat ######### ####################################### #/* # * Copyright (c) 2006-2007 Collaborative Fusion, Inc. All rights reserved. # * # * Developed by: Collaborative Fusion, Inc. # * http://www.collaborativefusion.com # * # * Permission is hereby granted, free of charge, to any person obtaining a copy # * of this software and associated documentation files (the "Software"), to # * deal with 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: # * 1. Redistributions of source code must retain the above copyright notice, # * this list of conditions and the following disclaimers. # * 2. Redistributions in binary form must reproduce the above copyright # * notice, this list of conditions and the following disclaimers in the # * documentation and/or other materials provided with the distribution. # * 3. All advertising materials mentioning features or use of this software # * must display the following acknowledgement: This product includes # * software developed by Collaborative Fusion, Inc. # * 4. Neither the name of Collaborative Fusion, Inc. or any of its employees # * may be used to endorse or promote products derived from this Software # * without specific prior written permission. # # * 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 # * COLLABORATIVE FUSION, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # */ # # /* # * This code was written under funding by Collaborative Fusion, Inc.. # */ # # Further modifications by Jonathan Delgado. Cleared out old code comments. # I don't quite get the $_intfoo type of naming scheme, but hey diff strokes. # # # $Author: delgado $ # $Revision: #4 $ $Date: 2010/07/30 $ use warnings; use strict; # Adjust to your local Nagios plugins directory use lib "/usr/local/libexec/nagios"; use utils qw(%ERRORS); # Set to path of locally installed amrstat if different my $amrstat = "sudo /usr/local/sbin/amrstat"; my $result = ''; my $_intLDCount = 0; my $_intDegCount = 0; my @_arrLDStatus; my $_intFailedComponentCount = 0; my @_arrFailedComponent; my $USAGE = "Usage: $0 \n"; if (@ARGV < 1) { print $USAGE; exit $ERRORS{'UNKNOWN'}; } if ($ARGV[0] !~ m/^\d?$/) { print $USAGE; exit $ERRORS{'UNKNOWN'}; } if (! open(AMRSTAT, "$amrstat -g -c $ARGV[0] |") ) { print "UNKOWN: Cannot open $amrstat\n"; exit $ERRORS{'UNKNOWN'}; } my $_intBus = 0; my $_intID = 0; while ( ) { if ( m/^Logical volume (\d):\s*(optimal|degraded)\s*\((.+),\s*(.+)\)/ ) { $_arrLDStatus[$_intLDCount][0] = $1; $_arrLDStatus[$_intLDCount][1] = $2; $_arrLDStatus[$_intLDCount][2] = $3; #capture the LD size $_arrLDStatus[$_intLDCount][3] = $4; #capture the LD RAID type $_arrLDStatus[$_intLDCount][2] =~ s/\s+//; if ($_arrLDStatus[$_intLDCount][1] eq "degraded") { $_intDegCount++; } $_intLDCount++; } elsif ( m/^Physical drive (\d):(\d) (online|failed)/ ) { $_intBus = $1; $_intID = $2; if ($3 =~ "failed") { $_arrFailedComponent[$_intFailedComponentCount][0] = $_intBus; $_arrFailedComponent[$_intFailedComponentCount][1] = $_intID; $_intFailedComponentCount++; } } } close(AMRSTAT); if ($_intLDCount < 1 ) { print "WARNING: No logical drives found"; exit $ERRORS{'WARNING'}; } my $_intCount = 0; foreach (@_arrLDStatus) { $result .= "$ARGV[0]:$_arrLDStatus[$_intCount][0]:$_arrLDStatus[$_intCount][3]:$_arrLDStatus[$_intCount][2]:$_arrLDStatus[$_intCount][1] "; $_intCount++; } if (@_arrFailedComponent > 0) { my $_intBadCounter = 0; $result .= "Drive(s) "; foreach (@_arrFailedComponent) { $result .= "$_arrFailedComponent[$_intBadCounter][0]:$_arrFailedComponent[$_intBadCounter][1] "; $_intBadCounter++; } $result .= "OFFLINE"; } if ($_intDegCount > 0) { print "CRITICAL: $result"; exit $ERRORS{'CRITICAL'}; } else { print "OK: $result"; exit $ERRORS{'OK'}; }