IBM服务器RAID卡Nagios监控脚本

#!/bin/bash

#Global Definition
Help_Message="\nParameters is incorrect,please use as follow:\n`basename $0` -H HOSTIP -U USERID -P PASSWORD"
export HOSTIP
export USERID
export PASSWORD
export ipmi_command=`which ipmitool`

#Paramters
if [ "$#" -ne 6 ]
	then 
		echo -e "${Help_Message}"
		exit 3
fi
while getopts ":H:U:P:" OPTNAME
	do
		case "$OPTNAME" in
			H)
				HOSTIP="$OPTARG"
				;;
			U)
				USERID="$OPTARG"
				;;
			P)
				PASSWORD="$OPTARG"
				;;
			*)
				echo "${Help_Message}"
				exit 3
				;;
		esac
	done

#Get the status of Drivers information
export SOURCEFILE=/tmp/ipmi_drive_check-"${HOSTIP}".txt   	                   
eval "$ipmi_command -H \"$HOSTIP\" -U \"$USERID\" -P \"$PASSWORD\"  sdr type \"Drive Slot / Bay\" >$SOURCEFILE"
export FAILED=`grep "Failed Array" $SOURCEFILE | wc -l`                			#Is the RAID completely failed or not
export FAULT=`grep "Critical Array" $SOURCEFILE | wc -l`                			#Amount of failed drivers
export UNCFGED=`grep "Predictive Failure" $SOURCEFILE | wc -l`         	#Amount of unconfigured drivers
export Drive_Message=""
export RMSRC="`which rm` -f $SOURCEFILE"

#Start
if [[ ! -f $SOURCEFILE || ! -s $SOURCEFILE ]]
	then
		echo "Unknown.Unable to obtain drive messages!"
                $RMSRC  >/dev/null 2>&1      																#Status Unkown,return 3
		exit 3
fi
if  (( "$UNCFGED" ))
	then
		Drive_Message=`awk -F '|' '/Predictive Failure/{print $1}' $SOURCEFILE |xargs`
		Drive_Message="$Drive_Message is Unconfigured Good!"
fi   
if  (( "$FAULT" ))                              																		#Existing failed drivers
	then
		FAULTDRIVE=`grep "Fault" $SOURCEFILE | awk -F '|' '{print $1}' | xargs`
		PD_Driver=`grep  "Drive Present" $SOURCEFILE | egrep -v 'Critical|Failed|Failure|Fault' |awk -F"|" '{print $1}' | xargs ` 
		if [ "$FAULTDRIVE" ]
			then 
				Drive_Message="$Drive_Message :$FAULTDRIVE is Fault!"
		fi
		if [ "$PD_Driver" ]
			then 
				Drive_Message="$Drive_Message :$PD_Driver PD Missing!"
		fi
		echo "Warning!$Drive_Message"
		$RMSRC  >/dev/null 2>&1
		exit 1
elif   (( "$FAILED" ))						
	then
		Drive_Message="$Drive_Message|` grep 'Failed Array' $SOURCEFILE |cut -d '|' -f1 |xargs`"
		echo "Critical!${Drive_Message} Failed!"
		$RMSRC  >/dev/null 2>&1 	 
		exit 2
else
	Drive_Fault="`grep 'Drive Fault' $SOURCEFILE |awk -F '|' '{print $1}' | xargs`" 
	if [ "$Drive_Fault" ]
		then
			Drive_Message="$Drive_Message:$Drive_Fault is Fault and not in logic drive."
	fi 
fi
$RMSRC  >/dev/null 2>&1
echo "Logic drive status:OK;$Drive_Message"
exit 0

你可能感兴趣的:(shell,nagios,监控脚本,RAID卡)