Plugin:check san switches


 * 1) !/bin/sh


 * 1) Version 0.0.3 2010-08-18
 * 2) Verify that the sensors check returns data. If not, return unknown to nagios.


 * 1) Version 0.0.2 2010-05-11
 * 2) Ulric Eriksson 

BASEOID=.1.3.6.1.3.94 SYSTEMOID=$BASEOID.1.6 connUnitStateOID=$SYSTEMOID.1.5 connUnitStatusOID=$SYSTEMOID.1.6 connUnitProductOID=$SYSTEMOID.1.7 connUnitSnOID=$SYSTEMOID.1.8 connUnitNumSensorsOID=$SYSTEMOID.1.14 connUnitNameOID=$SYSTEMOID.1.20 connUnitContactOID=$SYSTEMOID.1.23 connUnitLocationOID=$SYSTEMOID.1.24
 * 1) 1 = unknown, 2 = online, 3 = diag/offline
 * 1) 3 = OK, 4 = warning, 5 = failed
 * 1) e.g. "QLogic SANbox2 FC Switch"
 * 1) chassis serial number
 * 1) number of sensors in connUnitSensorTable
 * 1) symbolic name

SENSOROID=$BASEOID.1.8 connUnitSensorIndexOID=$SENSOROID.1.2 connUnitSensorNameOID=$SENSOROID.1.3 connUnitSensorStatusOID=$SENSOROID.1.4 connUnitSensorMessageOID=$SENSOROID.1.6
 * 1) textual id of sensor
 * 1) 1 = unknown, 2 = other, 3 = ok, 4 = warning, 5 = failed
 * 1) textual status message

PORTOID=$BASEOID.1.10 connUnitPortUnitIdOID=$PORTOID.1.1 connUnitPortIndexOID=$PORTOID.1.2 connUnitPortTypeOID=$PORTOID.1.3 connUnitPortStateOID=$PORTOID.1.6 connUnitPortStatusOID=$PORTOID.1.7 connUnitPortSpeedOID=$PORTOID.1.15
 * 1) user selected state
 * 2) 1 = unknown, 2 = online, 3 = offline, 4 = bypassed, 5 = diagnostics
 * 1) actual status
 * 2) 1 = unknown, 2 = unused, 3 = ready, 4 = warning, 5 = failure
 * 3) 6 = notparticipating, 7 = initializing, 8 = bypass, 9 = ols, 10 = other
 * 4) Always returns 2, so this is utterly useless
 * 1) port speed in kilobytes per second

usage {	echo "Usage: $0 -H host -C community -T status|sensors" exit 0 }

get_system {       echo "$SYSTEM"|grep "^$1."|head -1|sed -e 's,^.*: ,,' }

get_sensor {       echo "$SENSOR"|grep "^$2.*$1 = "|head -1|sed -e 's,^.*: ,,' }

get_port {       echo "$PORT"|grep "^$2.*$1 = "|head -1|sed -e 's,^.*: ,,' }

if test "$1" = -h; then usage fi

while getopts "H:C:T:" o; do	case "$o" in	H )		HOST="$OPTARG"		;;	C ) COMMUNITY="$OPTARG" ;;	T )		TEST="$OPTARG"		;;	* ) usage ;;	esac done

RESULT= STATUS=0	# OK

case "$TEST" in sensors )	SENSOR=`snmpwalk -v 1 -c $COMMUNITY -On $HOST $SENSOROID`	# Figure out which sensor indexes we have	connUnitSensorIndex=`echo "$SENSOR"|	grep -F "$connUnitSensorIndexOID."|	sed -e 's,^.*: ,,'`	for i in $connUnitSensorIndex; do		connUnitSensorName=`get_sensor $i $connUnitSensorNameOID`		connUnitSensorStatus=`get_sensor $i $connUnitSensorStatusOID`		connUnitSensorMessage=`get_sensor $i $connUnitSensorMessageOID`		RESULT="$RESULT$connUnitSensorName = $connUnitSensorMessage "		if test "$connUnitSensorStatus" != 3; then			STATUS=2	# Critical		fi	done	if test -z "$SENSOR"; then		STATUS=3	# Unknown	fi	;; status ) SYSTEM=`snmpwalk -v 1 -c $COMMUNITY -On $HOST $SYSTEMOID` connUnitStatus=`get_system $connUnitStatusOID` connUnitProduct=`get_system $connUnitProductOID` connUnitSn=`get_system $connUnitSnOID` case "$connUnitStatus" in	3 )		RESULT="Overall unit status: OK"		;;	4 ) RESULT="Overall unit status: Warning" STATUS=1 ;;	5 )		RESULT="Overall unit status: Failed"		STATUS=2		;;	* ) RESULT="Overall unit status: Unknown" STATUS=3 ;;	esac if test ! -z "$connUnitProduct"; then RESULT="$RESULT Product: $connUnitProduct" fi if test ! -z "$connUnitSn"; then RESULT="$RESULT Serial number: $connUnitSn" fi ;;	usage ;; esac

echo "$RESULT" exit $STATUS