diff --git a/network/cisco/wap/snmp/mode/clients.pm b/network/cisco/wap/snmp/mode/clients.pm new file mode 100644 index 000000000..174349993 --- /dev/null +++ b/network/cisco/wap/snmp/mode/clients.pm @@ -0,0 +1,152 @@ +# +# Copyright 2021 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::cisco::wap::snmp::mode::clients; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_radio_output { + my ($self, %options) = @_; + + return sprintf( + "Radio interface '%s' ", + $options{instance_value}->{name} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'radios', type => 1, cb_prefix_output => 'prefix_radio_output' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'clients-connected', nlabel => 'clients.connected.count', set => { + key_values => [ { name => 'clients_connected' } ], + output_template => 'clients connected: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{radios} = [ + { label => 'radio-clients-connected', nlabel => 'radio.clients.connected.count', set => { + key_values => [ { name => 'clients_connected' } ], + output_template => 'clients connected: %s', + perfdatas => [ + { template => '%s', min => 0, label_extra_instance => 1 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-radio-name:s' => { name => 'filter_radio_name' } + }); + + return $self; +} + +my $map_status = { 0 => 'down', 1 => 'up' }; + +my $mapping_radio = { + admin_status => { oid => '.1.3.6.1.4.1.9.6.1.104.1.6.1.1.2', map => $map_status }, # apRadioStatus + name => { oid => '.1.3.6.1.4.1.9.6.1.104.1.6.1.1.3' } # apRadioName +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_radio_table = '.1.3.6.1.4.1.9.6.1.104.1.6.1'; # apRadioTable + my $oid_assoc_interface = '.1.3.6.1.4.1.9.6.1.104.1.7.1.1.2'; # apAssocInterface + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_radio_table, start => $mapping_radio->{admin_status}->{oid}, end => $mapping_radio->{name}->{oid} }, + { oid => $oid_assoc_interface } + ], + nothing_quit => 1 + ); + + $self->{global} = { clients_connected => 0 }; + $self->{radios} = {}; + foreach (keys %{$snmp_result->{$oid_radio_table}}) { + next if (! /^$mapping_radio->{name}->{oid}\.(.*)$/); + + my $result = $options{snmp}->map_instance(mapping => $mapping_radio, results => $snmp_result->{$oid_radio_table}, instance => $1); + next if ($result->{admin_status} eq 'down'); + if (defined($self->{option_results}->{filter_radio_name}) && $self->{option_results}->{filter_radio_name} ne '' && + $result->{name} !~ /$self->{option_results}->{filter_radio_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{radios}->{ $result->{name} } = { + name => $result->{name}, + clients_connected => 0 + }; + } + + foreach (keys %{$snmp_result->{$oid_assoc_interface}}) { + next if (!defined($self->{radios}->{ $snmp_result->{$oid_assoc_interface}->{$_} })); + $self->{radios}->{ $snmp_result->{$oid_assoc_interface}->{$_} }->{clients_connected}++; + $self->{global}->{clients_connected}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check clients connected. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^clients' + +=item B<--filter-radio-name> + +Filter radio interfaces by name (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'clients-connected', 'radio-clients-connected'. + +=back + +=cut diff --git a/network/cisco/wap/snmp/mode/cpu.pm b/network/cisco/wap/snmp/mode/cpu.pm new file mode 100644 index 000000000..7b7a6965d --- /dev/null +++ b/network/cisco/wap/snmp/mode/cpu.pm @@ -0,0 +1,91 @@ +# +# Copyright 2021 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::cisco::wap::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu', type => 0 } + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'cpu-utilization', nlabel => 'cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_usage' } ], + output_template => 'Cpu usage is: %.2f%%', + perfdatas => [ + { template => '%.2f', unit => '%', min => 0, max => 100 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_cpu_usage = '.1.3.6.1.4.1.9.6.1.104.1.23.1.0'; # apUtilizationCPU = 9% + my $snmp_result = $options{snmp}->get_leef( + oids => [ $oid_cpu_usage ], + nothing_quit => 1 + ); + + $snmp_result->{$oid_cpu_usage} = $1 if ($snmp_result->{$oid_cpu_usage} =~ /([0-9\.]+)/); + $self->{cpu} = { cpu_usage => $snmp_result->{$oid_cpu_usage} }; +} + +1; + +__END__ + +=head1 MODE + +Check cpu usage. + +=over 8 + +=item B<--warning-cpu-utilization> + +Threshold warning in percent. + +=item B<--critical-cpu-utilization> + +Threshold critical in percent. + +=back + +=cut diff --git a/network/cisco/wap/snmp/mode/memory.pm b/network/cisco/wap/snmp/mode/memory.pm new file mode 100644 index 000000000..2905c6a4c --- /dev/null +++ b/network/cisco/wap/snmp/mode/memory.pm @@ -0,0 +1,87 @@ +# +# Copyright 2021 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::cisco::wap::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 0, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage-prct', nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Memory used: %.2f %%', + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_prct_used = '.1.3.6.1.4.1.9.6.1.104.1.23.2.0'; # apUtilizationMem = 46.77% + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_prct_used], nothing_quit => 1); + + $snmp_result->{$oid_prct_used} = $1 if ($snmp_result->{$oid_prct_used} =~ /([0-9\.]+)/); + $self->{memory} = { + prct_used => $snmp_result->{$oid_prct_used} + } +} + +1; + +__END__ + +=head1 MODE + +Check memory usage. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage-prct' (%). + +=back + +=cut diff --git a/network/cisco/wap/snmp/mode/virtualaccesspoints.pm b/network/cisco/wap/snmp/mode/virtualaccesspoints.pm new file mode 100644 index 000000000..bb7cf69a6 --- /dev/null +++ b/network/cisco/wap/snmp/mode/virtualaccesspoints.pm @@ -0,0 +1,187 @@ +# +# Copyright 2021 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::cisco::wap::snmp::mode::virtualaccesspoints; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'operational status: %s [admin: %s]', + $self->{result_values}->{operational_status}, + $self->{result_values}->{admin_status} + ); +} + +sub prefix_vap_output { + my ($self, %options) = @_; + + return sprintf( + "Virtual access point '%s' ", + $options{instance_value}->{description} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'vaps', type => 1, cb_prefix_output => 'prefix_vap_output', message_multiple => 'All virtual access points are ok' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'virtual_access_points.total.count', display_ok => 0, set => { + key_values => [ { name => 'total' } ], + output_template => 'total: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{vaps} = [ + { + label => 'status', type => 2, critical_default => '%{admin_status} eq "up" and %{operational_status} eq "down"', + set => { + key_values => [ + { name => 'description' }, { name => 'admin_status' }, + { name => 'operational_status' } + ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-description:s' => { name => 'filter_description' } + }); + + return $self; +} + +my $map_status = { 0 => 'down', 1 => 'up' }; + +my $mapping = { + admin_status => { oid => '.1.3.6.1.4.1.9.6.1.104.1.4.1.1.3', map => $map_status }, # apVapStatus + operational_status => { oid => '.1.3.6.1.4.1.9.6.1.104.1.4.1.1.14', map => $map_status }, # apVapOperationalStatus +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_description = '.1.3.6.1.4.1.9.6.1.104.1.4.1.1.5'; # apVapDescription + my $snmp_result = $options{snmp}->get_table( + oid => $oid_description, + nothing_quit => 1 + ); + + $self->{vaps} = {}; + foreach (keys %$snmp_result) { + /^$oid_description\.(.*)$/; + my $instance = $1; + + if (defined($self->{option_results}->{filter_description}) && $self->{option_results}->{filter_description} ne '' && + $snmp_result->{$_} !~ /$self->{option_results}->{filter_description}/) { + $self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$_} . "': no matching filter.", debug => 1); + next; + } + + $self->{vaps}->{$instance} = { + description => $snmp_result->{$_} + }; + } + + $self->{global} = { total => scalar(keys %{$self->{vaps}}) }; + + return if (scalar(keys %{$self->{vaps}}) <= 0); + + $options{snmp}->load(oids => [ + map($_->{oid}, values(%$mapping)) + ], + instances => [keys %{$self->{vaps}}], + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{vaps}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + $self->{vaps}->{$_} = { %{$self->{vaps}->{$_}}, %$result }; + } +} + +1; + +__END__ + +=head1 MODE + +Check virtual access points. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--filter-description> + +Filter virtual access points by description (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{description}, %{admin_status}, %{operational_status} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{description}, %{admin_status}, %{operational_status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admin_status} eq "up" and %{operational_status} eq "down"'). +Can used special variables like: %{description}, %{admin_status}, %{operational_status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total'. + +=back + +=cut diff --git a/network/cisco/wap/snmp/plugin.pm b/network/cisco/wap/snmp/plugin.pm new file mode 100644 index 000000000..2c593ed17 --- /dev/null +++ b/network/cisco/wap/snmp/plugin.pm @@ -0,0 +1,54 @@ +# +# Copyright 2021 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::cisco::wap::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $self->{modes} = { + 'clients' => 'network::cisco::wap::snmp::mode::clients', + 'cpu' => 'network::cisco::wap::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::cisco::wap::snmp::mode::memory', + 'uptime' => 'snmp_standard::mode::uptime', + 'virtual-access-points' => 'network::cisco::wap::snmp::mode::virtualaccesspoints' + }; + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Cisco Wireless Access Point (WAP) in SNMP. + +=cut