| 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::listvpns; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
$options{options}->add_options(arguments => { |
| 34 |
"filter-name:s" => { name => 'filter_name' }, |
| 35 |
"filter-connection-status:s" => { name => 'filter_connection_status' }, |
| 36 |
"filter-vpn-activated:s" => { name => 'filter_vpn_activated' }, |
| 37 |
}); |
| 38 |
|
| 39 |
return $self; |
| 40 |
} |
| 41 |
|
| 42 |
sub check_options { |
| 43 |
my ($self, %options) = @_; |
| 44 |
$self->SUPER::init(%options); |
| 45 |
} |
| 46 |
|
| 47 |
sub manage_selection { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
my $map_connection_status = { |
| 51 |
0 => 'inactive', |
| 52 |
1 => 'active', |
| 53 |
2 => 'partially-active' |
| 54 |
}; |
| 55 |
|
| 56 |
my $map_vpn_activated = { |
| 57 |
0 => 'inactive', |
| 58 |
1 => 'active' |
| 59 |
}; |
| 60 |
|
| 61 |
my $map_connection_type = { |
| 62 |
1 => 'host-to-host', |
| 63 |
2 => 'site-to-site', |
| 64 |
3 => 'tunnel-interface' |
| 65 |
}; |
| 66 |
|
| 67 |
my $mapping = { |
| 68 |
name => |
| 69 |
{ oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.2' },# sfosIPSecVpnConnName |
| 70 |
policy => |
| 71 |
{ oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.4' },# sfosIPSecVpnPolicyUsed |
| 72 |
description => |
| 73 |
{ oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.3' },# sfosIPSecVpnConnDes |
| 74 |
connection_mode => |
| 75 |
{ oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.5' },# sfosIPSecVpnConnMode |
| 76 |
connection_type => |
| 77 |
{ oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.6', map => $map_connection_type },# sfosIPSecVpnConnType |
| 78 |
connection_status => |
| 79 |
{ oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.9', map => $map_connection_status },# sfosIPSecVpnConnStatus |
| 80 |
activated => |
| 81 |
{ oid => '.1.3.6.1.4.1.2604.5.1.6.1.1.1.1.10', map => $map_vpn_activated }# sfosIPSecVpnActivated |
| 82 |
}; |
| 83 |
# parent oid for all the mapping usage |
| 84 |
my $oid_bsnAPEntry = '.1.3.6.1.4.1.2604.5.1.6.1.1.1'; |
| 85 |
|
| 86 |
my $snmp_result = $options{snmp}->get_table( |
| 87 |
oid => $oid_bsnAPEntry, |
| 88 |
start => $mapping->{name}->{oid},# First oid of the mapping => here : 2 |
| 89 |
end => $mapping->{activated}->{oid}# Last oid of the mapping => here : 23 |
| 90 |
); |
| 91 |
|
| 92 |
my $results = {}; |
| 93 |
# Iterate for all oids catch in snmp result above |
| 94 |
foreach my $oid (keys %$snmp_result) { |
| 95 |
next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/); |
| 96 |
my $oid_path = $1; |
| 97 |
|
| 98 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $oid_path); |
| 99 |
|
| 100 |
if (!defined($result->{name}) || $result->{name} eq '') { |
| 101 |
$self->{output}->output_add(long_msg => |
| 102 |
"skipping VPN '$oid_path': cannot get a name. please set it.", |
| 103 |
debug => |
| 104 |
1); |
| 105 |
next; |
| 106 |
} |
| 107 |
|
| 108 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 109 |
$result->{name} !~ /$self->{option_results}->{filter_name}/) { |
| 110 |
$self->{output}->output_add(long_msg => |
| 111 |
"skipping '" . $result->{name} . "': no matching name filter.", |
| 112 |
debug => |
| 113 |
1); |
| 114 |
next; |
| 115 |
} |
| 116 |
|
| 117 |
if (defined($self->{option_results}->{filter_connection_status}) && $self->{option_results}->{filter_connection_status} ne '' && |
| 118 |
$result->{connection_status} !~ /$self->{option_results}->{filter_connection_status}/) { |
| 119 |
$self->{output}->output_add(long_msg => |
| 120 |
"skipping '" . $result->{connection_status} . "': no matching connection_status filter.", |
| 121 |
debug => |
| 122 |
1); |
| 123 |
next; |
| 124 |
} |
| 125 |
|
| 126 |
if (defined($self->{option_results}->{filter_vpn_activated}) && $self->{option_results}->{filter_vpn_activated} ne '' && |
| 127 |
$result->{activated} !~ /$self->{option_results}->{filter_vpn_activated}/) { |
| 128 |
$self->{output}->output_add(long_msg => |
| 129 |
"skipping '" . $result->{activated} . "': no matching activated filter.", |
| 130 |
debug => |
| 131 |
1); |
| 132 |
next; |
| 133 |
} |
| 134 |
|
| 135 |
$results->{$oid_path} = { |
| 136 |
name => $result->{name}, |
| 137 |
policy => $result->{policy}, |
| 138 |
description => $result->{description}, |
| 139 |
connection_mode => $result->{connection_mode}, |
| 140 |
connection_type => $result->{connection_type}, |
| 141 |
connection_status => $result->{connection_status}, |
| 142 |
activated => $result->{activated} |
| 143 |
}; |
| 144 |
} |
| 145 |
|
| 146 |
return $results; |
| 147 |
} |
| 148 |
|
| 149 |
sub run { |
| 150 |
my ($self, %options) = @_; |
| 151 |
|
| 152 |
my $results = $self->manage_selection(snmp => $options{snmp}); |
| 153 |
foreach my $oid_path (sort keys %$results) { |
| 154 |
$self->{output}->output_add( |
| 155 |
long_msg => sprintf( |
| 156 |
'[oid_path: %s] [name: %s] [policy: %s] [description: %s] [connection_mode: %s] [connection_type: %s] [connection_status: %s] [activated: %s]', |
| 157 |
$oid_path, |
| 158 |
$results->{$oid_path}->{name}, |
| 159 |
$results->{$oid_path}->{policy}, |
| 160 |
$results->{$oid_path}->{description}, |
| 161 |
$results->{$oid_path}->{connection_mode}, |
| 162 |
$results->{$oid_path}->{connection_type}, |
| 163 |
$results->{$oid_path}->{connection_status}, |
| 164 |
$results->{$oid_path}->{activated} |
| 165 |
) |
| 166 |
); |
| 167 |
} |
| 168 |
|
| 169 |
$self->{output}->output_add( |
| 170 |
severity => 'OK', |
| 171 |
short_msg => 'List vpn' |
| 172 |
); |
| 173 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 174 |
$self->{output}->exit(); |
| 175 |
} |
| 176 |
|
| 177 |
sub disco_format { |
| 178 |
my ($self, %options) = @_; |
| 179 |
|
| 180 |
$self->{output}->add_disco_format(elements => |
| 181 |
[ 'name', 'policy', 'description', 'connection_mode', 'connection_type', 'connection_status', 'activated' ]); |
| 182 |
} |
| 183 |
|
| 184 |
sub disco_show { |
| 185 |
my ($self, %options) = @_; |
| 186 |
|
| 187 |
my $results = $self->manage_selection(snmp => $options{snmp}); |
| 188 |
foreach my $oid_path (sort keys %$results) { |
| 189 |
$self->{output}->add_disco_entry( |
| 190 |
name => |
| 191 |
$results->{$oid_path}->{name}, |
| 192 |
policy => |
| 193 |
$results->{$oid_path}->{policy}, |
| 194 |
description => |
| 195 |
$results->{$oid_path}->{description}, |
| 196 |
connection_mode => |
| 197 |
$results->{$oid_path}->{connection_mode}, |
| 198 |
connection_type => |
| 199 |
$results->{$oid_path}->{connection_type}, |
| 200 |
connection_status => |
| 201 |
$results->{$oid_path}->{connection_status}, |
| 202 |
activated => |
| 203 |
$results->{$oid_path}->{activated} |
| 204 |
); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
1; |
| 209 |
|
| 210 |
__END__ |
| 211 |
|
| 212 |
=head1 MODE |
| 213 |
|
| 214 |
List VPN. |
| 215 |
|
| 216 |
=over 8 |
| 217 |
|
| 218 |
=item B<--filter-name> |
| 219 |
|
| 220 |
Display VPN matching the filter. |
| 221 |
|
| 222 |
=item B<--filter-connection-status> |
| 223 |
|
| 224 |
Display VPN matching the filter. |
| 225 |
|
| 226 |
=item B<--filter-vpn-activated> |
| 227 |
|
| 228 |
Display VPN matching the filter. |
| 229 |
|
| 230 |
=back |
| 231 |
|
| 232 |
=cut |