2010-03-01 23:17:45 +01:00
|
|
|
#! /bin/sh
|
|
|
|
######################################################################
|
|
|
|
# Name: check_hparray
|
|
|
|
# By: Copyright (C) 2007 Magnus Glantz
|
|
|
|
# Credits to: andreiw
|
|
|
|
# Modified by: palli@ok.is 2010-02-21
|
|
|
|
######################################################################
|
|
|
|
# Licence: GPL 2.0
|
|
|
|
######################################################################
|
|
|
|
# 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.
|
|
|
|
######################################################################
|
|
|
|
# Description:
|
|
|
|
#
|
|
|
|
# A Nagios plugin that checks HP Proliant hardware raid via the HPACUCLI tool.
|
|
|
|
#
|
|
|
|
# HPACUCLI needs administrator rights.
|
|
|
|
# add this line to /etc/sudoers
|
|
|
|
#
|
|
|
|
# nagios ALL=NOPASSWD: /usr/sbin/hpacucli
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
|
|
PROGNAME=`basename $0`
|
|
|
|
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
|
|
|
|
REVISION=`echo '$Revision: 1.0 $' | sed -e 's/[^0-9.]//g'`
|
|
|
|
HPACUCLI=/usr/sbin/hpacucli
|
|
|
|
|
|
|
|
STATE_OK=0
|
|
|
|
STATE_WARNING=1
|
|
|
|
STATE_CRITICAL=2
|
|
|
|
STATE_UNKNOWN=3
|
|
|
|
STATE_DEPENDENT=4
|
|
|
|
|
2010-07-28 15:26:14 +02:00
|
|
|
|
|
|
|
TEMPFILE=`mktemp`
|
2010-09-03 01:30:27 +02:00
|
|
|
alias print_revision=echo
|
2010-07-28 15:26:14 +02:00
|
|
|
|
2010-03-01 23:17:45 +01:00
|
|
|
print_usage() {
|
|
|
|
echo ""
|
|
|
|
echo "Usage: $PROGNAME -s <slot-number>"
|
|
|
|
echo "Usage: $PROGNAME --all"
|
|
|
|
echo "Usage: $PROGNAME [-h | --help]"
|
|
|
|
echo "Usage: $PROGNAME [-V | --version]"
|
|
|
|
echo ""
|
|
|
|
echo " NOTE:"
|
|
|
|
echo ""
|
|
|
|
echo " HPACUCLI needs administrator rights."
|
|
|
|
echo " add this line to /etc/sudoers"
|
|
|
|
echo " nagios ALL=NOPASSWD: /usr/sbin/hpacucli"
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
print_help() {
|
|
|
|
print_revision $PROGNAME $REVISION
|
|
|
|
echo ""
|
|
|
|
print_usage
|
|
|
|
echo ""
|
|
|
|
echo "This plugin checks hardware status for HP Proliant servers using HPACUCLI utility."
|
|
|
|
echo ""
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
print_usage
|
|
|
|
exit $STATE_UNKNOWN
|
|
|
|
fi
|
|
|
|
|
|
|
|
check_raid()
|
|
|
|
{
|
2010-07-28 15:26:14 +02:00
|
|
|
raid_ok=`cat $TEMPFILE |grep -i ok|wc -l`
|
|
|
|
raid_warning=`cat $TEMPFILE|grep -i -E 'rebuild|predictive' |wc -l`
|
2015-10-14 22:23:12 +02:00
|
|
|
raid_critical_1=`cat $TEMPFILE|grep -i -E 'failed|recovery' | wc -l`
|
2010-03-01 23:17:45 +01:00
|
|
|
|
2010-07-28 15:26:14 +02:00
|
|
|
err_check=`expr $raid_ok + $raid_warning + $raid_critical_1 `
|
2010-03-01 23:17:45 +01:00
|
|
|
|
|
|
|
if [ $err_check -eq "0" ]; then
|
2010-07-28 15:26:14 +02:00
|
|
|
checkm=`cat $TEMPFILE|sed -e '/^$/ d'`
|
2010-03-01 23:17:45 +01:00
|
|
|
echo "$PROGNAME Error. $checkm"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $raid_ok -ge "1" ]; then
|
|
|
|
exit_status=$STATE_OK
|
2010-07-28 15:26:14 +02:00
|
|
|
fi
|
|
|
|
if [ $raid_warning -ge "1" ]; then
|
2010-03-01 23:17:45 +01:00
|
|
|
exit_status=$STATE_WARNING
|
2010-07-28 15:26:14 +02:00
|
|
|
fi
|
|
|
|
if [ $raid_critical_1 -ge "1" ]; then
|
2010-03-01 23:17:45 +01:00
|
|
|
exit_status=$STATE_CRITICAL
|
2010-07-28 15:26:14 +02:00
|
|
|
fi
|
2010-03-01 23:17:45 +01:00
|
|
|
|
|
|
|
if [ $exit_status -eq "0" ]; then
|
2010-07-28 15:26:14 +02:00
|
|
|
echo "RAID OK - ($raid_ok disks ok)"
|
2010-03-01 23:17:45 +01:00
|
|
|
elif [ $exit_status -eq "1" ]; then
|
2010-07-28 15:26:14 +02:00
|
|
|
echo "RAID WARNING - ($raid_ok OK; $raid_warning warnings)"
|
2010-03-01 23:17:45 +01:00
|
|
|
elif [ $exit_status -eq "2" ]; then
|
2010-07-28 15:26:14 +02:00
|
|
|
echo "RAID CRITICAL - ($raid_ok OK; $raid_warning warnings; $raid_critical_1 crit)"
|
2010-03-01 23:17:45 +01:00
|
|
|
fi
|
2010-07-28 15:26:14 +02:00
|
|
|
cat $TEMPFILE
|
|
|
|
rm -f "$TEMPFILE"
|
|
|
|
exit $exit_status
|
|
|
|
|
2010-03-01 23:17:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
--help)
|
|
|
|
print_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-h)
|
|
|
|
print_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--version)
|
|
|
|
print_revision $PROGNAME $REVISION
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-V)
|
|
|
|
print_revision $PROGNAME $REVISION
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--all)
|
2015-10-15 01:24:53 +02:00
|
|
|
controllers=`sudo -u root $HPACUCLI controller all show | sed 's/.*Slot \([0-9]*\).*/\1/'`
|
2010-07-28 15:26:14 +02:00
|
|
|
for i in $controllers ; do sudo -u root $HPACUCLI controller slot=$i pd all show status;done > $TEMPFILE
|
2010-03-01 23:17:45 +01:00
|
|
|
check_raid
|
|
|
|
;;
|
|
|
|
-s)
|
2010-07-28 15:26:14 +02:00
|
|
|
sudo -u root $HPACUCLI controller slot=$2 pd all show status > $TEMPFILE
|
2010-03-01 23:17:45 +01:00
|
|
|
check_raid
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
print_usage
|
|
|
|
;;
|
|
|
|
esac
|