Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- APPNAME=$(basename $0)
- ###############################
- # Check binaries before start #
- ###############################
- binaries=$(cat<<all_required_binaries
- snmpwalk
- all_required_binaries)
- for required_binary in $binaries; do
- which $required_binary > /dev/null
- if [ "$?" != '0' ];then
- printf "UNKNOWN: $APPNAME: No usable '$required_binary' binary in '$PATH'\n"
- exit 3
- fi
- done
- ######################
- # print Help Message #
- ######################
- usage () {
- cat<<EOU
- Usage of $APPNAME
- ---------------------------------------------------------------------
- Usable Options:
- -H fileserver
- The Hostname variable, set your hostname instead of fileserver
- (Required option)
- -C public
- The SNMP Community variable, set your SNMP read community here
- (Required Option)
- -h
- This help message
- Examples:
- $APPNAME -H fileserver -C public
- ---------------------------------------------------------------------
- EOU
- exit 3
- }
- ################################
- # Get Options from commandline #
- ################################
- while getopts "C:H:h" option
- do
- case $option in
- C ) COMMUNITY=$OPTARG ;;
- H ) HOST=$OPTARG ;;
- h ) usage ;;
- esac
- done
- ###########################################
- # Exit Unknown if not all arguments given #
- ###########################################
- if [ -z "$COMMUNITY" ] || [ -z "$HOST" ];then
- printf "UNKNOWN: No hostname and/or community set!"
- exit 3
- fi
- ###########################
- # Main part of the script #
- ###########################
- # Execute snmpwalk - Ouput is "FanNumer: Statuscode" #
- WALK=$(snmpwalk -v 2c -c $COMMUNITY $HOST .1.3.6.1.4.1.232.6.2.6.7.1.9 | cut -f4 -d ':')
- FANSTATUS=$(echo "$WALK" | grep -n [134])
- if [ -z "$WALK" ];then
- printf "No proper SNMP response or SNMP timeout. Check host or community string\n"
- exit 3
- fi
- # Get amount of failed fans #
- AMOUNT=$(echo "$FANSTATUS" | grep -o ' ' | wc -l)
- # Exit OK if no fan failed
- if [ $AMOUNT -eq "0" ];then
- printf "OK: All Fans running"
- exit 0
- # General failure if more than one fan failed
- elif [ "$AMOUNT" -gt "1" ];then
- printf "CRIT: $AMOUNT fans failed! Check HP Management Homepage"
- exit 2
- else
- # Get failed fans index number
- NUMBER=$(echo $FANSTATUS | cut -f1 -d ':')
- # Get Errorcode of failed fan
- CODE=$(echo $FANSTATUS | cut -f2 -d ':')
- # Translate Errorcode
- # Error 1
- if [ $CODE = 2 ];then
- printf "UNKNOWN: 1 (Fan check not supported for this system)"
- exit 3
- fi
- # Error 2
- if [ $CODE = 2 ];then
- DESCR="2 (Fan OK)"
- fi
- # Error 3
- if [ $CODE = 3 ];then
- DESCR="3 (Fan degraded)"
- fi
- # Error 4
- if [ $CODE = 4 ];then
- DESCR="4 (Fan failed)"
- fi
- printf "WARN: Fan Number $NUMBER failed with status $DESCR"
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment