Servus allerseits,
heute war ich auf der Suche nach einem fertigen plugin, welches mein qnap nach den gängigen Infos abfragt. Im Nagios-Port fand ich bereits eine Version von Mad-Eye, die allerdings noch die ein oder andere Macke hatte. Dank der super Community habe ich nun eine fertig, funktionierende Version zusammen gebastelt.
Usage: ./check_qnap <hostname> <community> <part> <warning> <critical>
Parts are: cpu, diskusage, temp, hdstatus and volstatus (volstatus = Raid Info)
Example: ./check_qnap 127.0.0.1 public diskusage 80 95
Download: check_qnap
#!/bin/bash if [ ! "$#" == "5" ]; then echo -e "\nWarning: Wrong command line arguments. \nUsage: ./check_qnap <hostname> <community> <part> <warning> <critical>\n \nParts are: cpu, diskusage, temp, 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 # CPU ---------------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "cpu" ]; then CPU=$(snmpget -v1 -c "$strCommunity" -mALL $strHostname 1.3.6.1.4.1.24681.1.2.1.0 | awk '{print $4}' | sed 's/.\(.*\)../\1/') 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 # Temperature--------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "temp" ]; then TEMP0=$(snmpget -v1 -c "$strCommunity" -mALL $strHostname 1.3.6.1.4.1.24681.1.2.11.1.3.1 | awk '{print $4}' | cut -c2-3) TEMP1=$(snmpget -v1 -c "$strCommunity" -mALL $strHostname 1.3.6.1.4.1.24681.1.2.11.1.3.1 | awk '{print $4}' | cut -c2-3) if [ "$TEMP0" -ge "42" -o "$TEMP1" -ge "42" ]; then echo Temperatur zu Hoch! exit 2 else let "TEMP=($TEMP0+$TEMP1)/2" strOutput="Temp=$[TEMP]C|'Temp C'=$[TEMP]C;$strWarning;$strCritical" if [ $TEMP -ge "$strCritical" ]; then echo "CRITICAL: "$strOutput exit 2 fi if [ $TEMP -ge "$strWarning" ]; then echo "WARNING: "$strOutput exit 1 fi echo "OK: "$strOutput exit 0 fi # Volume Status---------------------------------------------------------------------------------------------------------------------------------------- elif [ "$strpart" == "volstatus" ]; then Vol_Status=$(snmpget -v1 -c "$strCommunity" -mALL "$strHostname" 1.3.6.1.4.1.24681.1.2.17.1.6.1 | awk '{print $4}' | sed 's/^"\(.*\).$/\1/') 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 HD0=$(snmpget -v1 -c "$strCommunity" -mALL "$strHostname" 1.3.6.1.4.1.24681.1.2.11.1.7.1 | awk '{print $4}' | sed 's/^"\(.*\).$/\1/') HD1=$(snmpget -v1 -c "$strCommunity" -mALL "$strHostname" 1.3.6.1.4.1.24681.1.2.11.1.7.2 | awk '{print $4}' | sed 's/^"\(.*\).$/\1/') if [ "$HD0" == "GOOD" -a "$HD1" == "GOOD" ]; then echo OK exit 0 else echo ERROR exit 2 fi #---------------------------------------------------------------------------------------------------------------------------------------------------- else echo -e "\nUnknown Part!" && exit "3" fi exit 0
Gruß
Cons