#!/bin/bash if [ ! "$#" == "5" ]; then echo -e "\nWarning: Wrong command line arguments. \nUsage: ./check_qnap \n \nParts are: iops, latency, fanspeed, cpu, diskusage, poolusage, poolstatus, lunusage,memuse, tempcpu, tempsys, uptime, hdstatus and volstatus (volstatus = Raid Info)\nExample: ./check_qnap 127.0.0.1 public diskusage 80 95\n" && exit "3" fi strHostname=$1 strCommunity=$2 strpart=$3 strWarning=$4 strCritical=$5 # Check ob QNAP 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 # DISKUSAGE --------------------------------------------------------------------------------------------------------------------------------------- if [ "$strpart" == "diskusage" ]; then disk=$(snmpget -v1 -c "$strCommunity" -mALL "$strHostname" 1.3.6.1.4.1.24681.1.2.17.1.4.1 | awk '{print $4}' | sed 's/.\(.*\)/\1/') used=$(snmpget -v1 -c "$strCommunity" -mALL "$strHostname" 1.3.6.1.4.1.24681.1.2.17.1.5.1 | awk '{print $4}' | sed 's/.\(.*\)/\1/') freedisk=$(snmpget -v1 -c "$strCommunity" -mALL "$strHostname" 1.3.6.1.4.1.24681.1.2.17.1.5.1 | awk '{print $4, $5}' | sed 's/.\(.*\)/\1/') GBtest=$(snmpget -v1 -c "$strCommunity" -mALL "$strHostname" 1.3.6.1.4.1.24681.1.2.17.1.5.1 | awk '{print $5}' | sed 's/.*\(GB\).*/\1/') disk=$(echo "scale=0; $disk*100" | bc -l | sed 's/\(.*\).../\1/') if [ "$GBtest" == "GB" ]; then used=$(echo "scale=0; $used*100/1000" | bc -l | sed 's/\(.*\).../\1/') else used=$(echo "scale=0; $used*100" | bc -l | sed 's/\(.*\).../\1/') fi let "PERC=(100-($used*100)/$disk)" strOutput="Used=$[PERC]% 'free Disk'=$freedisk|'Used'=$[PERC]%;$strWarning;$strCritical;0;100" if [ $PERC -ge "$strCritical" ]; then echo "CRITICAL: "$strOutput exit 2 fi if [ $PERC -ge "$strWarning" ]; then echo "WARNING: "$strOutput exit 1 fi echo "OK: "$strOutput exit 0 # Poolusage ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "poolusage" ]; then declare -a nums=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.2.2.2.1.1 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.2.2.2.1.2 | tr '\n' ' ')) declare -a capacity=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.2.2.2.1.3 | tr '\n' ' ')) declare -a freespace=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.2.2.2.1.4 | 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" if [[ ${perc[${c}]} -le $strCritical ]] then status="CRIT" crit="$crit Pool ${nums[c]} $perc" elif [[ ${perc[${c}]} -le $strWarning ]] then status="WARN" warn="$warn Pool ${nums[c]} $perc" else status="OK" ok="$ok Pool ${nums[c]} $perc" fi let c++ done if [ "$status" == "CRIT" ] then echo "Critical: $crit% free|$perfdata" exit 2 elif [ "$status" == "WARN" ] then echo "Warning: $warn% free|$perfdata" exit 1 elif [ "$status" == "OK" ] then echo "OK: $ok% free|$perfdata" exit 0 else echo "No Performance Data" exit 0 fi fi # Poolstatus ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "poolstatus" ]; then declare -a nums=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.2.2.2.1.1 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.2.2.2.1.2 | tr '\n' ' ')) declare -a status=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.2.2.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}]} -eq -3 ]] then status="CRIT" elif [[ ${status[${c}]} -eq -1 ]] then status="WARN" elif [[ ${status[${c}]} -eq 0 ]] 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 # LUNusage ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "lunusage" ]; then declare -a names=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.2.1.10.2.1.6 | tr '\n' ' ' | sed 's/\"/ /g')) declare -a ids=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.2.1.10.2.1.2 | tr '\n' ' ')) declare -a used=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.2.1.10.2.1.4 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do perfdata="$perfdata LUN ${names[c]}=${used[c]};$strWarning;$strCritical" if [[ ${used[${c}]} -ge $strCritical ]] then critical="CRIT" crit="$crit LUN ${names[c]} ${used[c]}% used" elif [[ ${used[${c}]} -ge $strWarning ]] then warning="WARN" warn="$warn LUN ${names[c]} ${used[c]}% used" else status="OK" ok="$ok LUN ${names[c]} ${used[c]}% used" fi let c++ done if [ "$critical" == "CRIT" ] then echo "Critical: $crit|$perfdata" exit 2 elif [ "$warning" == "WARN" ] then echo "Warning: $warn|$perfdata" exit 1 elif [ "$status" == "OK" ] then echo "OK: $ok used|$perfdata" exit 0 else echo "No Performance Data" exit 0 fi fi # CPU ---------------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "cpu" ]; then CPU=$(snmpget -v1 -c "$strCommunity" -mALL $strHostname 1.3.6.1.4.1.24681.1.2.1.0 | awk -F : '{print $4}' | sed 's/\"/ /g' | sed 's/\./ /g' | cut -c2-4) echo "CPU: "$CPU"%" strOutput="CPU=$[CPU]%|'CPU'=$[CPU]%;$strWarning;$strCritical;0;100" if [ $CPU -ge "$strCritical" ]; then echo "CRITICAL: "$strOutput"%" exit 2 fi if [ $CPU -ge "$strWarning" ]; then echo "WARNING: "$strOutput"%" exit 1 fi echo "OK: "$strOutput exit 0 # CPU Temperature--------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "tempcpu" ]; then TEMPCPU=$(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.3.5) strOutput="CPUTemp=$[TEMPCPU]C|'CPUTemp C'=$[TEMPCPU]C;$strWarning;$strCritical" if [ $TEMPCPU -ge "$strCritical" ]; then echo "CRITICAL: "$strOutput exit 2 fi if [ $TEMPCPU -ge "$strWarning" ]; then echo "WARNING: "$strOutput exit 1 fi echo "OK: "$strOutput exit 0 # SYSTEM Temperature--------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "tempsys" ]; then TEMPSYS=$(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.3.6) 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 # Volume Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "volstatus" ]; then Vol_Status=$(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.2.17.1.6.1 | tr '\n' ' '| sed 's/\"/ /g') if [ $Vol_Status == Ready ]; then echo OK: $Vol_Status exit 0 elif [ "$Vol_Status" == "Rebuilding..." ]; then echo "Warning: "$Vol_Status exit 1 else echo "CRITICAL: "$Vol_Status exit 2 fi # HD Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "hdstatus" ]; then declare -a hddnames=($(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.3.11.1.2 | tr '\n' ' ')) declare -a hddcrit=($(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.3.11.1.7 | grep -n "Critical" | awk -F : '{print $1}' | tr '\n' ' ')) c=0 for line in ${hddcrit[@]} do hddcrit[$c]=`expr ${hddcrit[$c]} - 1` let c++ done # find the corresponding names of the critical drives c=0 for line in ${hddcrit[@]} do hddfinalcrit[${c}]=${hddnames[$line]} let c++ done declare -a hddwarn=($(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.3.11.1.7 | grep -n "Warning" | awk -F : '{print $1}' | tr '\n' ' ')) c=0 for line in ${hddwarn[@]} do hddwarn[$c]=`expr ${hddwarn[$c]} - 1` let w++ done # find the corresponding names of the critical drives c=0 for line in ${hddwarn[@]} do hddfinalwarn[${c}]=${hddnames[$line]} let w++ done declare -a hddwarn=($(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.3.11.1.7 | grep -n "Normal" | awk -F : '{print $1}' | tr '\n' ' ')) c=0 for line in ${hddwarn[@]} do hddwarn[$c]=`expr ${hddwarn[$c]} - 1` let w++ done # find the corresponding names of the critical drives c=0 for line in ${hddwarn[@]} do hddfinalwarn[${c}]=${hddnames[$line]} let w++ done if [[ ${#hddfinalcrit[*]} -gt 0 ]] then echo "CRITICAL Drives: ${hddfinalcrit[*]}"; exit 2 elif [[ ${#hddfinalwarn[*]} -gt 0 ]] then echo "WARNING Drives: ${hddfinalwarn[*]}"; exit 1 else echo "All Drives OK"; exit 0 fi # Uptime Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "uptime" ]; then UPTIME=$(snmpwalk -v 1 -O vqet -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.2.4) 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" echo $strOutput exit 0 # Memory Status--------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "memuse" ]; then MEMTOTAL=$(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.2.2 | sed 's/\"/ /g') MEMFREE=$(snmpwalk -v 1 -O vqe -c $strCommunity $strHostname 1.3.6.1.4.1.24681.1.2.3 | sed 's/\"/ /g') MEMTOTAL=${MEMTOTAL%.*} MEMFREE=${MEMFREE%.*} MEMUSE=$((100*$MEMFREE/MEMTOTAL)) strOutput="$[MEMUSE]% free|'MEMUSE'=$[MEMUSE]%;$strWarning;$strCritical" # strOutput="CPU=$[CPU]%|'CPU'=$[CPU]%;$strWarning;$strCritical;0;100" 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 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.2.1.10.2.1.6 | tr '\n' ' ' | sed 's/\"/ /g')) declare -a ids=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.11.5.6.2.1.2 | sed '1d' | tr '\n' ' ')) declare -a ios=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.11.5.6.2.1.3 | sed '1d' | 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 # Latencystatus ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "latency" ]; then declare -a luns=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.2.1.10.2.1.6 | tr '\n' ' ' | sed 's/\"/ /g')) declare -a ids=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.11.5.6.2.1.2 | sed '1d' | tr '\n' ' ')) declare -a lat=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.11.5.6.2.1.4 | sed '1d' | 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]}ms" elif [[ ${lat[${c}]} -ge $strWarning ]] then status="WARN" warn="$warn ${luns[c]} ${lat[c]}ms" else status="OK" ok="$ok ${luns[c]} ${lat[c]}ms" 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 # Fanspeed ---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "fanspeed" ]; then declare -a nums=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.1.2.2.1.2 | tr '\n' ' ')) declare -a ids=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.1.2.2.1.1 | tr '\n' ' ')) declare -a speed=($(snmpwalk -v 2c -t 60 -O vqe -c $strCommunity $strHostname .1.3.6.1.4.1.24681.1.4.1.1.1.1.2.2.1.5 | tr '\n' ' ')) c=0 if [ "$ids" = "No" ] then echo "Check not supported" exit 0 else for line in ${ids[@]} do perfdata="$perfdata Fan${nums[c]}=${speed[c]};$strWarning;$strCritical" if [[ ${speed[${c}]} -le $strCritical ]] then status="CRIT" crit="$crit Fan${nums[c]} ${speed[c]}" elif [[ ${speed[${c}]} -le $strWarning ]] then status="WARN" warn="$warn Fan${nums[c]} ${speed[c]}" else status="OK" ok="$ok Fan${nums[c]} ${speed[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|$perfdata" exit 0 else echo "No Performance Data" exit 0 fi fi #---------------------------------------------------------------------------------------------------------------------------------------------------- else echo -e "\nUnknown Part!" && exit "3" fi exit 0