-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_snmp_enterasys
More file actions
369 lines (333 loc) · 9.86 KB
/
check_snmp_enterasys
File metadata and controls
369 lines (333 loc) · 9.86 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/bin/bash
# Author: Jonathan Kaiser
# Date: 20121029ish
# Purpose: Enterasys SNMP OID check for device health and returns perfdata compatible format
# Dependances: net-snmp
# Version: 0.1
## Defaults
HOSTNAME=
SNMP_VERSION=2c
COMMUNITY=public
HTTP=false
OUTPUT_PERFDATA=false
TIMEOUT=1
RETRY=1
TYPE_CHECK=
WARN_THRESHOLD=
CRIT_THRESHOLD=
THRESHOLDS_SET=false
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
OUTPUT_DETAIL=
function help () {
echo "use : $0 -H hostname -C community -x check_type -w # -c #"
echo ""
echo " -H : hostname or IP address of device"
echo " -C : snmp community (default:public)"
echo ""
echo " -x : check_type options"
echo ""
echo " CPU : CPU 5min utilization average"
echo " thresholds [1..100] in percentage"
echo " PSU : PSU status"
#echo " storage : Storage status"
#echo " thresholds [1..100] in percentage"
echo " fan : Fan status"
echo ""
#echo " environmental : Display PSU, Storage, Fan status"
#echo ""
echo " -p : Include perfdata"
echo " -t : Format with HTTP line breaks"
echo " -w : Warning threshhold"
echo " -c : Critical threshold"
echo ""
echo " -h : print this message"
exit $UNKNOWN
}
while getopts "H:C:x:tpw:c:h" Input;
do
case ${Input} in
H) HOSTNAME=${OPTARG};;
C) COMMUNITY=${OPTARG};;
x) TYPE_CHECK=${OPTARG};;
t) HTTP=true;;
p) OUTPUT_PERFDATA=true;;
w) WARN_THRESHOLD=${OPTARG};;
c) CRIT_THRESHOLD=${OPTARG};;
h) help;;
*) echo "Invalid input"
exit $UNKNOWN
;;
esac
done
if [ "$WARN_THRESHOLD" != "" ] && [ "$CRIT_THRESHOLD" != "" ]; then
THRESHOLDS_SET=true
fi
get="snmpget -c "$COMMUNITY" -v "$SNMP_VERSION" -t "$TIMEOUT" -r "$RETRY" -O qv "$HOSTNAME" "
walk="snmpwalk -c "$COMMUNITY" -v "$SNMP_VERSION" -t "$TIMEOUT" -r "$RETRY" -O qv "$HOSTNAME" "
sysDescr=".1.3.6.1.2.1.1.1.0"
#CPU
etsysResourceCpuLoad5min=".1.3.6.1.4.1.5624.1.2.49.1.1.1.1.4"
etsysResourceCpuLoad1min=".1.3.6.1.4.1.5624.1.2.49.1.1.1.1.3"
etsysResourceCpuLoad5sec=".1.3.6.1.4.1.5624.1.2.49.1.1.1.1.2"
#PSU
ctChasPowerSupplyNum=".1.3.6.1.4.1.52.4.3.1.2.1.1.1"
ctChasPowerSupplyState=".1.3.6.1.4.1.52.4.3.1.2.1.1.2"
#INTEGER { infoNotAvailable ( 1 ) , notInstalled ( 2 ) , installedAndOperating ( 3 ) , installedAndNotOperating ( 4 ) }
ctChasPowerSupplyType=".1.3.6.1.4.1.52.4.3.1.2.1.1.3"
#INTEGER { ac-dc ( 1 ) , dc-dc ( 2 ) , notSupported ( 3 ) , highOutput ( 4 ) }
ctChasPowerSupplyRedundancy=".1.3.6.1.4.1.52.4.3.1.2.1.1.4"
#INTEGER { redundant ( 1 ) , notRedundant ( 2 ) , notSupported ( 3 ) }
#Storage - Size is in Kb
etsysResourceStorageDescr=".1.3.6.1.4.1.5624.1.2.49.1.3.1.1.3"
etsysResourceStorageSize=".1.3.6.1.4.1.5624.1.2.49.1.3.1.1.4"
etsysResourceStorageAvailable=".1.3.6.1.4.1.5624.1.2.49.1.3.1.1.5"
#Fans
ctChasFanModuleNum=".1.3.6.1.4.1.52.4.3.1.3.1.1.1"
ctChasFanModuleState=".1.3.6.1.4.1.52.4.3.1.3.1.1.2"
#INTEGER { infoNotAvailable ( 1 ) , notInstalled ( 2 ) , installedAndOperating ( 3 ) , installedAndNotOperating ( 4 ) }
chEnvNumFans=".1.3.6.1.4.1.52.4.1.1.8.1.11"
chEnvFanStatus=".1.3.6.1.4.1.52.4.1.1.8.1.12.1.2"
#INTEGER { unknown ( 1 ) , normal ( 2 ) , testing ( 3 ) , slow ( 4 ) , inoperative ( 5 ) , off ( 6 ) }
chEnvFanAdmin=".1.3.6.1.4.1.52.4.1.1.8.1.12.1.3"
#INTEGER { autoMode ( 1 ) , fullSpeed ( 2 ) , testingMode ( 3 ) }
chEnvFanSpeed=".1.3.6.1.4.1.52.4.1.1.8.1.12.1.4"
# [0-100]
# Connectivity Check
check=$($get$sysDescr 2>&1)
if [[ $check == Timeout* ]]; then
echo $check
exit $UNKNOWN
fi
########################################
# CPU Utilization Check (default 5min)
# eg. CRITICAL: CPU1 99%
# WARNING: CPU1 85%
# OK: 2 CPUs
########################################
function cpu () {
cpu5min=$($walk$etsysResourceCpuLoad5min)
cpu1min=$($walk$etsysResourceCpuLoad1min)
cpu5sec=$($walk$etsysResourceCpuLoad5sec)
RET_CODE=$OK
i=0
OUTPUT_DETAIL=$OUTPUT_DETAIL"5min: "
for c in ${cpu5min[@]}
do
acpu=$(echo "scale=1; $c / 10" | bc -l)
#acpu=$(echo $c | sed 's/.$/.&/;t;s/^.$/.0&/')
if $THRESHOLDS_SET ; then
if [[ "$acpu" > "$WARN_THRESHOLD" ]] && [[ "$RET_CODE" < "$CRITICAL" ]] ; then
if [[ "$acpu" > "$CRIT_THRESHOLD" ]] ; then
RET_CODE=$CRITICAL
else
if [[ "$RET_CODE" < "$WARNING" ]] ; then
RET_CODE=$WARNING
else
RET_CODE=$CRITICAL
fi
fi
fi
fi
(( i++ ))
OUTPUT_DETAIL=$OUTPUT_DETAIL"CPU"$i":"$acpu"% "
PERFDATA=$PERFDATA"CPU"$i"="$acpu"% "
done
if $HTTP ; then
OUTPUT_DETAIL=$OUTPUT_DETAIL"<br/>"
else
OUTPUT_DETAIL=$OUTPUT_DETAIL"\n"
fi
i=0
OUTPUT_DETAIL=$OUTPUT_DETAIL"1min: "
for c in ${cpu1min[@]}
do
acpu=$(echo "scale=1; $c / 10" | bc -l)
(( i++ ))
OUTPUT_DETAIL=$OUTPUT_DETAIL"CPU"$i":"$acpu"% "
done
if $HTTP ; then
OUTPUT_DETAIL=$OUTPUT_DETAIL"<br/>"
else
OUTPUT_DETAIL=$OUTPUT_DETAIL"\n"
fi
i=0
OUTPUT_DETAIL=$OUTPUT_DETAIL"5sec: "
for c in ${cpu5sec[@]}
do
acpu=$(echo "scale=1; $c / 10" | bc -l)
(( i++ ))
OUTPUT_DETAIL=$OUTPUT_DETAIL"CPU"$i":"$acpu"% "
done
}
########################################
# PSU Status Check
# eg. Critical: installedAndNotOperating PSUs: 1
# OK: Installed and operating PSUs: 1
########################################
function psu () {
psunums=$($walk$ctChasPowerSupplyNum)
if [[ $psunums == No* ]] ; then
OUTPUT_DETAIL="PSU data not available"
return $OK
fi
operatingpsus=""
notoperatingpsus=""
for eachpsu in ${psunums[@]}
do
thispsuState=$($get$ctChasPowerSupplyState"."$eachpsu)
thispsuType=$($get$ctChasPowerSupplyType"."$eachpsu)
thispsuTypeName=""
#echo "Checking "$eachpsu": "$thispsuState
#thispsuType=$($get$ctChasPowerSupplyType"."$eachpsu)
#TO DO!!! Add output for denoting PSU Type
case $thispsuType in
1) thispsuTypeName="AC";;
2) thispsuTypeName="DC";;
3) thispsuTypeName="notSupported";;
4) thispsuTypeName="highOutput";;
*) thispsuTypeName="Unknown";;
esac
if [[ "$thispsuType" != "3" ]] ; then
#Skipped unsupported PSUs
case $thispsuState in
1) #info not available
uninteresting=true;;
2) #not installed
uninteresting=true;;
3) #installed and operating
operatingpsus=$operatingpsus" "$eachpsu"("$thispsuTypeName")"
PERFDATA=$PERFDATA"PSU"$eachpsu"="$thispsuState" ";;
4) #installed and not operating
notoperatingpsus=$notoperatingpsus" "$eachpsu"("$thispsuTypeName")"
RET_CODE=$CRITICAL
PERFDATA=$PERFDATA"PSU"$eachpsu"="$thispsuState" ";;
*) #unkown, come back to this... To Do
uninteresting=true;;
esac
fi
done
if [[ "$notoperatingpsus" != "" ]] ; then
OUTPUT_DETAIL="Installed and not operating PSUs:"$notoperatingpsus
if $HTTP ; then
OUTPUT_DETAIL=$OUTPUT_DETAIL"<br/>"
else
OUTPUT_DETAIL=$OUTPUT_DETAIL"\n"
fi
OUTPUT_DETAIL=$OUTPUT_DETAIL"Installed and operating PSUs:"$operatingpsus
else
OUTPUT_DETAIL="Installed and operating PSUs:"$operatingpsus
RET_CODE=$OK
fi
}
########################################
# Storage Utilization Check
# eg. Critical: SmallDrive 99% Used, 99Kb/100Kb
# Warning: NVRAM 85% Used, 85Kb/100Kb
# OK: Flash 10% Used, 10Kb/100Kb
########################################
function stor () {
#To Do!
OUTPUT_DETAIL="Checking the storage is in development"
RET_CODE=$UNKNOWN
}
########################################
# Fan Status Check
# eg. Warning: Fan 2 unknown
# OK: 2 Fans
########################################
function fan () {
fannums=$($walk$ctChasFanModuleNum)
if [[ $fannums == No* ]] ; then
#OUTPUT_DETAIL=$ctChasFanModuleNum" = "$fannums
OUTPUT_DETAIL="Fan data not available"
return $OK
fi
operatingfans=""
notoperatingfans=""
for eachfan in ${fannums[@]}
do
thisfanState=$($get$ctChasFanModuleState"."$eachfan)
#echo "Checking "$eachfan": "$thisfanState
case $thisfanState in
1) #info not available
uninteresting=true;;
2) #not installed
uninteresting=true;;
3) #installed and operating
operatingfans=$operatingfans" "$eachfan
PERFDATA=$PERFDATA"fan"$eachfan"="$thisfanState" ";;
4) #installed and not operating
notoperatingfans=$notoperatingfans" "$eachfan
RET_CODE=$CRITICAL
PERFDATA=$PERFDATA"fan"$eachfan"="$thisfanState" ";;
*) #unkown, come back to this... To Do
uninteresting=true;;
esac
done
if [[ "$notoperatingfans" != "" ]] ; then
OUTPUT_DETAIL="Installed and not operating fans:"$notoperatingfans
if [[ $check == Enterasys*D2* ]] ; then
RET_CODE=$OK
fi
else
OUTPUT_DETAIL="Installed and operating fans:"$operatingfans
RET_CODE=$OK
fi
}
########################################
# Environmental Check
# Single output for PSUs, Storage devices and Fans
# eg. Critical: PSU 1 installedAndNotOperating
# Warning: Fan 2 unknown
# OK: 1 PSU, 1 Storage, 2 Fans
########################################
function enviro () {
cpu
CPUSTAT=$OUTPUT_DETAIL
ENVIRORET=$RET_CODE
psu
PSUSTAT=$OUTPUT_DETAIL
if [[ "$RET_CODE" > "$ENVIRORET" ]] ; then
ENVIRORET=$RET_CODE
fi
fan
FANSTAT=$OUTPUT_DETAIL
if [[ "$RET_CODE" > "$ENVIRORET" ]] ; then
ENVIRORET=$RET_CODE
fi
if $HTTP ; then
OUTPUT_DETAIL=$CPUSTAT"<br/>"$PSUSTAT"<br/>"$FANSTAT
else
OUTPUT_DETAIL=$CPUSTAT"\n"$PSUSTAT"\n"$FANSTAT
fi
RET_CODE=$ENVIRORET
}
case ${TYPE_CHECK} in
CPU) cpu;;
environment) enviro;;
PSU) psu;;
storage) stor;;
fan) fan;;
*)
echo "Not a valid type_check: $TYPE_CHECK"
exit $UNKNOWN;;
esac
case $RET_CODE in
0)
NAGIOS_OUT="OK: $OUTPUT_DETAIL";;
1)
NAGIOS_OUT="WARNING: $OUTPUT_DETAIL";;
2)
NAGIOS_OUT="CRITICAL: $OUTPUT_DETAIL";;
*)
NAGIOS_OUT="UNKNOWN: $OUTPUT_DETAIL";;
esac
if $OUTPUT_PERFDATA && [ -n "$PERFDATA" ] ; then
echo -e $NAGIOS_OUT" | "$PERFDATA
else
echo -e $NAGIOS_OUT
fi
exit $RET_CODE