#!/bin/bash if [ ! "$#" == "3" ]; then echo -e "\nWarning: Wrong command line arguments. \nUsage: ./check_huawei \n \nParts are: lunusage, poolusage, poolstatus, cpu, tempsys, hdstatus, psustatus, fanstatus, controller, enclosure, bbustatus, uptime, memuse, traffic, latency and iops\nExample: ./check_huawei 127.0.0.1 public poolusage 10 5\n" && exit "3" fi strHostname=$1 strCommunity=$2 strpart=$3 strWarning=$4 strCritical=$5 # Check ob Storage erreichbar ist TEST=$(snmpstatus -v 1 $strHostname -c "$strCommunity" -t 5 -r 0 2>&1) # echo "Test: $TEST"; if [ "$TEST" == "Timeout: No Response from $strHostname" ]; then echo "CRITICAL: SNMP to $strHostname is not available"; exit 2; fi # LUNUSAGE --------------------------------------------------------------------------------------------------------------------------------------- if [ "$strpart" == "lunusage" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.8.1.2 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.8.1.1 | tr '\n' ' ')) declare -a capacity=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.8.1.5 | tr '\n' ' ')) declare -a usedspace=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.8.1.6 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do let "perc=(100-(${usedspace[c]}*100)/${capacity[c]})" perfdata="$perfdata LUN${nums[c]}=$perc;$strWarning;$strCritical" if [[ ${perc[${c}]} > $strCritical ]] then status="CRIT" crit="$crit LUN ${nums[c]} $perc% free" elif [[ ${perc[${c}]} > $strWarning ]] then status="WARN" warn="$warn LUN ${nums[c]} $perc% free" else status="OK" ok="$ok LUN ${nums[c]} $perc% free" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical: $crit |$perfdata" exit 2 elif [ "$status" == "WARN" ] then echo "Warning: $warn |$perfdata" exit 1 elif [ "$status" == "OK" ] then echo "OK: $ok |$perfdata" exit 0 else echo "No Performance Data" exit 0 fi fi # Poolusage ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "poolusage" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.2.1.2 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.2.1.1 | tr '\n' ' ')) declare -a capacity=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.2.1.7 | tr '\n' ' ')) declare -a freespace=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.2.1.9 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do let used=${capacity[c]}-${freespace[c]} let "perc=(100-($used*100)/${capacity[c]})" perfdata="$perfdata Pool${ids[c]}=$perc;$strWarning;$strCritical;;;PoolGB${ids[c]}=$used;;;;;" if [[ ${perc[${c}]} < $strCritical ]] then status="CRIT" crit="$crit Pool ${nums[c]} $perc% free" elif [[ ${perc[${c}]} < $strWarning ]] then status="WARN" warn="$warn Pool ${nums[c]} $perc% free" else status="OK" ok="$ok Pool ${nums[c]} $perc% free" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical: $crit |$perfdata" exit 2 elif [ "$status" == "WARN" ] then echo "Warning: $warn |$perfdata" exit 1 elif [ "$status" == "OK" ] then echo "OK: $ok |$perfdata" exit 0 else echo "No Performance Data" exit 0 fi fi # Poolstatus ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "poolstatus" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.2.1.2 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.2.1.1 | tr '\n' ' ')) declare -a status=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.2.1.5 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do if [[ ${status[${c}]} != 1 ]] then status="CRIT" elif [[ ${status[${c}]} = 1 ]] then status="OK" else status="unknown" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical" exit 2 elif [ "$status" == "WARN" ] then echo "Warning" exit 1 elif [ "$status" == "OK" ] then echo "OK" exit 0 else echo "No Performance Data" exit 0 fi fi # CPU ---------------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "cpu" ]; then declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.21.3.1.1 | tr '\n' ' ')) declare -a cpu=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.21.3.1.2 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do perfdata="$perfdata CPU${ids[c]}=$cpu;$strWarning;$strCritical" if [[ ${cpu[${c}]} > $strCritical ]] then status="CRIT" crit="$crit CPU${ids[c]} $cpu" elif [[ ${cpu[${c}]} > $strWarning ]] then status="WARN" warn="$warn CPU${ids[c]} $cpu" else status="OK" ok="$ok CPU${ids[c]} $cpu %" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical: $crit% |$perfdata" exit 2 elif [ "$status" == "WARN" ] then echo "Warning: $warn% |$perfdata" exit 1 elif [ "$status" == "OK" ] then echo "OK: $ok |$perfdata" exit 0 else echo "No Performance Data" exit 0 fi fi # SYSTEM Temperature--------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "tempsys" ]; then TEMPSYS=$(snmpwalk -t 120 -v 1 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.6.1.8) strOutput="System Temp=$[TEMPSYS]C|'System Temp C'=$[TEMPSYS]C;$strWarning;$strCritical" if [ $TEMPSYS -ge "$strCritical" ]; then echo "CRITICAL: "$strOutput exit 2 fi if [ $TEMPSYS -ge "$strWarning" ]; then echo "WARNING: "$strOutput exit 1 fi echo "OK: "$strOutput exit 0 # HD Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "hdstatus" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.1.1.4 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.1.1.1 | tr '\n' ' ')) declare -a status=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.1.1.2 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do if [[ ${status[${c}]} != 1 ]] then status="CRIT" crit="$crit DISK${ids[c]} $status" elif [[ ${status[${c}]} = 1 ]] then status="OK" else status="unknown" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical" exit 2 elif [ "$status" == "WARN" ] then echo "Warning" exit 1 elif [ "$status" == "OK" ] then echo "OK" exit 0 else echo "No Performance Data" exit 0 fi fi # PSU Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "psustatus" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.3.1.2 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.3.1.1 | tr '\n' ' ')) declare -a status=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.3.1.3 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do if [[ ${status[${c}]} != 1 ]] then status="CRIT" crit="$crit PSU${ids[c]} $status" elif [[ ${status[${c}]} = 1 ]] then status="OK" else status="unknown" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical" exit 2 elif [ "$status" == "WARN" ] then echo "Warning" exit 1 elif [ "$status" == "OK" ] then echo "OK" exit 0 else echo "No Performance Data" exit 0 fi fi # FAN Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "fanstatus" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.4.1.2 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.4.1.1 | tr '\n' ' ')) declare -a status=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.4.1.3 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do if [[ ${status[${c}]} != 1 ]] then status="CRIT" crit="$crit FAN${ids[c]} $status" elif [[ ${status[${c}]} = 1 ]] then status="OK" else status="unknown" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical" exit 2 elif [ "$status" == "WARN" ] then echo "Warning" exit 1 elif [ "$status" == "OK" ] then echo "OK" exit 0 else echo "No Performance Data" exit 0 fi fi # Controller Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "controller" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.2.1.5 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.2.1.1 | tr '\n' ' ')) declare -a status=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.2.1.2 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do if [[ ${status[${c}]} != 1 ]] then status="CRIT" crit="$crit Controller${ids[c]} $status" elif [[ ${status[${c}]} = 1 ]] then status="OK" else status="unknown" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical" exit 2 elif [ "$status" == "WARN" ] then echo "Warning" exit 1 elif [ "$status" == "OK" ] then echo "OK" exit 0 else echo "No Performance Data" exit 0 fi fi # Enclusure Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "enclosure" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.6.1.2 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.6.1.1 | tr '\n' ' ')) declare -a status=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.6.1.4 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do if [[ ${status[${c}]} != 1 ]] then status="CRIT" crit="$crit Enclosure${ids[c]} $status" elif [[ ${status[${c}]} = 1 ]] then status="OK" else status="unknown" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical" exit 2 elif [ "$status" == "WARN" ] then echo "Warning" exit 1 elif [ "$status" == "OK" ] then echo "OK" exit 0 else echo "No Performance Data" exit 0 fi fi # BBU Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "bbustatus" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.5.1.2 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.5.1.1 | tr '\n' ' ')) declare -a status=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.5.1.3 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do if [[ ${status[${c}]} != 1 ]] then status="CRIT" crit="$crit BBU${ids[c]} $status" elif [[ ${status[${c}]} = 1 ]] then status="OK" else status="unknown" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical" exit 2 elif [ "$status" == "WARN" ] then echo "Warning" exit 1 elif [ "$status" == "OK" ] then echo "OK" exit 0 else echo "No Performance Data" exit 0 fi fi # Uptime Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "uptime" ]; then UPTIME=$(snmpwalk -t 120 -v 1 -O vqet -c $strCommunity $strHostname .1.3.6.1.2.1.1.3.0) strOutput=$UPTIME seconds=$((UPTIME/100%60)) minutes=$((UPTIME/100/60%60)) hours=$((UPTIME/100/60/60%24)) days=$((UPTIME/100/60/60/24)) strOutput="$days days, $hours hours, $minutes minutes, $seconds seconds|Uptime=$UPTIME;;;;;" echo $strOutput exit 0 # Memory Status--------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "memuse" ]; then declare -a nums=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.2.1.5 )) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.2.1.1 | tr '\n' ' ')) declare -a memusage=($(snmpwalk -t 120 -v 2c -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.5.2.1.9 )) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do perfdata="$perfdata ${nums[c]}=${memusage[${c}]};$strWarning;$strCritical" if [[ ${memusage[${c}]} > $strCritical ]] then status="CRIT" crit="$crit Memory${nums[c]} ${memusage[${c}]} %" elif [[ ${memusage[${c}]} > $strWarning ]] then status="WARN" warn="$warn Memory${nums[c]} ${memusage[${c}]} %" else status="OK" ok="$ok ${nums[${c}]} ${memusage[${c}]} %" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical: $crit% |$perfdata" exit 2 elif [ "$status" == "WARN" ] then echo "Warning: $warn% |$perfdata" exit 1 elif [ "$status" == "OK" ] then echo "OK: $ok |$perfdata" exit 0 else echo "No Performance Data" exit 0 fi fi strOutput="$[MEMUSE]% free|'MEMUSE'=$[MEMUSE]%;$strWarning;$strCritical" if [ $MEMUSE -lt "$strCritical" ]; then echo "CRITICAL: "$strOutput exit 2 fi if [ $MEMUSE -lt "$strWarning" ]; then echo "WARNING: "$strOutput exit 1 fi echo "OK: "$strOutput exit 0 # IOPS Status ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "iops" ]; then declare -a luns=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.8.1.2 | tr '\n' ' ' | sed 's/\"/ /g')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.21.4.1.1 | tr '\n' ' ')) declare -a ios=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.21.4.1.3 | tr '\n' ' ')) c=0 for line in ${ids[@]} do perfdata="$perfdata ${luns[c]}=${ios[c]};0;0" sum=$((sum+${ios[c]})) let c++ done echo "IOPS: $sum|All=$sum;0;0 $perfdata" exit 0 # Traffic Status ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "traffic" ]; then declare -a luns=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.19.8.12.1.2 | tr '\n' ' ' | sed 's/\"/ /g')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.21.3.1.1 | tr '\n' ' ')) declare -a traf=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.21.3.1.8 | tr '\n' ' ')) c=0 for line in ${ids[@]} do perfdata="$perfdata ${luns[c]}=${traf[c]};0;0" sum=$((sum+${traf[c]})) let c++ done echo "Traffic: $sum MB/s|All=$sum;0;0 $perfdata" exit 0 # Latencystatus ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "latency" ]; then declare -a luns=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.23.4.8.1.2 | tr '\n' ' ' | sed 's/\"/ /g')) declare -a ids=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.21.4.1.1 | tr '\n' ' ')) declare -a lat=($(snmpwalk -v 2c -t 120 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.34774.4.1.21.4.1.13 | tr '\n' ' ')) c=0 for line in ${ids[@]} do perfdata="$perfdata ${luns[c]}=${lat[c]};$strWarning;$strCritical" if [[ ${lat[${c}]} -ge $strCritical ]] then status="CRIT" crit="$crit ${luns[c]} ${lat[c]}µs" elif [[ ${lat[${c}]} -ge $strWarning ]] then status="WARN" warn="$warn ${luns[c]} ${lat[c]}µs" else status="OK" ok="$ok ${luns[c]} ${lat[c]}µs" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical: $crit|$perfdata" exit 2 elif [ "$status" == "WARN" ] then echo "Warning: $warn|$perfdata" exit 1 elif [ "$status" == "OK" ] then echo "OK|$perfdata" exit 0 else echo "No Performance Data" exit 0 fi #---------------------------------------------------------------------------------------------------------------------------------------------------- else echo -e "\nUnknown Part!" && exit "3" fi exit 0