-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcheck_asa_sessions.pl
204 lines (175 loc) · 5.83 KB
/
check_asa_sessions.pl
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
#!/usr/bin/perl -w
#
# (c) 2008 Marc Patino Gómez (marcpatino at gmail dot com)
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# you should have received a copy of the GNU General Public License
# along with this program (or with Netsaint); if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA
#
#######################################################################
# check_asa_sessions - script for checking asa stablished sessions
# on Cisco ASA clusters using SNMP
#
# Version: 0.2
# Changelog:
# 2008-06-09: Initial version created
# 2015-07-03: OID fix, rewrite, new functions ([email protected])
use strict;
use Net::SNMP;
use Getopt::Long;
use lib '/srv/app/nagios/libexec';
use utils qw (%ERRORS $TIMEOUT);
my $hostname;
my $community;
my $debug;
my $timeout;
my $check_type;
my $cluster_ip;
my $retries;
my $help;
my $warning;
my $critical;
Getopt::Long::Configure('bundling');
GetOptions (
"help" => \$help,
"hostname=s" => \$hostname,
"community=s" => \$community,
"debug" => \$debug,
"timeout=i" => \$timeout,
"retries=i" => \$retries,
"type=s" => \$check_type,
"cluster=s" => \$cluster_ip,
"h" => \$help,
"H=s" => \$hostname,
"C=s" => \$community,
"d" => \$debug,
"t=i" => \$timeout,
"w=s" => \$warning,
"c=s" => \$critical,
"r=i" => \$retries,
"T=s" => \$check_type,
"u=s" => \$cluster_ip
);
unless (defined ($debug)) {
$debug = 0;
}
unless (defined ($timeout)) {
$timeout = $TIMEOUT;
}
unless (defined ($retries)) {
$retries = 1;
}
unless (defined ($retries)) {
$check_type = "ipsec";
}
# OID's to check
my $ipsec_oid = ".1.3.6.1.4.1.9.9.171.1.3.1.1.0"; # Cisco ASA IPSec Session count
my $sslvpn_oid = ".1.3.6.1.4.1.9.9.392.1.3.35.0"; # Cisco ASA SSL VPN count
my $webvpn_oid = ".1.3.6.1.4.1.9.9.392.1.3.38.0"; # Cisco ASA Web VPN count
my $rasvpn_oid = ".1.3.6.1.4.1.9.9.392.1.3.1.0"; # Cisco ASA All VPN session count
# valid values
my @valid_types = ("ipsec","sslvpn","webvpn", "rasvpn");
# Session OID array
my %session_oid = ("ipsec",$ipsec_oid,"sslvpn",$sslvpn_oid,"webvpn",$webvpn_oid,"rasvpn",$rasvpn_oid);
###########################################
# sub: help
# Prints help information
sub help () {
print <<USE;
Usage: check_asa_sessions.pl [options]
where options is
-h, --help Print this text
-H, --hostname Hostname (required)
-C, --community SNMP Community (required)
-w, --warning warning connections (required)
-c, --critical critical connections (required)
-d, --debug Show debug information
-t, --timeout Timeout value in seconds (defaults to $TIMEOUT)
-r, --retries Number of retries (defaults to 1)
-T, --type ipsec | sslvpn | webvpn | rasvpn
-u, --cluster add the IP addresses of the remaining VPN cluster members
this option will count the sessions over all members
and return the summary
Note that every retry has its own timeout value, for example,
if timeout is 15 and retries is 1, maximum timeout would be 30s.
USE
exit ($ERRORS{OK});
};
###########################################
# sub: status_request
# The function that does the actual snmp
# requests
sub status_request () {
my ($hostname, $community, $debug, $timeout, $retries, $check_type) = @_;
my $count = 0;
my $error;
my @oidlist = $session_oid{$check_type};
my ($session);
# SNMPV1 login
($session, $error) = Net::SNMP->session(
-hostname => $hostname,
-community => $community,
-retries => $retries,
-timeout => $timeout
);
unless ($session) {
print "Session error: $error\n";
exit $ERRORS{UNKNOWN};
}
my $result = (Net::SNMP->VERSION < 4) ?
$session->get_request (@oidlist)
: $session->get_request (-varbindlist => \@oidlist);
if (!defined ($$result{$session_oid{$check_type}})) {
print "UNKNOWN: Check timed out\n";
exit ($ERRORS{UNKNOWN});
}
if (!defined($result)) {
printf("ERROR: Description table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
$count=$$result{$session_oid{$check_type}};
$session->close;
return ($count);
}
# Check command line arguments
&help () if ($help);
&help () unless ($hostname && $community);
my ($sessions) = &status_request ($hostname, $community, $debug, $timeout, $retries, $check_type);
if (defined($cluster_ip)) {
my ($csessions) = &status_request ($cluster_ip, $community, $debug, $timeout, $retries, $check_type);
if ($debug) {
print "Primary sessions: $sessions\n";
print "Secondary sessions: $csessions\n";
}
$sessions = $sessions + $csessions;
$check_type = $check_type . " cluster";
}
# perfdata: 'label'=value[UOM];[warn];[crit];[min];[max]
my $perf = "|".$check_type."=".$sessions.";".$warning.";".$critical.";0;\n";
# Determine status against warning /crit thresholds
if ($sessions < $warning) {
print "OK: $sessions Cisco ASA $check_type sessions".$perf;
exit ($ERRORS{OK});
} elsif ($sessions > $warning && $sessions < $critical) {
print "WARNING: $sessions Cisco ASA $check_type sessions".$perf;
exit ($ERRORS{WARNING});
} elsif ($sessions > $critical) {
print "CRITICAL: $sessions Cisco ASA $check_type sessions".$perf;
exit ($ERRORS{CRITICAL});
} else {
print "UNKNOWN: $sessions Cisco ASA $check_type sessions".$perf;
exit ($ERRORS{UNKNOWN});
}