-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_qnap.sh
216 lines (194 loc) · 7.25 KB
/
check_qnap.sh
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
#!/bin/bash
if [ ! "$#" == "3" ]; then
echo -e "QNap-NAS-monitoring for icinga v. 1.13 - (C) 2011 Martin Fuchs\n-> https://github.com/trendchiller/icinga-checks\n\nusage : ./check_qnap.sh <hostname> <snmp_community> <check>\nchecks: cpu, diskusage, fan, hdsmart, hdtemp, volumes, systemp, ramuse \n" && exit "3"
fi
strHostname=$1
strCommunity=$2
strCheck=$3
# -> DISKUSAGE -----------------------------------------------------------------
if [ "$strCheck" == "diskusage" ]; then
disk=$(snmpget -v1 -c $strCommunity -mALL $strHostname .1.3.6.1.2.1.25.2.3.1.5.33 | awk '{print $4}')
used=$(snmpget -v1 -c $strCommunity -mALL $strHostname .1.3.6.1.2.1.25.2.3.1.6.33 | awk '{print $4}')
let "PERC=(($used*100)/$disk)"
strOutput="Belegt=$[PERC]%|'Belegt'=$[PERC]%;80;90;0;100"
if [ $PERC -ge "90" ]; then
echo "CRITICAL: "$strOutput
exit 2
fi
if [ $PERC -ge "80" ]; then
echo "WARNING: "$strOutput
exit 1
fi
echo "OK: "$strOutput
exit 0
# -> CPU -----------------------------------------------------------------------
elif [ "$strCheck" == "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]%;80;90;0;100"
if [ $CPU -ge "90" ]; then
echo "CRITICAL: "$strOutput
exit 2
fi
if [ $CPU -ge "80" ]; then
echo "WARNING: "$strOutput
exit 1
fi
echo "OK: "$strOutput
exit 0
# -> HDD SMART Status ----------------------------------------------------------
elif [ "$strCheck" == "hdsmart" ]; then
HDNUM=$(snmpget -v1 -c $strCommunity -mALL "$strHostname" .1.3.6.1.4.1.24681.1.2.10.0 | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
i=1
while [ $i -le $HDNUM ]
do
HD[$i]=$(snmpget -v1 -c $strCommunity -mALL "$strHostname" 1.3.6.1.4.1.24681.1.2.11.1.7.$i | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
let i=i+1
done
FLAG=0
SMART="SMART-Status: "
for i in ${HD[@]}
do
[ "GOOD" != "$i" ] && FLAG=1
SMART="$SMART $i"
done
if [ "$FLAG" == "0" ]; then
echo OK: $SMART
exit 0
else
echo ERROR: $SMART
exit 2
fi
# -> VOLUME Status ---------------------------------------------------------------
elif [ "$strCheck" == "volumes" ]; then
VOLNUM=$(snmpget -v1 -c $strCommunity -mALL "$strHostname" .1.3.6.1.4.1.24681.1.2.16.0 | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
i=1
while [ $i -le $VOLNUM ]
do
raid_status[$i]=$(snmpget -v1 -c $strCommunity -mALL "$strHostname" .1.3.6.1.4.1.24681.1.2.17.1.6.$i | awk '{print $4, $5, $6}' | sed 's/^"\(.*\)"/\1/')
let i=i+1
done
FLAG=0
STATUS="RAID-Status: "
for i in ${raid_status[@]}
do
[ "Ready" != "$i" ] && FLAG=1
[ "Rebuilding" == "$i" ] && FLAG=2
STATUS="$STATUS $i"
done
if [ "$FLAG" == "0" ]; then
echo OK: $STATUS
exit 0
elif [ "$FLAG" == "2" ]; then
echo "WARNING: "$STATUS
exit 1
else
echo CRITICAL: $STATUS
exit 2
fi
# -> FAN Status ----------------------------------------------------------------
elif [ "$strCheck" == "fan" ]; then
FANNUM=$(snmpget -v1 -c $strCommunity -mALL "$strHostname" .1.3.6.1.4.1.24681.1.2.14.0 | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
i=1
while [ $i -le $FANNUM ]
do
FAN[$i]=$(snmpget -v1 -c $strCommunity -mALL "$strHostname" .1.3.6.1.4.1.24681.1.2.15.1.3.$i | awk '{print $4}' | sed 's/^"\(.*\)/\1/')
let i=i+1
done
FLAG=0
RPM="RPM: "
for i in ${FAN[@]}
do
[ "$i" -gt "2500" ] && FLAG=3
[ "$i" -le "2500" ] && FLAG=2
[ "$i" -le "2000" ] && FLAG=1
RPM="$RPM $i"
done
if [ "$FLAG" == "1" ]; then
echo OK: $RPM
exit 0
elif [ "$FLAG" == "2" ]; then
echo "WARNING: "$RPM
exit 1
else
echo CRITICAL: $RPM
exit 2
fi
# -> HDD TEMP ------------------------------------------------------------------
elif [ "$strCheck" == "hdtemp" ]; then
HDNUM=$(snmpget -v1 -c $strCommunity -mALL "$strHostname" .1.3.6.1.4.1.24681.1.2.10.0 | awk '{print $4}' | sed 's/^"\(.*\).$/\1/')
i=1
while [ $i -le $HDNUM ]
do
HD[$i]=$(snmpget -v1 -c $strCommunity -mALL "$strHostname" .1.3.6.1.4.1.24681.1.2.11.1.3.$i | awk '{print $4}' | cut -c2-3)
let i=i+1
done
FLAG=0
TEMP="HD-TEMP in C: "
for i in ${HD[@]}
do
[ "$i" -ge "50" ] && FLAG=3
[ "$i" -le "40" ] && FLAG=2
[ "$i" -le "30" ] && FLAG=1
TEMP="$TEMP $i"
done
if [ "$FLAG" == "1" ]; then
echo OK: $TEMP
exit 0
elif [ "$FLAG" == "2" ]; then
echo "WARNING: "$TEMP
exit 1
else
echo CRITICAL: $TEMP
exit 2
fi
# -> CPU-TEMP ------------------------------------------------------------------
elif [ "$strCheck" == "cputemp" ]; then
TEMP=$(snmpget -v1 -c $strCommunity -mALL $strHostname .1.3.6.1.4.1.24681.1.2.5.0 | awk '{print $4}' | cut -c2-3)
strOutput="CPU-Temp: $[TEMP]C|'Temp C'=$[TEMP]C;42;45"
if [ $TEMP -ge "45" ]; then
echo "CRITICAL: "$strOutput
exit 2
fi
if [ $TEMP -ge "42" ]; then
echo "WARNING: "$strOutput
exit 1
fi
echo "OK: "$strOutput
exit 0
# -> SYS-TEMP ------------------------------------------------------------------
elif [ "$strCheck" == "systemp" ]; then
TEMP=$(snmpget -v1 -c $strCommunity -mALL $strHostname .1.3.6.1.4.1.24681.1.2.6.0 | awk '{print $4}' | cut -c2-3)
strOutput="SYS-Temp: $[TEMP]C|'Temp C'=$[TEMP]C;40;45"
if [ $TEMP -ge "45" ]; then
echo "CRITICAL: "$strOutput
exit 2
fi
if [ $TEMP -ge "42" ]; then
echo "WARNING: "$strOutput
exit 1
fi
echo "OK: "$strOutput
exit 0
# -> RAM-USAGE -----------------------------------------------------------------
elif [ "$strCheck" == "ramuse" ]; then
ramtot=$(snmpget -v1 -c $strCommunity -mALL $strHostname .1.3.6.1.4.1.24681.1.2.2.0 | awk '{print $4}' | sed 's/.\(.*\)/\1/')
ramfree=$(snmpget -v1 -c $strCommunity -mALL $strHostname .1.3.6.1.4.1.24681.1.2.3.0 | awk '{print $4}' | sed 's/.\(.*\)/\1/')
ramtot=$(echo "scale=0; $ramtot" | bc -l | sed 's/\(.*\).../\1/')
ramfree=$(echo "scale=0; $ramfree" | bc -l | sed 's/\(.*\).../\1/')
let "PERC=(100-($ramfree*100)/$ramtot)"
strOutput="RAM: $[PERC]%|'RAM'=$[PERC]%;80;90;0;100"
if [ $PERC -ge "90" ]; then
echo "CRITICAL: "$strOutput
exit 2
fi
if [ $PERC -ge "80" ]; then
echo "WARNING: "$strOutput
exit 1
fi
echo "OK: "$strOutput
exit 0
# -> ---------------------------------------------------------------------------
else
echo -e "\nnon existing check!" && exit "3"
fi
exit 0