| 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::networks; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
|
| 29 |
sub prefix_network_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return "Network '" . $options{instance_value}->{display} . "' "; |
| 33 |
} |
| 34 |
|
| 35 |
sub set_counters { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
$self->{maps_counters_type} = [ |
| 39 |
{ name => 'networks', type => 1, cb_prefix_output => 'prefix_network_output', message_multiple => 'All networks are ok' } |
| 40 |
]; |
| 41 |
|
| 42 |
$self->{maps_counters}->{networks} = [ |
| 43 |
{ label => 'connections-success', nlabel => 'network.connections.success.count', set => { |
| 44 |
key_values => [ { name => 'assoc' }, { name => 'display' } ], |
| 45 |
output_template => 'connections success: %s', |
| 46 |
perfdatas => [ |
| 47 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 48 |
] |
| 49 |
} |
| 50 |
}, |
| 51 |
{ label => 'connections-auth', nlabel => 'network.connections.auth.count', display_ok => 0, set => { |
| 52 |
key_values => [ { name => 'auth' }, { name => 'display' } ], |
| 53 |
output_template => 'connections auth: %s', |
| 54 |
perfdatas => [ |
| 55 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 56 |
] |
| 57 |
} |
| 58 |
}, |
| 59 |
{ label => 'connections-assoc', nlabel => 'network.connections.assoc.count', display_ok => 0, set => { |
| 60 |
key_values => [ { name => 'assoc' }, { name => 'display' } ], |
| 61 |
output_template => 'connections assoc: %s', |
| 62 |
perfdatas => [ |
| 63 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 64 |
] |
| 65 |
} |
| 66 |
}, |
| 67 |
{ label => 'connections-dhcp', nlabel => 'network.connections.dhcp.count', display_ok => 0, set => { |
| 68 |
key_values => [ { name => 'dhcp' }, { name => 'display' } ], |
| 69 |
output_template => 'connections dhcp: %s', |
| 70 |
perfdatas => [ |
| 71 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 72 |
] |
| 73 |
} |
| 74 |
}, |
| 75 |
{ label => 'connections-dns', nlabel => 'network.connections.dns.count', display_ok => 0, set => { |
| 76 |
key_values => [ { name => 'dns' }, { name => 'display' } ], |
| 77 |
output_template => 'connections dns: %s', |
| 78 |
perfdatas => [ |
| 79 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 80 |
] |
| 81 |
} |
| 82 |
}, |
| 83 |
{ label => 'traffic-in', nlabel => 'network.traffic.in.bitspersecond', set => { |
| 84 |
key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ], |
| 85 |
output_template => 'traffic in: %s %s/s', |
| 86 |
output_change_bytes => 2, |
| 87 |
perfdatas => [ |
| 88 |
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } |
| 89 |
] |
| 90 |
} |
| 91 |
}, |
| 92 |
{ label => 'traffic-out', nlabel => 'network.traffic.out.bitspersecond', set => { |
| 93 |
key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ], |
| 94 |
output_template => 'traffic out: %s %s/s', |
| 95 |
output_change_bytes => 2, |
| 96 |
perfdatas => [ |
| 97 |
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } |
| 98 |
] |
| 99 |
} |
| 100 |
} |
| 101 |
]; |
| 102 |
} |
| 103 |
|
| 104 |
sub new { |
| 105 |
my ($class, %options) = @_; |
| 106 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 107 |
bless $self, $class; |
| 108 |
|
| 109 |
$options{options}->add_options(arguments => { |
| 110 |
'filter-network-name:s' => { name => 'filter_network_name' }, |
| 111 |
'filter-organization-name:s' => { name => 'filter_organization_name' }, |
| 112 |
'filter-organization-id:s' => { name => 'filter_organization_id' } |
| 113 |
}); |
| 114 |
|
| 115 |
return $self; |
| 116 |
} |
| 117 |
|
| 118 |
sub manage_selection { |
| 119 |
my ($self, %options) = @_; |
| 120 |
|
| 121 |
$self->{cache_name} = 'meraki_' . $self->{mode} . '_' . $options{custom}->get_token() . '_' . |
| 122 |
md5_hex( |
| 123 |
(defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : 'all') . '_' . |
| 124 |
(defined($self->{option_results}->{filter_network_name}) ? $self->{option_results}->{filter_network_name} : 'all') . '_' . |
| 125 |
(defined($self->{option_results}->{filter_organization_id}) ? $self->{option_results}->{filter_organization_id} : 'all') . '_' . |
| 126 |
(defined($self->{option_results}->{filter_organization_name}) ? $self->{option_results}->{filter_organization_name} : 'all') |
| 127 |
); |
| 128 |
|
| 129 |
my $datas = $options{custom}->get_datas(skipDevices => 1, skipDevicesStatus => 1, skipVpnTunnelsStatus => 1); |
| 130 |
|
| 131 |
$self->{networks} = {}; |
| 132 |
foreach my $id (keys %{$datas->{networks}}) { |
| 133 |
next if (defined($self->{option_results}->{filter_network_name}) && $self->{option_results}->{filter_network_name} ne '' && |
| 134 |
$datas->{networks}->{$id}->{name} !~ /$self->{option_results}->{filter_network_name}/); |
| 135 |
|
| 136 |
next if (defined($self->{option_results}->{filter_organization_id}) && $self->{option_results}->{filter_organization_id} ne '' && |
| 137 |
$datas->{networks}->{$id}->{organizationId} !~ /$self->{option_results}->{filter_organization_id}/); |
| 138 |
next if (defined($self->{option_results}->{filter_organization_name}) && $self->{option_results}->{filter_organization_name} ne '' && |
| 139 |
$datas->{orgs}->{ $datas->{networks}->{$id}->{organizationId} }->{name} !~ /$self->{option_results}->{filter_organization_name}/); |
| 140 |
|
| 141 |
my $connections = $options{custom}->get_networks_connection_stats(network_id => $id); |
| 142 |
my $clients = $options{custom}->get_networks_clients(network_id => $id); |
| 143 |
|
| 144 |
$self->{networks}->{$id} = { |
| 145 |
display => $datas->{networks}->{$id}->{name}, |
| 146 |
assoc => defined($connections->{assoc}) ? $connections->{assoc} : 0, |
| 147 |
auth => defined($connections->{auth}) ? $connections->{auth} : 0, |
| 148 |
dhcp => defined($connections->{dhcp}) ? $connections->{dhcp} : 0, |
| 149 |
dns => defined($connections->{dns}) ? $connections->{dns} : 0, |
| 150 |
success => defined($connections->{success}) ? $connections->{success} : 0, |
| 151 |
traffic_in => 0, traffic_out => 0 |
| 152 |
}; |
| 153 |
|
| 154 |
if (defined($clients)) { |
| 155 |
foreach my $client (@$clients) { |
| 156 |
$self->{networks}->{$id}->{traffic_in} += $client->{usage}->{recv} * 8; |
| 157 |
$self->{networks}->{$id}->{traffic_out} += $client->{usage}->{sent} * 8; |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
if (scalar(keys %{$self->{networks}}) <= 0) { |
| 163 |
$self->{output}->add_option_msg(short_msg => 'No networks found.'); |
| 164 |
$self->{output}->option_exit(); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
1; |
| 169 |
|
| 170 |
__END__ |
| 171 |
|
| 172 |
=head1 MODE |
| 173 |
|
| 174 |
Check networks. |
| 175 |
|
| 176 |
=over 8 |
| 177 |
|
| 178 |
=item B<--filter-network-name> |
| 179 |
|
| 180 |
Filter network name (can be a regexp). |
| 181 |
|
| 182 |
=item B<--filter-organization-id> |
| 183 |
|
| 184 |
Filter networks by organization ID (can be a regexp). |
| 185 |
|
| 186 |
=item B<--filter-organization-name> |
| 187 |
|
| 188 |
Filter networks by organization name (can be a regexp). |
| 189 |
|
| 190 |
=item B<--warning-*> B<--critical-*> |
| 191 |
|
| 192 |
Thresholds. |
| 193 |
Can be: 'connections-success', 'connections-auth', 'connections-assoc', |
| 194 |
'connections-dhcp', 'connections-dns', 'traffic-in', 'traffic-out'. |
| 195 |
|
| 196 |
=back |
| 197 |
|
| 198 |
=cut |