| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package network::cyberoam::snmp::mode::vpnstatus; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $msg = 'status: ' . $self->{result_values}->{connection_status}; |
| 33 |
return $msg; |
| 34 |
} |
| 35 |
|
| 36 |
sub prefix_global_output { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
return 'VPN '; |
| 40 |
} |
| 41 |
|
| 42 |
sub vpn_long_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return "checking vpn '" . $options{instance_value}->{display} . "'"; |
| 46 |
} |
| 47 |
|
| 48 |
sub prefix_vpn_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
my $output = "VPN '" . $options{instance_value}->{display} . "' "; |
| 52 |
|
| 53 |
if (defined(($options{instance_value}->{vpn_global}->{description})) |
| 54 |
&& ($options{instance_value}->{vpn_global}->{description})) { |
| 55 |
$output .= "($options{instance_value}->{vpn_global}->{description}) "; |
| 56 |
} |
| 57 |
|
| 58 |
return $output; |
| 59 |
} |
| 60 |
|
| 61 |
sub set_counters { |
| 62 |
my ($self, %options) = @_; |
| 63 |
|
| 64 |
$self->{maps_counters_type} = [ |
| 65 |
{ |
| 66 |
name => 'global', |
| 67 |
type => 0, |
| 68 |
cb_prefix_output => 'prefix_global_output' |
| 69 |
}, |
| 70 |
{ |
| 71 |
name => 'vpn', |
| 72 |
type => 3, |
| 73 |
cb_prefix_output => 'prefix_vpn_output', |
| 74 |
cb_long_output => 'vpn_long_output', |
| 75 |
indent_long_output => ' ', |
| 76 |
message_multiple => 'All VPNs are ok', |
| 77 |
group => [ |
| 78 |
{ name => 'vpn_global', type => 0 } |
| 79 |
] |
| 80 |
} |
| 81 |
]; |
| 82 |
|
| 83 |
$self->{maps_counters}->{global} = [ |
| 84 |
{ |
| 85 |
label => 'total', |
| 86 |
type => 1, |
| 87 |
nlabel => 'vpn.total.count', |
| 88 |
set => { |
| 89 |
key_values => [ { name => 'total' } ], |
| 90 |
output_template => 'total: %s', |
| 91 |
perfdatas => [ |
| 92 |
{ label => 'total', template => '%s', min => 0 } |
| 93 |
] |
| 94 |
} |
| 95 |
}, |
| 96 |
{ |
| 97 |
label => 'total-inactive', |
| 98 |
type => 1, |
| 99 |
nlabel => 'vpn.inactive.count', |
| 100 |
set => { |
| 101 |
key_values => [ { name => 'inactive' } ], |
| 102 |
output_template => 'inactive: %s', |
| 103 |
perfdatas => [ |
| 104 |
{ label => 'total_inactive', template => '%s', min => 0 } |
| 105 |
] |
| 106 |
} |
| 107 |
}, |
| 108 |
{ |
| 109 |
label => 'total-active', |
| 110 |
type => 1, |
| 111 |
nlabel => 'vpn.active.count', |
| 112 |
set => { |
| 113 |
key_values => [ { name => 'active' } ], |
| 114 |
output_template => 'active: %s', |
| 115 |
perfdatas => [ |
| 116 |
{ label => 'total_active', template => '%s', min => 0 } |
| 117 |
] |
| 118 |
} |
| 119 |
}, |
| 120 |
{ |
| 121 |
label => 'total-partially-active', |
| 122 |
type => 1, |
| 123 |
nlabel => 'vpn.partiallyactive.count', |
| 124 |
set => { |
| 125 |
key_values => [ { name => 'partiallyActive' } ], |
| 126 |
output_template => 'partially active: %s', |
| 127 |
perfdatas => [ |
| 128 |
{ label => 'total_partially_active', template => '%s', min => 0 } |
| 129 |
] |
| 130 |
} |
| 131 |
} |
| 132 |
]; |
| 133 |
|
| 134 |
$self->{maps_counters}->{vpn_global} = [ |
| 135 |
{ |
| 136 |
label => 'status', |
| 137 |
type => 2, |
| 138 |
critical_default => '%{connection_status} =~ /inactive/', |
| 139 |
warning_default => '%{connection_status} =~ /partiallyActive/', |
| 140 |
set => { |
| 141 |
key_values => [ { name => 'connection_status' }, { name => 'display' }, { name => 'description' } ], |
| 142 |
closure_custom_output => $self->can('custom_status_output'), |
| 143 |
closure_custom_perfdata => sub {return 0;}, |
| 144 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 145 |
} |
| 146 |
} |
| 147 |
]; |
| 148 |
} |
| 149 |
|
| 150 |
sub new { |
| 151 |
my ($class, %options) = @_; |
| 152 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 153 |
bless $self, $class; |
| 154 |
|
| 155 |
$options{options}->add_options(arguments => { |
| 156 |
"filter-name:s" => { name => 'filter_name' }, |
| 157 |
"filter-vpn-activated:s" => { name => 'filter_vpn_activated' }, |
| 158 |
"filter-connection-mode:s" => { name => 'filter_connection_mode' }, |
| 159 |
"filter-connection-type:s" => { name => 'filter_connection_type' } |
| 160 |
}); |
| 161 |
|
| 162 |
return $self; |
| 163 |
} |
| 164 |
|
| 165 |
# SFOS-FIREWALL-MIB::sfosIPSecVpnConnStatus |
| 166 |
# sfosIPSecVpnConnStatus OBJECT-TYPE |
| 167 |
# -- FROM SFOS-FIREWALL-MIB |
| 168 |
# -- TEXTUAL CONVENTION IPSecVPNConnectionStatus |
| 169 |
# SYNTAX INTEGER {inactive(0), active(1), partially-active(2)} |
| 170 |
# MAX-ACCESS read-only |
| 171 |
# STATUS current |
| 172 |
# DESCRIPTION "Connection status of IPsec tunnel" |
| 173 |
# ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) sophosMIB(2604) sfosXGMIB(5) sfosXGMIBObjects(1) sfosXGTunnelInfo(6) sfosVPNInfo(1) sfosIPSecVPNConnInfo(1) sfosIPSecVpnTunnelTable(1) sfosIPSecVpnTunnelEntry(1) 9 } |
| 174 |
my $map_connection_status = { |
| 175 |
0 => 'inactive', |
| 176 |
1 => 'active', |
| 177 |
2 => 'partiallyActive' |
| 178 |
}; |
| 179 |
|
| 180 |
# SFOS-FIREWALL-MIB::sfosIPSecVpnActivated |
| 181 |
# sfosIPSecVpnActivated OBJECT-TYPE |
| 182 |
# -- FROM SFOS-FIREWALL-MIB |
| 183 |
# -- TEXTUAL CONVENTION IPSecVPNActivationStatus |
| 184 |
# SYNTAX INTEGER {inactive(0), active(1)} |
| 185 |
# MAX-ACCESS read-only |
| 186 |
# STATUS current |
| 187 |
# DESCRIPTION "Activation status of IPsec tunnel" |
| 188 |
# ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) sophosMIB(2604) sfosXGMIB(5) sfosXGMIBObjects(1) sfosXGTunnelInfo(6) sfosVPNInfo(1) sfosIPSecVPNConnInfo(1) sfosIPSecVpnTunnelTable(1) sfosIPSecVpnTunnelEntry(1) 10 } |
| 189 |
my $map_vpn_activated = { |
| 190 |
0 => 'inactive', |
| 191 |
1 => 'active' |
| 192 |
}; |
| 193 |
|
| 194 |
# SFOS-FIREWALL-MIB::sfosIPSecVpnConnType |
| 195 |
# sfosIPSecVpnConnType OBJECT-TYPE |
| 196 |
# -- FROM SFOS-FIREWALL-MIB |
| 197 |
# -- TEXTUAL CONVENTION IPSecVPNConnectionType |
| 198 |
# SYNTAX INTEGER {host-to-host(1), site-to-site(2), tunnel-interface(3)} |
| 199 |
# MAX-ACCESS read-only |
| 200 |
# STATUS current |
| 201 |
# DESCRIPTION "Connection Type of IPsec Tunnel" |
| 202 |
# ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) sophosMIB(2604) sfosXGMIB(5) sfosXGMIBObjects(1) sfosXGTunnelInfo(6) sfosVPNInfo(1) sfosIPSecVPNConnInfo(1) sfosIPSecVpnTunnelTable(1) sfosIPSecVpnTunnelEntry(1) 6 } |
| 203 |
my $map_connection_type = { |
| 204 |
1 => 'host-to-host', |
| 205 |
2 => 'site-to-site', |
| 206 |
3 => 'tunnel-interface' |
| 207 |
}; |
| 208 |
|
| 209 |
my $mapping = { |
| 210 |
name => { oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.2' },# sfosIPSecVpnConnName |
| 211 |
connection_mode => { oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.5' },# sfosIPSecVpnConnMode |
| 212 |
connection_type => { oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.6', map => $map_connection_type },# sfosIPSecVpnConnType |
| 213 |
activated => { oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.10', map => $map_vpn_activated }# sfosIPSecVpnActivated |
| 214 |
}; |
| 215 |
|
| 216 |
my $mapping_stat = { |
| 217 |
description => { oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.3' },# sfosIPSecVpnConnDes |
| 218 |
connection_status => |
| 219 |
{ oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.9', map => $map_connection_status }# sfosIPSecVpnConnStatus |
| 220 |
}; |
| 221 |
|
| 222 |
sub manage_selection { |
| 223 |
my ($self, %options) = @_; |
| 224 |
|
| 225 |
$self->{vpn} = {}; |
| 226 |
$self->{global} = { |
| 227 |
inactive => 0, |
| 228 |
active => 0, |
| 229 |
partiallyActive => 0 |
| 230 |
}; |
| 231 |
|
| 232 |
my $request = [ { oid => $mapping->{name}->{oid} } ]; |
| 233 |
push @$request, { oid => $mapping->{activated}->{oid} } |
| 234 |
if (defined($self->{option_results}->{filter_vpn_activated}) && $self->{option_results}->{filter_vpn_activated} ne ''); |
| 235 |
|
| 236 |
push @$request, { oid => $mapping->{connection_mode}->{oid} } |
| 237 |
if (defined($self->{option_results}->{filter_connection_mode}) && $self->{option_results}->{filter_connection_mode} ne ''); |
| 238 |
|
| 239 |
push @$request, { oid => $mapping->{connection_type}->{oid} } |
| 240 |
if (defined($self->{option_results}->{filter_connection_type}) && $self->{option_results}->{filter_connection_type} ne ''); |
| 241 |
|
| 242 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 243 |
oids => $request, |
| 244 |
return_type => 1, |
| 245 |
nothing_quit => 1 |
| 246 |
); |
| 247 |
|
| 248 |
foreach (keys %$snmp_result) { |
| 249 |
next if (!/^$mapping->{name}->{oid}\.(.*)/); |
| 250 |
my $instance = $1; |
| 251 |
|
| 252 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 253 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 254 |
$result->{name} !~ /$self->{option_results}->{filter_name}/) { |
| 255 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{name} . "': not matching name filter."); |
| 256 |
next; |
| 257 |
} |
| 258 |
|
| 259 |
if (defined($self->{option_results}->{filter_connection_type}) && $self->{option_results}->{filter_connection_type} ne '' && |
| 260 |
$result->{connection_type} !~ /$self->{option_results}->{filter_connection_type}/) { |
| 261 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{connection_type} . "': not matching connection-type filter."); |
| 262 |
next; |
| 263 |
} |
| 264 |
|
| 265 |
if (defined($self->{option_results}->{filter_connection_mode}) && $self->{option_results}->{filter_connection_mode} ne '' && |
| 266 |
$result->{connection_mode} !~ /$self->{option_results}->{filter_connection_mode}/) { |
| 267 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{connection_mode} . "': not matching connection-mode filter."); |
| 268 |
next; |
| 269 |
} |
| 270 |
|
| 271 |
if (defined($self->{option_results}->{filter_vpn_activated}) && $self->{option_results}->{filter_vpn_activated} ne '' && |
| 272 |
$result->{activated} !~ /$self->{option_results}->{filter_vpn_activated}/) { |
| 273 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{activated} . "': not matching vpn-activated filter " . $self->{option_results}->{filter_vpn_activated} . "."); |
| 274 |
next; |
| 275 |
} |
| 276 |
|
| 277 |
$self->{vpn}->{ $result->{name} } = { |
| 278 |
instance => $instance, |
| 279 |
display => $result->{name}, |
| 280 |
vpn_global => { display => $result->{name} } }; |
| 281 |
} |
| 282 |
|
| 283 |
if (scalar(keys %{$self->{vpn}}) <= 0) { |
| 284 |
$self->{output}->output_add(long_msg => 'no VPN associated'); |
| 285 |
return; |
| 286 |
} |
| 287 |
|
| 288 |
$options{snmp}->load( |
| 289 |
oids => [ map($_->{oid}, values(%$mapping_stat)) ], |
| 290 |
instances => [ map($_->{instance}, values %{$self->{vpn}}) ], |
| 291 |
instance_regexp => '^(.*)$' |
| 292 |
); |
| 293 |
$snmp_result = $options{snmp}->get_leef(); |
| 294 |
|
| 295 |
foreach (keys %{$self->{vpn}}) { |
| 296 |
my $result = $options{snmp}->map_instance( |
| 297 |
mapping => $mapping_stat, |
| 298 |
results => $snmp_result, |
| 299 |
instance => $self->{vpn}->{$_}->{instance}); |
| 300 |
|
| 301 |
$self->{global}->{total}++; |
| 302 |
$self->{global}->{ $result->{connection_status} }++; |
| 303 |
$self->{vpn}->{$_}->{vpn_global}->{connection_status} = $result->{connection_status}; |
| 304 |
$self->{vpn}->{$_}->{vpn_global}->{description} = $result->{description}; |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
1; |
| 309 |
|
| 310 |
__END__ |
| 311 |
|
| 312 |
=head1 MODE |
| 313 |
|
| 314 |
Check VPN status. |
| 315 |
VPN-Connection-Status: inactive, active, partiallyActive |
| 316 |
|
| 317 |
=over 8 |
| 318 |
|
| 319 |
=item B<--filter-counters> |
| 320 |
|
| 321 |
Only display some counters (regexp can be used). |
| 322 |
Example: --filter-counters='^total$|^total-normal$' |
| 323 |
|
| 324 |
=item B<--filter-name> |
| 325 |
|
| 326 |
Filter VPN name (can be a regexp). |
| 327 |
|
| 328 |
=item B<--filter-vpn-activated> |
| 329 |
|
| 330 |
Filter by the activation status of the VPN (can be a regexp). |
| 331 |
Values: active, inactive |
| 332 |
|
| 333 |
=item B<--filter-connection-mode> |
| 334 |
|
| 335 |
Filter by the connection mode of the VPN (can be a regexp). |
| 336 |
|
| 337 |
=item B<--connection-type> |
| 338 |
|
| 339 |
Filter by the connection type of the VPN (can be a regexp). |
| 340 |
Values: host-to-host, site-to-site, tunnel-interface |
| 341 |
|
| 342 |
=item B<--warning-status> |
| 343 |
|
| 344 |
Trigger warning on %{connection_status} values. |
| 345 |
(default: '%{connection_status} =~ /partiallyActive/'). |
| 346 |
|
| 347 |
=item B<--critical-status> |
| 348 |
|
| 349 |
Trigger critical on %{connection_status} values. |
| 350 |
(default: '%{connection_status} =~ /inactive/'). |
| 351 |
|
| 352 |
=item B<--warning-total> |
| 353 |
|
| 354 |
Thresholds. |
| 355 |
|
| 356 |
=item B<--critical-total> |
| 357 |
|
| 358 |
Thresholds. |
| 359 |
|
| 360 |
=item B<--warning-total-inactive> |
| 361 |
|
| 362 |
Thresholds. |
| 363 |
|
| 364 |
=item B<--critical-total-inactive> |
| 365 |
|
| 366 |
Thresholds. |
| 367 |
|
| 368 |
=item B<--warning-total-partially-active> |
| 369 |
|
| 370 |
Thresholds. |
| 371 |
|
| 372 |
=item B<--critical-total-partially-active> |
| 373 |
|
| 374 |
Thresholds. |
| 375 |
|
| 376 |
=item B<--warning-total-active> |
| 377 |
|
| 378 |
Thresholds. |
| 379 |
|
| 380 |
=item B<--critical-total-active> |
| 381 |
|
| 382 |
Thresholds. |
| 383 |
|
| 384 |
=back |
| 385 |
|
| 386 |
=cut |