--- smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/sudoers/00zabbixAgentAlias.megaraid_parser 2009-04-24 22:28:07.000000000 +0200 +++ smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/sudoers/00zabbixAgentAlias 2009-04-26 18:43:19.000000000 +0200 @@ -1,7 +1,7 @@ { my $runasroot = '/usr/bin/mysqladmin status, /sbin/e-smith/db yum_updates show, /var/lib/zabbix/bin/sensors *'; if ( -x '/opt/MegaRAID/MegaCli/MegaCli' ){ - $runasroot .= ', /opt/MegaRAID/MegaCli/MegaCli -ldinfo -Lall -Aall'; + $runasroot .= ', /opt/MegaRAID/MegaCli/MegaCli *'; } $runasroot .= "\n"; $OUT .= 'Cmnd_Alias ZABBIX_AGENT_ROOT = '.$runasroot --- smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/zabbix/zabbix_agentd.conf/90UserParameters_megaRaid.megaraid_parser 2009-04-24 22:28:07.000000000 +0200 +++ smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/zabbix/zabbix_agentd.conf/90UserParameters_megaRaid 2009-04-26 19:39:57.000000000 +0200 @@ -15,13 +15,12 @@ # Show Value: As is # The value reported is like: -# State: Optimal -# State: Degraded +# State: OK: 0:0:RAID-1:2 drives:68GB:Optimal 0:1:RAID-5:4 drives:837GB:Optimal Drives:7 # # Tips: You can add a simple trigger on this check like: -# \{ hostname:raid.mega.status.str( Degraded ) \}=1 -UserParameter=raid.mega.status,/usr/bin/sudo /opt/MegaRAID/MegaCli/MegaCli -ldinfo -Lall -Aall | grep "^State:" +# \{ hostname:raid.mega.status.str( OK ) \}=0 +UserParameter=raid.mega.status,/var/lib/zabbix/bin/megaraid-parser.pl HERE } --- smeserver-zabbix-agent-0.1/root/var/lib/zabbix/bin/megaraid-parser.pl.megaraid_parser 2009-04-26 18:39:10.000000000 +0200 +++ smeserver-zabbix-agent-0.1/root/var/lib/zabbix/bin/megaraid-parser.pl 2009-04-26 18:38:39.000000000 +0200 @@ -0,0 +1,194 @@ +#!/usr/bin/perl -w + +# check_megaraid_sas Nagios plugin +# Copyright (C) 2007 Jonathan Delgado, delgado@molbio.mgh.harvard.edu +# +# 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; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# +# Nagios plugin to monitor the status of volumes attached to a LSI Megaraid SAS +# controller, such as the Dell PERC5/i and PERC5/e. If you have any hotspares +# attached to the controller, you can specify the number you should expect to +# find with the '-s' flag. +# +# The paths for the Nagios plugins lib and MegaCli may need to me changed. +# +# $Author: delgado $ +# $Revision: #3 $ $Date: 2007/06/07 $ + +# Slightly modified by Daniel B. for SME Server integration with zabbix +# 23 Apr 2009 + +use strict; +use Getopt::Std; + +our($opt_h, $opt_s); + + +getopts('hs:'); + +if ( $opt_h ) { + print "usage w/o hotspare: $0\n"; + print " w/ hotspare: $0 -s \n"; + exit; +} + +my $megacli = '/usr/bin/sudo /opt/MegaRAID/MegaCli/MegaCli'; + +## Return codes for Nagios +my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); + +my ($adapters); +my $hotspares = 0; +my $hotsparecount = 0; +my $pdbad = 0; +my $pdcount = 0; +my $pderrors = 0; +my $result = ''; +my $status = 'OK'; + +sub max_state ($$) { + my ($current, $compare) = @_; + + if (($compare eq 'CRITICAL') || ($compare eq 'CRITICAL')) { + return 'CRITICAL'; + } elsif ($compare eq 'OK') { + return $current; + } elsif ($compare eq 'WARNING') { + return 'WARNING'; + } elsif (($compare eq 'UNKNOWN') && ($current eq 'OK')) { + return 'UNKNOWN'; + } else { + return $current; + } +} + + +if ( $opt_s ) { + $hotspares = $opt_s; +} + +# Get the number of RAID controllers we have +open (ADPCOUNT, "$megacli -adpCount |") + || die "error: Could not execute MegaCli -adpCount"; + +while () { + if ( m/Controller Count:\s*(\d+)/ ) { + $adapters = $1; + last; + } +} +close ADPCOUNT; + +ADAPTER: for ( my $adp = 0; $adp < $adapters; $adp++ ) { + # Get the number of logical drives on this adapter + open (LDGETNUM, "$megacli -LdGetNum -a$adp |") + || die "error: Could not execute $megacli -LdGetNum -a$adp"; + + my ($ldnum); + while () { + if ( m/Number of Virtual drives configured on adapter \d:\s*(\d+)/ ) { + $ldnum = $1; + last; + } + } + close LDGETNUM; + + LDISK: for ( my $ld = 0; $ld < $ldnum; $ld++ ) { + # Get info on this particular logical drive + open (LDINFO, "$megacli -LdInfo -L$ld -a$adp |") + || die "error: Could not execute $megacli -LdInfo -L$ld -a$adp"; + + my ($size, $unit, $raidlevel, $ldpdcount, $state); + while () { + if ( m/Size:\s*((\d+)(MB|GB|TB))/ ) { + $size = $2; + $unit = $3; + # Adjust MB to GB if that's what we got + if ( $unit eq 'MB' ) { + $size = sprintf( "%.0f", ($size / 1024) ); + $unit= 'GB'; + } + } elsif ( m/State:\s*(\w+)/ ) { + $state = $1; + if ( $state ne 'Optimal' ) { + $status = 'CRITICAL'; + } + } elsif ( m/Number Of Drives:\s*(\d+)/ ) { + $ldpdcount = $1; + } elsif ( m/RAID Level: Primary-(\d)/ ) { + $raidlevel = $1; + } + } + close LDINFO; + + $result .= "$adp:$ld:RAID-$raidlevel:$ldpdcount drives:$size$unit:$state "; + + } #LDISK + close LDINFO; + + # Get info on physical disks for this adapter + open (PDLIST, "$megacli -PdList -a$adp |") + || die "error: Could not execute $megacli -PdList -a$adp"; + + my ($slotnumber,$fwstate); + PDISKS: while () { + if ( m/Slot Number:\s*(\d+)/ ) { + $slotnumber = $1; + $pdcount++ unless ( $slotnumber == 255 ); + } elsif ( m/Error Count:\s*(\d+)/ ) { + $pderrors += $1; + } elsif ( m/Predictive Failure Count:\s*(\d+)/ ) { + $pderrors += $1; + } elsif ( m/Firmware state:\s*(\w+)/ ) { + $fwstate = $1; + if ( $fwstate eq 'Hotspare' ) { + $hotsparecount++; + } elsif ( $fwstate eq 'Online' ) { + # Do nothing + } elsif ( $slotnumber != 255 ) { + $pdbad++; + $status = 'CRITICAL'; + } + } + } #PDISKS + close PDLIST; +} + +$result .= "Drives:$pdcount "; + +# Any bad disks? +if ( $pdbad ) { + $result .= "$pdbad Bad Drives "; +} + +# Were there any errors? +if ( $pderrors ) { + $result .= "($pderrors Errors) "; + $status = max_state($status, 'WARNING'); +} + +# Do we have as many hotspares as expected (if any) +if ( $hotspares ) { + if ( $hotsparecount < $hotspares ) { + $status = max_state($status, 'WARNING'); + $result .= "Hotspare(s):$hotsparecount (of $hotspares)"; + } else { + $result .= "Hotspare(s):$hotsparecount"; + } +} + +print STDOUT "$status: $result\n"; +exit $ERRORS{$status};