-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_snmp_qnap_volumes
executable file
·160 lines (129 loc) · 4.25 KB
/
check_snmp_qnap_volumes
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
#
# Program : check_snmp_qnap_disks
# :
# Author : Jason Rivers <jason@jasonrivers.co.uk>
# :
# 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_VOLUMES=".1.3.6.1.4.1.24681.1.2.16.0"
OID_MODEL_NUMBER=".1.3.6.1.4.1.24681.1.2.12"
OID_VOLUMES=".1.3.6.1.4.1.24681.1.2.17"
OID_VOLUMES_SIZE=".1.3.6.1.4.1.24681.1.2.17.1.4"
OID_VOLUMES_FREE=".1.3.6.1.4.1.24681.1.2.17.1.5"
OID_VOLUMES_NAME=".1.3.6.1.4.1.24681.1.2.17.1.2"
SNMPWALK=/usr/bin/snmpwalk
SNMPGET=/usr/bin/snmpget
SNMP_COMMUNITY="public"
SNMP_VERSION="2c"
WARNING=20
CRITICAL=10
while getopts H:v:C:w:c:hV:D OPT
do
case "$OPT" in
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";;
D) DEBUG=true ;;
esac
done
TOTAL_VOLUMES=`$SNMPWALK -c $SNMP_COMMUNITY -v $SNMP_VERSION $REMOTE_HOSTNAME $OID_NUMBER_OF_VOLUMES -Oav | sed 's/INTEGER: //'`
VOLUME=1
if [ "$DEBUG" ]; then
echo "DEBUG: TOTAL_VOLUMES: $TOTAL_VOLUMES"
fi
SizeInMB () {
SIZE=$1
COMP=$2
case $COMP in
"TB")
SIZE=$(echo "${SIZE} *1024 * 1024" | bc )
;;
"GB")
SIZE=$(echo "${SIZE} * 1024" | bc)
;;
esac
echo $SIZE
}
while [ ${VOLUME} -le ${TOTAL_VOLUMES} ]; do
VOLUME_NAME=`$SNMPWALK -c $SNMP_COMMUNITY -v $SNMP_VERSION $REMOTE_HOSTNAME ${OID_VOLUMES_NAME}.${VOLUME} -Oav | sed 's/STRING: "\[//;s/\]"//;s/,//' | awk '{print $2}'`
VOLUME_SIZE=`$SNMPWALK -c $SNMP_COMMUNITY -v $SNMP_VERSION $REMOTE_HOSTNAME ${OID_VOLUMES_SIZE}.${VOLUME} -Oav | sed 's/STRING: "//;s/"//'`
VOLUME_FREE=`$SNMPWALK -c $SNMP_COMMUNITY -v $SNMP_VERSION $REMOTE_HOSTNAME ${OID_VOLUMES_FREE}.${VOLUME} -Oav | sed 's/STRING: "//;s/"//'`
## ignore dumb volumes
if ! [ "${VOLUME_SIZE}" = "0.00 KB" ]; then
SIZE_COMP=$(echo ${VOLUME_SIZE} | awk '{print $NF}')
FREE_COMP=$(echo ${VOLUME_FREE} | awk '{print $NF}')
VOLUME_SIZE_COMP=$(echo $VOLUME_SIZE | awk '{print $1}')
VOLUME_FREE_COMP=$(echo $VOLUME_FREE | awk '{print $1}')
VOLUME_SIZE=$(SizeInMB ${VOLUME_SIZE_COMP} ${SIZE_COMP})
VOLUME_FREE=$(SizeInMB ${VOLUME_FREE_COMP} ${FREE_COMP})
VOLUME_USED=$(echo "$VOLUME_SIZE - $VOLUME_FREE" | bc)
VOLUME_PERCENT_USED=$(awk "BEGIN { pc=100*${VOLUME_USED}/${VOLUME_SIZE}; i=int(pc); print (pc-i<0.5)?i:i+1 }")
VOLUME_PERCENT_FREE=$(awk "BEGIN { pc=100*${VOLUME_FREE}/${VOLUME_SIZE}; i=int(pc); print (pc-i<0.5)?i:i+1 }")
if ! [ "$EXITCODE" = "$STATE_CRITICAL" ]; then
if [ $VOLUME_PERCENT_FREE -le $WARNING ]; then
EXITCODE=$STATE_WARNING
fi
if [ $VOLUME_PERCENT_FREE -le $CRITICAL ]; then
EXITCODE=$STATE_CRITICAL
fi
fi
if [ "$DEBUG" ]; then
echo "DEBUG: VOLUME_NAME: ${VOLUME_NAME}"
echo "DEBUG: VOLUME_SIZE: ${VOLUME_SIZE}"
echo "DEBUG: VOLUME_FREE: ${VOLUME_FREE}"
echo "DEBUG: VOLUME_USED: ${VOLUME_USED}"
echo "DEBUG: VOLUME_PERCENT_USED: ${VOLUME_PERCENT_USED}"
echo "DEBUG: VOLUME_PERCENT_FREE: ${VOLUME_PERCENT_FREE}"
fi
if [ "$PERFDATA" = "" ]; then
PERFDATA="${VOLUME_NAME}=${VOLUME_PERCENT_USED};${WARNING};${CRITICAL};0;100"
MESSAGE="${VOLUME_NAME}=${VOLUME_PERCENT_USED}%";
else
PERFDATA="${PERFDATA}, ${VOLUME_NAME}=${VOLUME_PERCENT_USED};${WARNING};${CRITICAL};0;100"
MESSAGE="${MESSAGE}, ${VOLUME_NAME}=${VOLUME_PERCENT_USED}%";
fi
else
if [ "$DEBUG" ]; then
echo "DEBUG: IGNORING ${VOLUME_NAME}"
fi
fi
let VOLUME=${VOLUME}+1
done
if [ $EXITCODE = $STATE_WARNING ];then
EXITCODE=$STATE_WARNING
EXITMSG="WARNING: Volume usage"
elif [ $EXITCODE = $STATE_CRITICAL ];then
EXITCODE=$STATE_CRITICAL
EXITMSG="CRITICAL: Volume usage"
else
EXITCODE=$STATE_OK
EXITMSG="OK: Volume usage"
fi
if [ "$DEBUG" ]; then
echo "DEBUG: PERFDATA: ${PERFDATA}"
echo "exiting with $EXITCODE"
fi
echo "${EXITMSG} ${MESSAGE} | ${PERFDATA}"
exit $EXITCODE