#! /usr/bin/perl # $Id: check_mpt.pl,v 0.1 2006/05/16 15:17:49 Exp $ # check_mpt.pl Copyright (C) 2006 Claudio Messineo # 0.2: Fixed by Nicolai Langfeldt (nicolai.langfeldt@broadnet.no) 2013 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # you should have received a copy of the GNU General Public License # along with this program (or with Nagios); if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA use strict; use English; use Getopt::Long; use vars qw($PROGNAME $VERSION); use lib "/usr/local/nagios/libexec" ; use utils qw (%ERRORS &print_revision &support); sub print_help (); sub print_usage (); my ( $opt_h, $opt_V); my ( $mpt_path ); $PROGNAME="check_mpt"; $VERSION='0.2'; $mpt_path="sudo /usr/sbin/mpt-status"; Getopt::Long::Configure('bundling'); GetOptions( "V" => \$opt_V, "version" => \$opt_V, "h" => \$opt_h, "help" => \$opt_h, ); if ($opt_V) { print_revision($PROGNAME, $VERSION ); exit $ERRORS{'OK'}; } if ($opt_h) { print_help(); exit $ERRORS{'OK'}; } sub print_usage () { print "Usage:\n"; print " $PROGNAME [-h | --help]\n"; print " $PROGNAME [-V | --version]\n"; } sub print_help () { print_revision($PROGNAME, $VERSION); print "Copyright (c) 2006 Claudio Messineo claudio\@__no__spam__zero.it (s/__no__spam__//)\n"; print "Some fixes by Nicolai Langfeldt with broadnet in norway.\n\n"; print_usage(); print "\n"; support(); } my $num_raid = 0; my $num_disks = 0; my @err = (); if ( ! open( MPT_STAT, " $mpt_path | " ) ) { print "ERROR: could not open $mpt_path \n"; exit $ERRORS{'UNKNOWN'}; } else { # Example output: # # ioc0 vol_id 0 type IME, 4 phy, 271 GB, state OPTIMAL, flags ENABLED # ioc0 phy 3 scsi_id 4 SEAGATE ST914603SSUN146G 0868, 136 GB, state ONLINE, flags NONE # ioc0 phy 2 scsi_id 1 SEAGATE ST914603SSUN146G 0868, 136 GB, state ONLINE, flags NONE # ioc0 phy 1 scsi_id 2 HITACHI H103014SCSUN146G A2A8, 136 GB, state ONLINE, flags NONE # ioc0 phy 0 scsi_id 3 HITACHI H103014SCSUN146G A160, 136 GB, state ONLINE, flags NONE while () { chomp; if ( m/vol_id (\d+)/ ) { my $id = $1; $num_raid++; if (! m/OPTIMAL/) { push @err,"volume $id is NOT optimal"; } if (! m/ENABLED/) { push @err,"volume $id is NOT enabled"; } } elsif ( m/scsi_id (\d+)/) { my $id = $1; $num_disks++; if (! m/ONLINE/) { push @err,"disk $id is NOT online"; } } else { push @err,"unrecognized: $_"; } } if ( $num_raid == 0 ) { unshift @err, "There are NO raid volumes here!"; } if ( $num_raid != 0 and $num_disks == 0 ) { unshift @err, "There are NO disks here!" } if (scalar(@err) > 0) { print "mpt-status CRITICAL: ",join(", ",@err),"\n"; exit $ERRORS{'CRITICAL'}; } else { print "Mpt-status OK\n"; exit $ERRORS{'OK'}; } }