Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.

Commit da36e84

Browse files
authored
Add files via upload
1 parent c44f97b commit da36e84

File tree

1 file changed

+296
-0
lines changed

1 file changed

+296
-0
lines changed

check_pfSense.sh

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
#!/bin/sh
2+
3+
#Initial File: https://gitlab.unetresgrossebite.com/DevOps/puppet/blob/30bf4d18dd98d5dc1b658be56a312051f61ac9bc/modules/nagios/files/custom_plugins/check_pfsense
4+
#rewritten by Pit Wenkin
5+
#using stuff from: https://github.com/diogouchoas/check_pfsense/blob/master/check_pfsense.sh
6+
#Additions include:
7+
# - CPU check
8+
# - Load check
9+
# - Memory check
10+
# - Disk check (diskusage was confusing)
11+
# - Possibility to define custom warning/critical levels
12+
13+
Prg=`basename $0`
14+
OK=0
15+
WARNING=1
16+
CRITICAL=2
17+
UNKNOWN=3
18+
ret=UNKNOWN
19+
community="public"
20+
target="127.0.0.1"
21+
query="firmware"
22+
port=1
23+
24+
OID_MOUNTPOINT=".1.3.6.1.2.1.25.2.3.1.3"
25+
OID_FSBLKSIZE=".1.3.6.1.2.1.25.2.3.1.4"
26+
OID_FSBLKAMOUNT=".1.3.6.1.2.1.25.2.3.1.5"
27+
OID_FSBLKUSED=".1.3.6.1.2.1.25.2.3.1.6"
28+
OID_PROCS=".1.3.6.1.2.1.25.1.6.0"
29+
OID_USERS=".1.3.6.1.2.1.25.1.5.0"
30+
OID_STATES=".1.3.6.1.4.1.12325.1.200.1.3.1.0"
31+
OID_CPU=".1.3.6.1.4.1.2021.11.11.0"
32+
OID_LOAD=".1.3.6.1.4.1.2021.10.1.3.1"
33+
OID_LOAD5=".1.3.6.1.4.1.2021.10.1.3.2"
34+
OID_LOAD15=".1.3.6.1.4.1.2021.10.1.3.3"
35+
OID_MEMT=".1.3.6.1.4.1.2021.4.5.0"
36+
OID_MEMF=".1.3.6.1.4.1.2021.4.11.0"
37+
OID_DISK_UPCT=".1.3.6.1.4.1.2021.9.1.9.1"
38+
OID_DISK_TOT=".1.3.6.1.4.1.2021.9.1.6.1"
39+
OID_DISK_FREE=".1.3.6.1.4.1.2021.9.1.7.1"
40+
41+
usage()
42+
{
43+
echo "Usage: $Prg -H host -C community -t query -w warning -c critical"
44+
echo " query: cpu"
45+
echo " query: disk"
46+
echo " query: diskusage [-d disknbr]"
47+
echo " query: load"
48+
echo " query: memory"
49+
echo " query: procs"
50+
echo " query: states"
51+
echo " query: users"
52+
}
53+
54+
if test -z "$1"; then
55+
usage
56+
exit $UNKNOWN
57+
fi
58+
59+
while getopts H:C:t:d:w:c:h OPT
60+
do
61+
case $OPT in
62+
H) target=$OPTARG ;;
63+
C) community=$OPTARG ;;
64+
t) query=$OPTARG ;;
65+
d) disk=$OPTARG ;;
66+
w) warning=$OPTARG ;;
67+
c) critical=$OPTARG ;;
68+
h)
69+
usage
70+
exit $UNKNOWN
71+
;;
72+
esac
73+
done
74+
75+
if test $query = diskusage; then
76+
for i in `seq 1 100`
77+
do
78+
test "$disk" && i=$disk
79+
mpt=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_MOUNTPOINT.$i | sed 's|"||g'`
80+
echo "$mpt" | grep UMA && break
81+
echo "$mpt" | grep MALLOC && break
82+
bsz=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_FSBLKSIZE.$i`
83+
tsz=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_FSBLKAMOUNT.$i`
84+
usz=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_FSBLKUSED.$i`
85+
tsz=`expr $tsz '*' $bsz`
86+
usz=`expr $usz '*' $bsz`
87+
free=`expr $tsz - $usz`
88+
if echo "$mpt" | grep '^/,'; then
89+
if test `expr $free '*' 20` -lt $tsz; then
90+
ret=CRITICAL
91+
elif test `expr $free '*' 10` -lt $usz; then
92+
ret=WARNING
93+
elif test $tsz -ge 0 -a $usz -ge 0; then
94+
ret=OK
95+
fi
96+
fi
97+
for val in free usz tsz
98+
do
99+
unit=b
100+
eval i=\$$val
101+
while :
102+
do
103+
case $unit in
104+
b) unit=k ;;
105+
k) unit=M ;;
106+
M) unit=G ;;
107+
G) unit=T ;;
108+
T) unit=P ;;
109+
P) unit=E ;;
110+
E) unit=Z ;;
111+
*) break ;;
112+
esac
113+
if test `expr $i / 1024` -lt 1024; then
114+
i="`expr $i / 1024`.`expr $i % 1024`"
115+
break
116+
fi
117+
i=`expr $i / 1024`
118+
done
119+
eval $val=$i$unit
120+
done
121+
test "$msg" && msg="$msg,"
122+
msg="$msg $mpt usage: $free/$usz/$tsz (free/used/tot)"
123+
test "$disk" && break
124+
done
125+
elif test $query = disk; then
126+
diskpct=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_DISK_UPCT`
127+
#disktot=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_DISK_TOT`
128+
diskfree=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_DISK_FREE`
129+
if test $diskpct -gt $critical; then
130+
ret=CRITICAL
131+
elif test $diskpct -gt $warning; then
132+
ret=WARNING
133+
elif test $diskpct -ge 0; then
134+
ret=OK
135+
fi
136+
for val in free diskfree
137+
do
138+
unit=b
139+
eval i=\$$val
140+
while :
141+
do
142+
case $unit in
143+
b) unit=k ;;
144+
k) unit=M ;;
145+
M) unit=G ;;
146+
G) unit=T ;;
147+
T) unit=P ;;
148+
P) unit=E ;;
149+
E) unit=Z ;;
150+
*) break ;;
151+
esac
152+
if test `expr $i / 1024` -lt 1024; then
153+
i="`expr $i / 1024`.`expr $i % 1024`"
154+
break
155+
fi
156+
i=`expr $i / 1024`
157+
done
158+
eval $val=$i$unit
159+
done
160+
msg=" free space: / $diskfree ($diskpct%)"
161+
elif test $query = users; then
162+
res=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_USERS`
163+
warning=${warning:='5'}
164+
critical=${critical:='10'}
165+
if test $res -gt $critical; then
166+
ret=CRITICAL
167+
elif test $res -gt $warning; then
168+
ret=WARNING
169+
elif test $res -ge 0; then
170+
ret=OK
171+
fi
172+
msg=" $res active sessions"
173+
elif test $query = cpu; then
174+
res=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_CPU`
175+
used=`expr 100 - $res`
176+
warning=${warning:='50'}
177+
critical=${critical:='75'}
178+
if test $used -gt $critical; then
179+
ret=CRITICAL
180+
elif test $used -gt $warning; then
181+
ret=WARNING
182+
elif test $used -ge 0; then
183+
ret=OK
184+
fi
185+
msg=" $used% cpu used - $warning/$critical"
186+
elif test $query = load; then
187+
load=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_LOAD | sed 's|"||g'`
188+
load5=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_LOAD5 | sed 's|"||g'`
189+
load15=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_LOAD15 | sed 's|"||g'`
190+
191+
load100=$(echo "scale=0; 100*$load" | bc)
192+
load105=$(echo "scale=0; 100*$load5" | bc)
193+
load115=$(echo "scale=0; 100*$load15" | bc)
194+
load100=$(echo $load100 |cut -d '.' -f 1)
195+
load105=$(echo $load105 |cut -d '.' -f 1)
196+
load115=$(echo $load115 |cut -d '.' -f 1)
197+
198+
warning=${warning:='0.75'}
199+
critical=${critical:='1'}
200+
warning100=$(echo "scale=0; 100 * $warning" | bc)
201+
critical100=$(echo "scale=0; 100 * $critical" | bc)
202+
warning100=$(echo $warning100 |cut -d '.' -f 1)
203+
critical100=$(echo $critical100 |cut -d '.' -f 1)
204+
205+
if test $load105 -gt $critical100; then
206+
if test $load115 -gt $critical100; then
207+
ret=CRITICAL
208+
else
209+
ret=WARNING
210+
fi
211+
elif test $load105 -gt $warning100; then
212+
if test $load115 -gt $warning100; then
213+
ret=CRITCAL
214+
else
215+
ret=WARNING
216+
fi
217+
else
218+
ret=OK
219+
fi
220+
msg=" load = $load, $load5, $load15"
221+
222+
223+
elif test $query = memory; then
224+
memt=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_MEMT | sed 's|"||g'`
225+
memf=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_MEMF | sed 's|"||g'`
226+
memf_pct=$(echo "scale=0; $memf*100/$memt" | bc)
227+
memu=$(($memt-$memf))
228+
memu_pct=$((100-$memf_pct))
229+
230+
warning=${warning:='70'}
231+
critical=${critical:='80'}
232+
warning=$(echo $warning |cut -d ',' -f 1)
233+
critical=$(echo $critical |cut -d ',' -f 1)
234+
235+
if test $memu_pct -gt $critical; then
236+
ret=CRITICAL
237+
elif test $memu_pct -gt $warning; then
238+
ret=WARNING
239+
elif test $memu_pct -ge 0; then
240+
ret=OK
241+
fi
242+
for val in free memt memf memu
243+
do
244+
unit=b
245+
eval i=\$$val
246+
while :
247+
do
248+
case $unit in
249+
b) unit=k ;;
250+
k) unit=M ;;
251+
M) unit=G ;;
252+
G) unit=T ;;
253+
T) unit=P ;;
254+
P) unit=E ;;
255+
E) unit=Z ;;
256+
*) break ;;
257+
esac
258+
if test `expr $i / 1024` -lt 1024; then
259+
i="`expr $i / 1024`.`expr $i % 1024`"
260+
break
261+
fi
262+
i=`expr $i / 1024`
263+
done
264+
eval $val=$i$unit
265+
done
266+
msg=" Memory usage: $memu_pct% - Total: $memt, used: $memu, free: $memf"
267+
elif test $query = procs; then
268+
res=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_PROCS`
269+
warning=${warning:='150'}
270+
critical=${critical:='200'}
271+
if test $res -gt $critical; then
272+
ret=CRITICAL
273+
elif test $res -gt $warning; then
274+
ret=WARNING
275+
elif test $res -ge 0; then
276+
ret=OK
277+
fi
278+
msg=" $res processes"
279+
elif test $query = states; then
280+
res=`snmpget -t2 -r2 -v1 -c $community -Ovq $target $OID_STATES`
281+
warning=${warning:='15000'}
282+
critical=${critical:='20000'}
283+
if test $res -gt $critical; then
284+
ret=CRITICAL
285+
elif test $res -gt $warning; then
286+
ret=WARNING
287+
elif test $res -gt 0; then
288+
ret=OK
289+
fi
290+
msg=" $res states"
291+
fi >/dev/null 2>&1
292+
293+
echo $ret$msg$pefdata
294+
eval ret=\$$ret
295+
exit $ret
296+

0 commit comments

Comments
 (0)