This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_pfSense.sh
296 lines (280 loc) · 7.75 KB
/
check_pfSense.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
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
#!/bin/sh
#Initial File: https://gitlab.unetresgrossebite.com/DevOps/puppet/blob/30bf4d18dd98d5dc1b658be56a312051f61ac9bc/modules/nagios/files/custom_plugins/check_pfsense
#rewritten by Pit Wenkin
#using stuff from: https://github.com/diogouchoas/check_pfsense/blob/master/check_pfsense.sh
#Additions include:
# - CPU check
# - Load check
# - Memory check
# - Disk check (diskusage was confusing)
# - Possibility to define custom warning/critical levels
Prg=`basename $0`
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
ret=UNKNOWN
community="public"
target="127.0.0.1"
query="firmware"
port=1
OID_MOUNTPOINT=".1.3.6.1.2.1.25.2.3.1.3"
OID_FSBLKSIZE=".1.3.6.1.2.1.25.2.3.1.4"
OID_FSBLKAMOUNT=".1.3.6.1.2.1.25.2.3.1.5"
OID_FSBLKUSED=".1.3.6.1.2.1.25.2.3.1.6"
OID_PROCS=".1.3.6.1.2.1.25.1.6.0"
OID_USERS=".1.3.6.1.2.1.25.1.5.0"
OID_STATES=".1.3.6.1.4.1.12325.1.200.1.3.1.0"
OID_CPU=".1.3.6.1.4.1.2021.11.11.0"
OID_LOAD=".1.3.6.1.4.1.2021.10.1.3.1"
OID_LOAD5=".1.3.6.1.4.1.2021.10.1.3.2"
OID_LOAD15=".1.3.6.1.4.1.2021.10.1.3.3"
OID_MEMT=".1.3.6.1.4.1.2021.4.5.0"
OID_MEMF=".1.3.6.1.4.1.2021.4.11.0"
OID_DISK_UPCT=".1.3.6.1.4.1.2021.9.1.9.1"
OID_DISK_TOT=".1.3.6.1.4.1.2021.9.1.6.1"
OID_DISK_FREE=".1.3.6.1.4.1.2021.9.1.7.1"
usage()
{
echo "Usage: $Prg -H host -C community -t query -w warning -c critical"
echo " query: cpu"
echo " query: disk"
echo " query: diskusage [-d disknbr]"
echo " query: load"
echo " query: memory"
echo " query: procs"
echo " query: states"
echo " query: users"
}
if test -z "$1"; then
usage
exit $UNKNOWN
fi
while getopts H:C:t:d:w:c:h OPT
do
case $OPT in
H) target=$OPTARG ;;
C) community=$OPTARG ;;
t) query=$OPTARG ;;
d) disk=$OPTARG ;;
w) warning=$OPTARG ;;
c) critical=$OPTARG ;;
h)
usage
exit $UNKNOWN
;;
esac
done
if test $query = diskusage; then
for i in `seq 1 100`
do
test "$disk" && i=$disk
mpt=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_MOUNTPOINT.$i | sed 's|"||g'`
echo "$mpt" | grep UMA && break
echo "$mpt" | grep MALLOC && break
bsz=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_FSBLKSIZE.$i`
tsz=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_FSBLKAMOUNT.$i`
usz=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_FSBLKUSED.$i`
tsz=`expr $tsz '*' $bsz`
usz=`expr $usz '*' $bsz`
free=`expr $tsz - $usz`
if echo "$mpt" | grep '^/,'; then
if test `expr $free '*' 20` -lt $tsz; then
ret=CRITICAL
elif test `expr $free '*' 10` -lt $usz; then
ret=WARNING
elif test $tsz -ge 0 -a $usz -ge 0; then
ret=OK
fi
fi
for val in free usz tsz
do
unit=b
eval i=\$$val
while :
do
case $unit in
b) unit=k ;;
k) unit=M ;;
M) unit=G ;;
G) unit=T ;;
T) unit=P ;;
P) unit=E ;;
E) unit=Z ;;
*) break ;;
esac
if test `expr $i / 1024` -lt 1024; then
i="`expr $i / 1024`.`expr $i % 1024`"
break
fi
i=`expr $i / 1024`
done
eval $val=$i$unit
done
test "$msg" && msg="$msg,"
msg="$msg $mpt usage: $free/$usz/$tsz (free/used/tot)"
test "$disk" && break
done
elif test $query = disk; then
diskpct=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_DISK_UPCT`
#disktot=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_DISK_TOT`
diskfree=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_DISK_FREE`
if test $diskpct -gt $critical; then
ret=CRITICAL
elif test $diskpct -gt $warning; then
ret=WARNING
elif test $diskpct -ge 0; then
ret=OK
fi
for val in free diskfree
do
unit=b
eval i=\$$val
while :
do
case $unit in
b) unit=k ;;
k) unit=M ;;
M) unit=G ;;
G) unit=T ;;
T) unit=P ;;
P) unit=E ;;
E) unit=Z ;;
*) break ;;
esac
if test `expr $i / 1024` -lt 1024; then
i="`expr $i / 1024`.`expr $i % 1024`"
break
fi
i=`expr $i / 1024`
done
eval $val=$i$unit
done
msg=" free space: / $diskfree ($diskpct%)"
elif test $query = users; then
res=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_USERS`
warning=${warning:='5'}
critical=${critical:='10'}
if test $res -gt $critical; then
ret=CRITICAL
elif test $res -gt $warning; then
ret=WARNING
elif test $res -ge 0; then
ret=OK
fi
msg=" $res active sessions"
elif test $query = cpu; then
res=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_CPU`
used=`expr 100 - $res`
warning=${warning:='50'}
critical=${critical:='75'}
if test $used -gt $critical; then
ret=CRITICAL
elif test $used -gt $warning; then
ret=WARNING
elif test $used -ge 0; then
ret=OK
fi
msg=" $used% cpu used - $warning/$critical"
elif test $query = load; then
load=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_LOAD | sed 's|"||g'`
load5=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_LOAD5 | sed 's|"||g'`
load15=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_LOAD15 | sed 's|"||g'`
load100=$(echo "scale=0; 100*$load" | bc)
load105=$(echo "scale=0; 100*$load5" | bc)
load115=$(echo "scale=0; 100*$load15" | bc)
load100=$(echo $load100 |cut -d '.' -f 1)
load105=$(echo $load105 |cut -d '.' -f 1)
load115=$(echo $load115 |cut -d '.' -f 1)
warning=${warning:='0.75'}
critical=${critical:='1'}
warning100=$(echo "scale=0; 100 * $warning" | bc)
critical100=$(echo "scale=0; 100 * $critical" | bc)
warning100=$(echo $warning100 |cut -d '.' -f 1)
critical100=$(echo $critical100 |cut -d '.' -f 1)
if test $load105 -gt $critical100; then
if test $load115 -gt $critical100; then
ret=CRITICAL
else
ret=WARNING
fi
elif test $load105 -gt $warning100; then
if test $load115 -gt $warning100; then
ret=CRITCAL
else
ret=WARNING
fi
else
ret=OK
fi
msg=" load = $load, $load5, $load15"
elif test $query = memory; then
memt=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_MEMT | sed 's|"||g'`
memf=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_MEMF | sed 's|"||g'`
memf_pct=$(echo "scale=0; $memf*100/$memt" | bc)
memu=$(($memt-$memf))
memu_pct=$((100-$memf_pct))
warning=${warning:='70'}
critical=${critical:='80'}
warning=$(echo $warning |cut -d ',' -f 1)
critical=$(echo $critical |cut -d ',' -f 1)
if test $memu_pct -gt $critical; then
ret=CRITICAL
elif test $memu_pct -gt $warning; then
ret=WARNING
elif test $memu_pct -ge 0; then
ret=OK
fi
for val in free memt memf memu
do
unit=b
eval i=\$$val
while :
do
case $unit in
b) unit=k ;;
k) unit=M ;;
M) unit=G ;;
G) unit=T ;;
T) unit=P ;;
P) unit=E ;;
E) unit=Z ;;
*) break ;;
esac
if test `expr $i / 1024` -lt 1024; then
i="`expr $i / 1024`.`expr $i % 1024`"
break
fi
i=`expr $i / 1024`
done
eval $val=$i$unit
done
msg=" Memory usage: $memu_pct% - Total: $memt, used: $memu, free: $memf"
elif test $query = procs; then
res=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_PROCS`
warning=${warning:='150'}
critical=${critical:='200'}
if test $res -gt $critical; then
ret=CRITICAL
elif test $res -gt $warning; then
ret=WARNING
elif test $res -ge 0; then
ret=OK
fi
msg=" $res processes"
elif test $query = states; then
res=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_STATES`
warning=${warning:='15000'}
critical=${critical:='20000'}
if test $res -gt $critical; then
ret=CRITICAL
elif test $res -gt $warning; then
ret=WARNING
elif test $res -gt 0; then
ret=OK
fi
msg=" $res states"
fi >/dev/null 2>&1
echo $ret$msg$pefdata
eval ret=\$$ret
exit $ret