| 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::cisco::meraki::cloudcontroller::restapi::mode::listvpntunnels; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
my @labels = ( |
| 29 |
'organization_id', |
| 30 |
'organization_name', |
| 31 |
'network_id', |
| 32 |
'network_name', |
| 33 |
'device_serial', |
| 34 |
'device_mode', |
| 35 |
'device_status', |
| 36 |
'vpn_type', |
| 37 |
'vpn_name', |
| 38 |
'vpn_status' |
| 39 |
); |
| 40 |
|
| 41 |
sub new { |
| 42 |
my ($class, %options) = @_; |
| 43 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 44 |
bless $self, $class; |
| 45 |
|
| 46 |
$options{options}->add_options(arguments => { |
| 47 |
'filter-network-id:s' => { name => 'filter_network_id' }, |
| 48 |
'filter-organization-name:s' => { name => 'filter_organization_name' }, |
| 49 |
'filter-organization-id:s' => { name => 'filter_organization_id' } |
| 50 |
}); |
| 51 |
|
| 52 |
return $self; |
| 53 |
} |
| 54 |
|
| 55 |
sub check_options { |
| 56 |
my ($self, %options) = @_; |
| 57 |
$self->SUPER::init(%options); |
| 58 |
} |
| 59 |
|
| 60 |
sub manage_selection { |
| 61 |
my ($self, %options) = @_; |
| 62 |
|
| 63 |
my $organizations = $options{custom}->get_organizations(); |
| 64 |
my $devices = $options{custom}->get_organization_vpn_tunnels_statuses( |
| 65 |
orgs => [keys %$organizations] |
| 66 |
); |
| 67 |
|
| 68 |
my $results = []; |
| 69 |
foreach my $id (keys %$devices) { |
| 70 |
next if (defined($self->{option_results}->{filter_network_id}) && $self->{option_results}->{filter_network_id} ne '' && |
| 71 |
$devices->{$id}->{networkId} !~ /$self->{option_results}->{filter_network_id}/); |
| 72 |
next if (defined($self->{option_results}->{filter_organization_id}) && $self->{option_results}->{filter_organization_id} ne '' && |
| 73 |
$devices->{$id}->{organizationId} !~ /$self->{option_results}->{filter_organization_id}/); |
| 74 |
|
| 75 |
my $organization_name = $organizations->{ $devices->{$id}->{organizationId} }->{name}; |
| 76 |
next if (defined($self->{option_results}->{filter_organization_name}) && $self->{option_results}->{filter_organization_name} ne '' && |
| 77 |
$organization_name !~ /$self->{option_results}->{filter_organization_name}/); |
| 78 |
|
| 79 |
foreach (@{$devices->{$id}->{merakiVpnPeers}}) { |
| 80 |
push @$results, { |
| 81 |
network_id => $devices->{$id}->{networkId}, |
| 82 |
network_name => $devices->{$id}->{networkName}, |
| 83 |
device_serial => $devices->{$id}->{deviceSerial}, |
| 84 |
organization_id => $devices->{$id}->{organizationId}, |
| 85 |
organization_name => $organization_name, |
| 86 |
device_mode => $devices->{$id}->{vpnMode}, |
| 87 |
device_status => $devices->{$id}->{deviceStatus}, |
| 88 |
vpn_type => 'meraki', |
| 89 |
vpn_name => $_->{networkName}, |
| 90 |
vpn_status => $_->{reachability} |
| 91 |
}; |
| 92 |
} |
| 93 |
|
| 94 |
foreach (@{$devices->{$id}->{thirdPartyVpnPeers}}) { |
| 95 |
push @$results, { |
| 96 |
network_id => $devices->{$id}->{networkId}, |
| 97 |
network_name => $devices->{$id}->{networkName}, |
| 98 |
device_serial => $devices->{$id}->{deviceSerial}, |
| 99 |
organization_id => $devices->{$id}->{organizationId}, |
| 100 |
organization_name => $organization_name, |
| 101 |
device_mode => $devices->{$id}->{vpnMode}, |
| 102 |
device_status => $devices->{$id}->{deviceStatus}, |
| 103 |
vpn_type => 'thirdParty', |
| 104 |
vpn_name => $_->{name}, |
| 105 |
vpn_status => $_->{reachability} |
| 106 |
}; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
return $results; |
| 111 |
} |
| 112 |
|
| 113 |
sub run { |
| 114 |
my ($self, %options) = @_; |
| 115 |
|
| 116 |
my $results = $self->manage_selection(custom => $options{custom}); |
| 117 |
foreach my $item (@$results) { |
| 118 |
$self->{output}->output_add(long_msg => |
| 119 |
join('', map("[$_: " . $item->{$_} . ']', @labels)) |
| 120 |
); |
| 121 |
} |
| 122 |
|
| 123 |
$self->{output}->output_add( |
| 124 |
severity => 'OK', |
| 125 |
short_msg => 'List VPN tunnels:' |
| 126 |
); |
| 127 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 128 |
$self->{output}->exit(); |
| 129 |
} |
| 130 |
|
| 131 |
sub disco_format { |
| 132 |
my ($self, %options) = @_; |
| 133 |
|
| 134 |
$self->{output}->add_disco_format(elements => [@labels]); |
| 135 |
} |
| 136 |
|
| 137 |
sub disco_show { |
| 138 |
my ($self, %options) = @_; |
| 139 |
|
| 140 |
my $results = $self->manage_selection(custom => $options{custom}); |
| 141 |
foreach my $item (@$results) { |
| 142 |
$self->{output}->add_disco_entry( |
| 143 |
%$item |
| 144 |
); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
1; |
| 149 |
|
| 150 |
__END__ |
| 151 |
|
| 152 |
=head1 MODE |
| 153 |
|
| 154 |
List VPN tunnels. |
| 155 |
|
| 156 |
=over 8 |
| 157 |
|
| 158 |
=item B<--filter-network-id> |
| 159 |
|
| 160 |
Filter VPN tunnels by network ID (can be a regexp). |
| 161 |
|
| 162 |
=item B<--filter-organization-id> |
| 163 |
|
| 164 |
Filter VPN tunnels by organization ID (can be a regexp). |
| 165 |
|
| 166 |
=item B<--filter-organization-name> |
| 167 |
|
| 168 |
Filter VPN tunnels by organization name (can be a regexp). |
| 169 |
|
| 170 |
=back |
| 171 |
|
| 172 |
=cut |