-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_snmp_cisco_firewall
executable file
·326 lines (282 loc) · 8.4 KB
/
check_snmp_cisco_firewall
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
#!/bin/bash
#
# Written By: Pierre SOURDEAU to AMF company [FRANCE]
# Created: 28/10/2008
# Description: Check SNMP v 1, 2c, 3 for Cisco Firewall, and return :
### Mode 1 - Failover ###
# - fail over status for ptimary and secondary host
# => warning if primary = stanby and secondary = active
# => critical if primary or secondary = error
# => unknwon if failover is not configured
### Mode 2 - Sessions ###
# - number of sessions in use
# => warning or critical exit if superior
# - number of max session ever used
#
# Each mode included graphic return to Centreon application
#
# Check succesfuly on Cisco PIX-515E and ASA-5500
#
# License: This nagios plugin comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of
# the plugins under the terms of the GNU General Public License. For more information about these
# matters, see the GNU General Public License.
# Version: 2.3 (updated 09/04/2009)
############################################################
# Varialbles
############################################################
PROGNAME=$0
#`/bin/basename $0` #no basename on Mac OS X 10.3
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$PROGNAME: 2.3 $' | sed -e 's/[^0-9.]//g'`
SNMPGET="/usr/bin/snmpget";
SNMPWALK="/usr/bin/snmpwalk";
. /usr/lib64/nagios/plugins/utils.sh
USAGE="Usage: check_cisco_firewall.sh -H hostname -V version -M failover|sessions [-w|-c|-C|-l|-u|-a|-d|-h]
### PARAMETERS ###
-H Hostname (IP adresse or DNS name)
-V Version (1|2c|3)
-M Mode (failover|sessions)
### OPTIONNAL ###
-w Warning_Level (number of sessions before warning) *** Use on session mode ***
-c Critical_Level (number of sessions before critical) *** Use on session mode ***
-C Community (name) *** Use on Version 1|2 ***
-l Login (NoAuthNoPriv | AuthNoPriv | AuthPriv) *** Use on Version 3 ***
-u Username *** Use on Version 3 ***
-a Password *** Use on Version 3 ***
-d Debug mode
-h Help (print command usage, and quit)"
sum_value_Ok=0
sum_value_Warning=0
sum_value_Critical=0
sum_value_Unknwon=0
failover_status_value=([3]=Down [4]=Error [9]=Active [10]=Standby)
actives_nodes=0
comm_final=""
walk_param=""
mib_failover_prim=".1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.6"
mib_failover_sec=".1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.7"
mib_sessions_current=".1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.6"
mib_sessions_max=".1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.7"
############################################################
# Global Functions
############################################################
# Check if value is numeric or not
check_num()
{
if ! let $1 2> /dev/null
then
if [ $1 != 0 ]
then
echo "Error - Not numeric value : $2 = $1"
exit $STATE_UNKNOWN
fi
fi
}
# Check Parameters
check_param()
{
if [ "$hostname" == "" ] || [ "$version" == "" ] || [ "$mode" == "" ]
then
echo "Error - Missing parameters - hostname = $hostname : version = $version : mode = $mode"
echo "$USAGE"
exit $STATE_UNKNOWN
fi
case $version in
1 | 2c)
if [ "$community" == "" ]
then
echo "Error - Missing parameters - community = $community"
echo "$USAGE"
exit $STATE_UNKNOWN
fi
walk_param="-v $version -c $community $hostname";;
3)
if [ "$login" == "" ] || [ "$user" == "" ] || [ "$password" == "" ]
then
echo "Error - Missing parameters - login = $login : user = $user : password = $password"
echo "$USAGE"
exit $STATE_UNKNOWN
fi
walk_param="-v $version -l $login -u $user -A $password $hostname";;
esac
}
# Command used to debug
debug()
{
echo "*********************************************************************"
echo "### Mode Failover ###"
echo "Status primaire = $status_prim (${failover_status_value[$status_prim]})"
echo "Status secondaire = $status_sec (${failover_status_value[$status_sec]})"
echo "### Mode Sessions ###"
echo "Number of used sessions : $Used_Sessions"
echo "Number of max sessions ever used : $Max_Used_Sessions"
echo "### Global Values ###"
echo "Sum values : Ok = $sum_value_Ok ; Warning = $sum_value_Warning ; Critical = $sum_value_Critical ; Unknown = $sum_value_Unknwon"
echo "Nagios return : Ok = $STATE_OK ; Warning = $STATE_WARNING ; Critical = $STATE_CRITICAL ; Unknown = $STATE_UNKNOWN"
echo "Parameters : Hostname = $hostname ; Version = $version ; Community = $community ; Mode = $mode ; warning = $warning ; critical = $critical ; login = $login ; user = $user ; password = $password"
echo "*********************************************************************"
}
# Results sent to Nagios
function_exit()
{
if [ $sum_value_Unknwon != 0 ]
then
echo "Unknown $comm_final"
exit $STATE_UNKNOWN
fi
if [ $sum_value_Critical != 0 ]
then
echo "Critical $comm_final"
exit $STATE_CRITICAL
fi
if [ $sum_value_Warning != 0 ]
then
echo "Warning $comm_final"
exit $STATE_WARNING
fi
if [ $sum_value_Ok != 0 ]
then
echo "OK $comm_final"
exit $STATE_OK
fi
}
############################################################
# Mode Failover Functions
############################################################
# Failover Status
failover_status()
{
status_prim=`$SNMPGET $walk_param $mib_failover_prim | cut -d' ' -f4`
check_num $status_prim status_prim
status_sec=`$SNMPGET $walk_param $mib_failover_sec | cut -d' ' -f4`
check_num $status_sec status_sec
}
# Failover Sum
failover_sum()
{
if [ $status_prim == 9 ] && [ $status_sec == 10 ]
then
actives_nodes=2
sum_value_Ok=$(( $sum_value_Ok + 1 ))
fi
if [ $status_prim == 10 ] && [ $status_sec == 9 ]
then
actives_nodes=2
sum_value_Warning=$(( $sum_value_Warning + 1 ))
fi
if [ $status_prim == 9 ] && [ $status_sec == 4 ]
then
actives_nodes=1
sum_value_Warning=$(( $sum_value_Warning + 1 ))
fi
if [ $status_prim == 4 ] && [ $status_sec == 9 ]
then
actives_nodes=1
sum_value_Critical=$(( $sum_value_Critical + 1 ))
fi
if [ $status_prim == 4 ] && [ $status_sec == 4 ]
then
actives_nodes=0
sum_value_Critical=$(( $sum_value_Critical + 1 ))
fi
if [ $status_prim == 3 ] && [ $status_sec == 3 ]
then
actives_nodes=0
sum_value_Unknwon=$(( $sum_value_Unknwon + 1 ))
fi
comm_final="$comm_final - Primary = ${failover_status_value[$status_prim]}, Secondary = ${failover_status_value[$status_sec]} | Actives_Nodes=$actives_nodes"
}
############################################################
# Mode Sessions Functions
############################################################
# The number of current sessions used
sessions_current()
{
Used_Sessions=`$SNMPGET $walk_param $mib_sessions_current | cut -d' ' -f4`
check_num $Used_Sessions Used_Sessions
}
# The number of max sessions ever used
sessions_max()
{
if [ "$version" == "1" ]
then
Max_Used_Sessions=`$SNMPGET $walk_param $mib_sessions_max | cut -d' ' -f4`
else
Max_Used_Sessions=`$SNMPGET $walk_param $mib_sessions_max | cut -d' ' -f4`
fi
check_num $Max_Used_Sessions Max_Used_Sessions
if [ $Used_Sessions -gt $Max_Used_Sessions ]
then
echo "Error - Too much sessions used : $Used_Sessions, but only $Max_Used_Sessions max sessions used !"
exit $STATE_UNKNOWN
fi
}
# Sessions Sum
sessions_sum()
{
if [ $Used_Sessions -lt $warning ]
then
sum_value_Ok=$(( $sum_value_Ok + 1 ))
fi
if [ $Used_Sessions -ge $warning ] && [ $Used_Sessions -lt $critical ]
then
sum_value_Warning=$(( $sum_value_Warning + 1 ))
fi
if [ $Used_Sessions -ge $critical ] || [ $Used_Sessions == 0 ]
then
sum_value_Critical=$(( $sum_value_Critical + 1 ))
fi
comm_final="$comm_final - $Used_Sessions sessions (max : $Max_Used_Sessions) | 'Current Used'=$Used_Sessions;$warning;$critical;1;$Max_Used_Sessions"
}
############################################################
# Main Method
############################################################
main()
{
# Get Options and check parameters
while getopts H:V:C:M:w:c:l:u:a:dh option;
do
case $option in
H) hostname=$OPTARG;;
V) version=$OPTARG;;
C) community=$OPTARG;;
M) mode=$OPTARG;;
w) warning=$OPTARG;;
c) critical=$OPTARG;;
l) login=$OPTARG;;
u) user=$OPTARG;;
a) password=$OPTARG;;
d) debug=1;;
h) echo "$USAGE"
exit $STATE_UNKNOWN;;
esac
done
check_param
### Mode 1 - Failover ###
if [ "$mode" == "failover" ]
then
# Functions lunch
failover_status
failover_sum
fi
### Mode 2 - Sessions ###
if [ "$mode" == "sessions" ]
then
# Parameters Checking
check_num $warning warning
check_num $critical critical
# Functions lunch
sessions_current
sessions_max
sessions_sum
fi
if [ "$debug" == 1 ]
then
debug
fi
function_exit
}
main $*
# Default exit
echo "Unknown - No result sent to nagios - End of script"
exit $STATE_UNKNOWN