-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_watchguard.sh
275 lines (242 loc) · 10 KB
/
check_watchguard.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
#!/bin/bash
# - VAR
# - Bash info
APPNAME=$(basename $0)
NAME="Check WatchGuard"
AUTHOR="Kalarumeth"
VERSION="v1.3"
URL="https://github.com/Kalarumeth/Check-WatchGuard"
# - Default settings for connection
COMMUNITY="public"
HOST_NAME="localhost"
SNMPVERSION="2c"
# - State Variables
STATE_OK=0
STATE_WARN=1
STATE_CRIT=2
STATE_UNK=3
STATE=$STATE_OK
# - Range Variables
WA=80
CR=90
maxActiveConns=3300000
# - OID
WatchGuard.OIDS() {
# - wgSystemStatisticsMIB
OID_wgSystemTotalSendBytes="1.3.6.1.4.1.3097.6.3.8"
OID_wgSystemTotalRecvBytes="1.3.6.1.4.1.3097.6.3.9"
OID_wgSystemTotalSendPackets="1.3.6.1.4.1.3097.6.3.10"
OID_wgSystemTotalRecvPackets="1.3.6.1.4.1.3097.6.3.11"
OID_wgSystemCpuUtil1="1.3.6.1.4.1.3097.6.3.77"
OID_wgSystemCurrActiveConns="1.3.6.1.4.1.3097.6.3.80"
# - wgMem
OID_wgMemTotalReal="1.3.6.1.4.1.2021.4.5.0"
OID_wgMemAvailReal="1.3.6.1.4.1.2021.4.6.0"
# - wgIpsecStats
OID_wgIpsecTunnelNum="1.3.6.1.4.1.3097.6.5.1.1"
# - wgInfoSystem
OID_wgInfoGavService="1.3.6.1.4.1.3097.6.1.3.0"
OID_wgInfoIpsService="1.3.6.1.4.1.3097.6.1.4"
}
# - MAIN CODE
Source.HostAlive() {
for host in $HOST_NAME; do
ping -c1 -W1 -q $host &>/dev/null
if [[ $? != 0 ]] ; then
printf "%s\n" "$host is unreachable"
exit $STATE_UNK
fi
done
}
Source.SNMP() {
snmpwalk -v $SNMPVERSION -r 1 -t 10 -Oe -c $COMMUNITY $HOST_NAME $1
}
# - WatchGuard Health Monitoring
WatchGuard.Main() {
Source.HostAlive
case $1 in
ac)
WatchGuard.ActiveConns ;;
cpu)
WatchGuard.Cpu ;;
data)
WatchGuard.TransferData ;;
info)
WatchGuard.Info ;;
ram)
WatchGuard.Ram ;;
*)
echo "Unknown Monitoring: $1"
Help.WatchGuard
STATE=$STATE_UNK ;;
esac
}
WatchGuard.GetData() {
WatchGuard.OIDS
case $1 in
data)
totalSendGb=$(Source.SNMP $OID_wgSystemTotalSendBytes | cut -d " " -f 4 | awk '{ byte = $1 /1024/1024/1024; print byte }' | xargs printf "%.0f")
totalRecvGb=$(Source.SNMP $OID_wgSystemTotalRecvBytes | cut -d " " -f 4 | awk '{ byte = $1 /1024/1024/1024; print byte }' | xargs printf "%.0f")
totalSendPackets=$(Source.SNMP $OID_wgSystemTotalSendPackets | cut -d " " -f 4)
totalRecvPackets=$(Source.SNMP $OID_wgSystemTotalRecvPackets | cut -d " " -f 4) ;;
cpu)
cpuPercentage=$(Source.SNMP $OID_wgSystemCpuUtil1 | cut -d " " -f 4 | awk '{ cpu = $1 /100; print cpu }') ;;
ram)
rawRamAll=$(Source.SNMP $OID_wgMemTotalReal | cut -d " " -f 4)
rawRamFree=$(Source.SNMP $OID_wgMemAvailReal | cut -d " " -f 4)
valueRamAllGb=$(echo "$rawRamAll" | awk '{ gbyte = $1 /1024/1024; print gbyte }' | xargs printf "%.2f")
valueRamFreeGb=$(echo "$rawRamFree" | awk '{ gbyte = $1 /1024/1024; print gbyte }' | xargs printf "%.2f")
printPercetageRam=$(echo "$rawRamFree" "$rawRamAll" | awk '{ ramp = $1 /$2 *100; print ramp }' | xargs printf "%.2f")
printPercetageRamUsed=$(echo "$printPercetageRam" | awk '{ ramup = 100 - $1; print ramup }')
rangePercetageRam=$(echo "$printPercetageRamUsed" | cut -d "." -f1)
rawRamUsed=$(echo "$rawRamAll" "$rawRamFree" | awk '{ used = $1 -$2; print used }')
valueRamUsedGb=$(echo "$rawRamUsed" | awk '{ gbyte = $1 /1024/1024; print gbyte }' | xargs printf "%.2f") ;;
ac)
rawActiveConns=$(Source.SNMP $OID_wgSystemCurrActiveConns | cut -d " " -f 4)
rawPercetageActiveConns=$(echo "$rawActiveConns $maxActiveConns" | awk '{ perc = $1 /$2 *100; print perc; }')
rangeActiveConns=$(echo "$rawPercetageActiveConns" | cut -d "." -f 1 )
printPercetageActiveConns=$(echo "$rawPercetageActiveConns" | xargs printf "%.2f")
printValueActiveConns=$(echo "$rawActiveConns" | perl -pe 's/(\d{1,3})(?=(?:\d{3}){1,5}\b)/\1./g')
printMaxActiveConns=$(echo "$maxActiveConns" | perl -pe 's/(\d{1,3})(?=(?:\d{3}){1,5}\b)/\1./g') ;;
info)
ipsecNum=$(Source.SNMP $OID_wgIpsecTunnelNum | cut -d " " -f 4)
rawInfoGav=$(Source.SNMP $OID_wgInfoGavService)
InfoGavVers=$(echo "$rawInfoGav" | cut -d "<" -f 2 | cut -d ">" -f 1)
InfoGavData=$(echo "$rawInfoGav" | cut -d "(" -f 2 | cut -d ")" -f 1)
rawInfoIps=$(snmpwalk -v $SNMPVERSION -c $COMMUNITY $HOST_NAME $OID_wgInfoIpsService 2>&1 | sed 's/Timeout: No Response.*/Idle/')
if [ "$rawInfoIps" != "Idle" ] ; then
rawInfoIps=$(echo $rawInfoIps)
fi
InfoIpsVers=$(echo "$rawInfoIps" | cut -d "<" -f 2 | cut -d ">" -f 1)
InfoIpsData=$(echo "$rawInfoIps" | cut -d "(" -f 2 | cut -d ")" -f 1) ;;
esac
}
WatchGuard.TransferData() {
WatchGuard.GetData data
printf "%s\n" "Send $totalSendGb GB / Recive $totalRecvGb GB"
printf "%s\n" "WatchGuard transfer info:"
printf "%s\t%s\t%s\n" "Total Data Send:" "$totalSendGb GB" "$totalSendPackets Pkg"
printf "%s\t%s\t%s\n" "Total Data Recive:" "$totalRecvGb GB" "$totalRecvPackets Pkg"
}
WatchGuard.Cpu() {
WatchGuard.GetData cpu
for value in $cpuPercentage; do
case 1 in
$(($value <= $WA-1)))
echo "OK! CPU used: $value%" && exit $STATE_OK ;;
$(($value <= $CR-1)))
echo "WARRING! CPU used: $value%" && exit $STATE_WARN ;;
$(($value > $CR-1)))
echo "CRITICAL! CPU used: $value%" && exit $STATE_CRIT ;;
esac
done
}
WatchGuard.Ram() {
WatchGuard.GetData ram
case 1 in
$(($rangePercetageRam <= $WA-1)))
printf "%s\n" "OK! RAM used: $valueRamUsedGb / $valueRamAllGb GB ($printPercetageRamUsed%)" "RAM free: $valueRamFreeGb GB ($printPercetageRam%)" && exit $STATE_OK ;;
$(($rangePercetageRam <= $CR-1)))
printf "%s\n" "WARRING! RAM used: $valueRamUsedGb / $valueRamAllGb GB ($printPercetageRamUsed%)" "RAM free: $valueRamFreeGb GB ($printPercetageRam%)" && exit $STATE_WARN ;;
$(($rangePercetageRam > $CR-1)))
printf "%s\n" "CRITICAL! RAM used: $valueRamUsedGb / $valueRamAllGb GB ($printPercetageRamUsed%)" "RAM free: $valueRamFreeGb GB ($printPercetageRam%)" && exit $STATE_CRIT ;;
esac
}
WatchGuard.ActiveConns() {
WatchGuard.GetData ac
case 1 in
$(($rangeActiveConns <= $WA-1)))
printf "%s\n" "OK! Active Connections used: $printPercetageActiveConns%" "Current Active Connections: $printValueActiveConns of $printMaxActiveConns" && exit $STATE_OK ;;
$(($rangeActiveConns <= $CR-1)))
printf "%s\n" "WARRING! Active Connections used: $printPercetageActiveConns%" "Current Active Connections: $printValueActiveConns of $printMaxActiveConns" && exit $STATE_WARN ;;
$(($rangeActiveConns > $CR-1)))
printf "%s\n" "CRITICAL! Active Connections used: $printPercetageActiveConns%" "Current Active Connections: $printValueActiveConns of $printMaxActiveConns" && exit $STATE_CRIT ;;
esac
}
WatchGuard.Info() {
WatchGuard.GetData info
printf "%s\t%s\n\n" "VPN active:" "$ipsecNum"
printf "%s\n%s\n\n" "Gateway Antivirus Service: $InfoGavVers" " Last Update: $InfoGavData"
printf "%s\n" "Intrusion Prevention Service: $InfoIpsVers" " Last Update: $InfoIpsData"
}
# - HELP
Help.Main() {
echo "Script bash for moninitoring WatchGuard Health"
echo ''
Help.Usage
echo ''
Help.Option
echo ''
Help.WatchGuard
echo ''
Help.Support
echo ''
Help.Info
echo ''
exit $STATE_UNK
}
Help.Usage() {
printf "%s\n" "Method to compose the execution string:" "./$APPNAME -c <SNMP community> -h <host> [-wa <value> -cr <value> -ac <value>] -t <object>"
}
Help.Option() {
printf "%s\n" "OPTIONS:"
printf "%s\t%s\t%s\n\t\t\t%s\n" "-c" "--community" "SNMP v2 community string with Read access." " Default is: $COMMUNITY."
printf "%s\t%s\t\t%s\n\t\t\t%s\n" "-h" "--host" "Host name or IP address to check." " Default is: $HOST_NAME."
printf "%s\t%s\t%s\n\t\t\t%s\n" "-wa" "--allert-wa" "Defines the threshold for Warning." " Default is: $WA."
printf "%s\t%s\t%s\n\t\t\t%s\n" "-cr" "--allert-cr" "Defines the threshold for Critical." " Default is: $CR."
printf "%s\t%s\t%s\n\t\t\t%s\n" "-ac" "--activeconns" "Defines the threshold for Max ActiveConnection." " Default is: $maxActiveConns."
printf "%s\t%s\t\t%s\n\t\t\t%s\n" "-t" "--type" "[REQUIRED OPTION] Field for select element to check on WatchGuard Device." " { ac | cpu | data | info | ram }"
printf "%s\t%s\t\t%s\n" "-H" "--help" "Show script help."
printf "%s\t%s\t%s\n" "-V" "--version" "Show script version."
}
Help.WatchGuard() {
printf "\n%s\n\n" "WatchGuard Check Function"
printf "%s\t%s\n\n" "Check" "Description"
printf "%s\t%s\n" "ac" "Monitoring Active Connection."
printf "%s\t%s\n" "cpu" "Monitoring Cpu load."
printf "%s\t%s\n" "data" "Monitoring Data Tranfer."
printf "%s\t%s\n" "info" "Monitoring Ip Sec, Info Gav Service and Info Ips Service."
printf "%s\t%s\n" "ram" "Monitoring RAM load."
}
Help.Support(){
printf "%s\n" "GitHub Supporters:"
printf "\t%s\n" "kelups"
}
Help.Info() {
printf "%s\t%s\t%s\n" "INFO:" "$NAME" "$VERSION" "" "$AUTHOR" "$URL"
}
# - COMMAND LINE ENCODER
# - Prompt
while test -n "$1"; do
case "$1" in
--host|-h)
HOST_NAME=$2
shift ;;
--comunity|-c)
COMMUNITY=$2
shift ;;
--activeconns|-ac)
maxActiveConns=$2
shift ;;
--allert-wa|-wa)
WA=$2
shift ;;
--allert-cr|-cr)
CR=$2
shift ;;
--type|-t)
WatchGuard.Main $2
shift ;;
--help|-H)
Help.Main ;;
--version|-V)
Help.Info
exit $STATE ;;
*)
echo "Unknown argument: $1"
Help.Main
exit $STATE_UNK ;;
esac
shift
done
exit $STATE