-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_snmp_qnap_disks
executable file
·134 lines (111 loc) · 3.6 KB
/
check_snmp_qnap_disks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
#
# Program : check_snmp_qnap_disks
# :
# Author : Jason Rivers <[email protected]>
# :
# Purpose : Nagios plugin to return Information about Disks in a QNAP NAS
# :
# Parameters : --help
# : --version
# :
# Returns : Standard Nagios status_* codes
# :
# Licence : GPL
#
# Notes : See --help for details
#============:==============================================================
#set -x
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
EXITCODE=$STATE_UNKNOWN
OID_NUMBER_OF_DISKS=".1.3.6.1.4.1.24681.1.2.10.0"
OID_MODEL_NUMBER=".1.3.6.1.4.1.24681.1.2.12"
OID_DISKS=".1.3.6.1.4.1.24681.1.2.11"
OID_DISKS_TEMP="${OID_DISKS}.1.3"
OID_DISKS_STATUS="${OID_DISKS}.1.7"
OID_DISKS_MODEL_NUMBER="${OID_DISKS}.1.5"
SNMPWALK=/usr/bin/snmpwalk
SNMPGET=/usr/bin/snmpget
SNMP_COMMUNITY="public"
SNMP_VERSION="2c"
WARNING=45
CRITICAL=50
function print_help(){
echo -e "check_snmp_qnap_disks {options}\n"
echo -e "\t-a\tForce all disks - This will report CRITICAL if there is an empty bay"
echo -e "\t-H\tremote Hostname of QNAP (Also accepts IP Address)"
echo -e "\t-v\tsnmp version"
echo -e "\t-C\tsnmp community"
echo -e "\t-w\tTemperature warning"
echo -e "\t-c\tTemperature Critical"
echo -e "\t-h\tprint_help"
echo -e "\t-V\tprint_version"
}
function print_version(){
echo "check_snmp_qnap_disks v0.5"
}
while getopts aH:v:C:w:c:hV OPT
do
case "$OPT" in
a) ALLDISKS=true ;;
H) REMOTE_HOSTNAME="$OPTARG" ;;
v) SNMP_VERSION="$OPTARG" ;;
C) SNMP_COMMUNITY="$OPTARG" ;;
w) WARNING=$OPTARG ;;
c) CRITICAL=$OPTARG ;;
h) print_help
exit "$STATE_UNKNOWN" ;;
V) print_version
exit "$STATE_UNKNOWN";;
esac
done
DISK_COUNTER=1
EXITMSG=""
AVERAGE_TEMP=`$SNMPWALK -c $SNMP_COMMUNITY -v $SNMP_VERSION $REMOTE_HOSTNAME ${OID_DISKS_TEMP} -Oav | cut -c "10-11" | awk '{s+=$1}END{print s/NR}' RS=" "`
if [ $AVERAGE_TEMP -ge $CRITICAL ]; then
EXITCODE=$STATE_CRITICAL
EXITMSG="CRITICAL: Average disk temperateure (${AVERAGE_TEMP}C)"
elif [ $AVERAGE_TEMP -ge $WARNING ]; then
EXITCODE=$STATE_WARNING
EXITMSG="WARNING: Average disk temperateure (${AVERAGE_TEMP}C)"
elif [ $AVERAGE_TEMP -lt $WARNING ]; then
EXITCODE=$STATE_OK
EXITMSG="OK: Average disk temperateure (${AVERAGE_TEMP}C)"
else
EXITCODE=$STATE_UNKNOWN
EXITMSG="UNKNOWN: Unable to get disk temperature"
fi
NUMBER_OF_DISKS=$($SNMPWALK -c $SNMP_COMMUNITY -v $SNMP_VERSION $REMOTE_HOSTNAME $OID_NUMBER_OF_DISKS -Oav | sed 's/INTEGER: //')
while [ $DISK_COUNTER -le $NUMBER_OF_DISKS ]; do
DISK_TEMP=`$SNMPGET -c $SNMP_COMMUNITY -v $SNMP_VERSION $REMOTE_HOSTNAME ${OID_DISKS_TEMP}.${DISK_COUNTER} -Oav | cut -c "10-11"`
DISK_STATUS=`$SNMPGET -c $SNMP_COMMUNITY -v $SNMP_VERSION $REMOTE_HOSTNAME ${OID_DISKS_STATUS}.${DISK_COUNTER} -Oav | sed 's/STRING: "//;s/"//'`
if ! [ $EXITCODE = $STATE_CRITICAL ];then
if [ $EXITCODE = $STATE_UNKNOWN ]; then
if [ $DISK_TEMP -ge $WARNING ]; then
EXITCODE=$STATE_WARNING
EXITMSG="WARNING: Disk Temperature is $DISK_TEMP"
fi
fi
if [ "$DISK_TEMP" != "--" ]; then
if [ $DISK_TEMP -ge $CRITICAL ]; then
EXITCODE=$STATE_CRITICAL
EXITMSG="CRITICAL: Disk Temperature is $DISK_TEMP"
fi
fi
if ! [ "$DISK_STATUS" = "GOOD" ]; then
if [ "x$ALLDISKS" == "xtrue" ]; then
EXITCODE=$STATE_CRITICAL
EXITMSG="CRITICAL: Disk ${DISK_COUNTER} SMART Status is \"$DISK_STATUS\""
fi
fi
fi
if [ "$DISK_TEMP" != "--" ]; then
PERFDATA="${PERFDATA}Disk${DISK_COUNTER}_temperature=$DISK_TEMP "
fi
let DISK_COUNTER=${DISK_COUNTER}+1
done
echo "${EXITMSG}|${PERFDATA}"
exit $EXITCODE