From 053854e1c13429aea705398006f7cce1557b4b57 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut <123162035+lucie-dubrunfaut@users.noreply.github.com> Date: Tue, 30 May 2023 09:23:41 +0200 Subject: [PATCH] add cambium cnpilot series plugin (#4418) --- .../cnpilot/snmp/mode/connectionstatus.pm | 142 +++++++++++++ src/network/cambium/cnpilot/snmp/mode/cpu.pm | 129 ++++++++++++ .../cambium/cnpilot/snmp/mode/interfaces.pm | 182 ++++++++++++++++ .../cambium/cnpilot/snmp/mode/listradios.pm | 140 +++++++++++++ .../cambium/cnpilot/snmp/mode/memory.pm | 139 ++++++++++++ .../cambium/cnpilot/snmp/mode/radios.pm | 198 ++++++++++++++++++ src/network/cambium/cnpilot/snmp/plugin.pm | 52 +++++ 7 files changed, 982 insertions(+) create mode 100644 src/network/cambium/cnpilot/snmp/mode/connectionstatus.pm create mode 100644 src/network/cambium/cnpilot/snmp/mode/cpu.pm create mode 100644 src/network/cambium/cnpilot/snmp/mode/interfaces.pm create mode 100644 src/network/cambium/cnpilot/snmp/mode/listradios.pm create mode 100644 src/network/cambium/cnpilot/snmp/mode/memory.pm create mode 100644 src/network/cambium/cnpilot/snmp/mode/radios.pm create mode 100644 src/network/cambium/cnpilot/snmp/plugin.pm diff --git a/src/network/cambium/cnpilot/snmp/mode/connectionstatus.pm b/src/network/cambium/cnpilot/snmp/mode/connectionstatus.pm new file mode 100644 index 000000000..4bc496c3f --- /dev/null +++ b/src/network/cambium/cnpilot/snmp/mode/connectionstatus.pm @@ -0,0 +1,142 @@ +# +# Copyright 2023 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::cambium::cnpilot::snmp::mode::connectionstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub prefix_connection_output { + my ($self, %options) = @_; + + return "Access point '" . $options{instance_value}->{name} . "' "; +} + +sub custom_connection_output { + my ($self, %options) = @_; + + return sprintf( + 'connection status: %s', + $self->{result_values}->{connection_status} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'connection', type => 1, cb_prefix_output => 'prefix_connection_output', message_multiple => 'All connection status are ok' } + ]; + + $self->{maps_counters}->{connection} = [ + { label => 'connection-status', type => 2, + set => { + key_values => [ { name => 'connection_status' }, { name => 'name' } ], + closure_custom_output => $self->can('custom_connection_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-ap:s' => { name => 'filter_ap' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $mapping = { + cambiumAPName => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.2' }, + cambiumAPCnmConstaus => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.12' } + }; + + # Point at the begining of the table + my $oid_cambiumAccessPointEntry = '.1.3.6.1.4.1.17713.22.1.1.1'; + + my $connectionstatus_result = $options{snmp}->get_table( + oid => $oid_cambiumAccessPointEntry, + nothing_quit => 1 + ); + + $self->{connection} = {}; + foreach my $oid (keys %{$connectionstatus_result}) { + next if ($oid !~ /^$mapping->{cambiumAPName}->{oid}\.(.*)$/); + # Catch instance in table + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $connectionstatus_result, instance => $instance); + + if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' && + $result->{cambiumAPName} !~ /$self->{option_results}->{filter_ap}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{cambiumAPName} . "': no matching filter.", debug => 1); + next; + } + + $self->{connection}->{$instance} = { + name => $result->{cambiumAPName}, + connection_status => $result->{cambiumAPCnmConstaus} + }; + + } + + if (scalar(keys %{$self->{connection}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No AP matching with filter found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Connection status. + +=over 8 + +=item B<--filter-ap> + +Filter on one or several AP. + +=item B<--warning-connection-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{name} + +=item B<--critical-connection-status> + +Set critical threshold for status. +Can used special variables like: %{status}, %{name} + +=back + +=cut diff --git a/src/network/cambium/cnpilot/snmp/mode/cpu.pm b/src/network/cambium/cnpilot/snmp/mode/cpu.pm new file mode 100644 index 000000000..d9b01f2ba --- /dev/null +++ b/src/network/cambium/cnpilot/snmp/mode/cpu.pm @@ -0,0 +1,129 @@ +# +# Copyright 2023 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::cambium::cnpilot::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "CPU '" . $options{instance_value}->{name} . "' usage: "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok' } + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'cpu-usage-prct', nlabel => 'cpu.usage.percentage', set => { + key_values => [ { name => 'cpu_usage' }, { name => 'name' } ], + output_template => '%.2f %%', + perfdatas => [ + { label => 'cpu', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name' } + ] + } + } + ]; +} + +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-ap:s' => { name => 'filter_ap' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # Select relevant oids for CPU monitoring + my $mapping = { + cambiumAPName => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.2' }, + cambiumAPCPUUtilization => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.6' } + }; + + # Point at the begining of the table + my $oid_cambiumAccessPointEntry = '.1.3.6.1.4.1.17713.22.1.1.1'; + + my $cpu_result = $options{snmp}->get_table( + oid => $oid_cambiumAccessPointEntry, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$cpu_result}) { + next if ($oid !~ /^$mapping->{cambiumAPName}->{oid}\.(.*)$/); + # Catch instance in table + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $cpu_result, instance => $instance); + + if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' && + $result->{cambiumAPName} !~ /$self->{option_results}->{filter_ap}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{cambiumAPName} . "': no matching filter.", debug => 1); + next; + } + + $self->{cpu}->{$instance} = { + name => $result->{cambiumAPName}, + cpu_usage => $result->{cambiumAPCPUUtilization} + }; + } + + if (scalar(keys %{$self->{cpu}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No AP matching with filter found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check CPU usage. + +=over 8 + +=item B<--filter-ap> + +Filter on one AP name. + +=item B<--warning> + +Warning threshold for CPU. + +=item B<--critical> + +Critical threshold for CPU. + +=back + +=cut diff --git a/src/network/cambium/cnpilot/snmp/mode/interfaces.pm b/src/network/cambium/cnpilot/snmp/mode/interfaces.pm new file mode 100644 index 000000000..377c78007 --- /dev/null +++ b/src/network/cambium/cnpilot/snmp/mode/interfaces.pm @@ -0,0 +1,182 @@ +# +# Copyright 2023 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::cambium::cnpilot::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-global> + +Check global port statistics (By default if no --add-* option is set). + +=item B<--add-status> + +Check interface status. + +=item B<--add-duplex-status> + +Check duplex status (with --warning-status and --critical-status). + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-errors> + +Check interface errors. + +=item B<--add-cast> + +Check interface cast. + +=item B<--add-speed> + +Check interface speed. + +=item B<--add-volume> + +Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). + +=item B<--check-metrics> + +If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"'). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast', +'speed' (b/s). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--nagvis-perfdata> + +Display traffic perfdata to be compatible with nagvis widget. + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--map-speed-dsl> + +Get interface speed configuration for interface type 'adsl' and 'vdsl2'. + +Syntax: --map-speed-dsl=interface-src-name,interface-dsl-name + +E.g: --map-speed-dsl=Et0.835,Et0-vdsl2 + +=item B<--force-counters64> + +Force to use 64 bits counters only. Can be used to improve performance. + +=item B<--force-counters32> + +Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> + +Regexp src to transform display value. + +=item B<--display-transform-dst> + +Regexp dst to transform display value. + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/src/network/cambium/cnpilot/snmp/mode/listradios.pm b/src/network/cambium/cnpilot/snmp/mode/listradios.pm new file mode 100644 index 000000000..23042cf7d --- /dev/null +++ b/src/network/cambium/cnpilot/snmp/mode/listradios.pm @@ -0,0 +1,140 @@ +# +# Copyright 2023 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::cambium::cnpilot::snmp::mode::listradios; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + # Select relevant oids for discovery function for Radio CnPilot + my $mapping = { + cambiumRadioIndex => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.1' }, + cambiumRadioMACAddress => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.2' }, + cambiumBandType => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.3' }, + cambiumRadioState => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.13' }, + cambiumRadioChannel => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.6' } + }; + + # Point at the begining of the table + my $oid_cambiumRadioEntry = '.1.3.6.1.4.1.17713.22.1.2.1'; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_cambiumRadioEntry, + nothing_quit => 1 + ); + + my $results = {}; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{cambiumRadioMACAddress}->{oid}\.(.*)$/); + # Catch instance in table + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $results->{$result->{cambiumRadioMACAddress}} = { + id => $result->{cambiumRadioIndex}, + name => $result->{cambiumRadioMACAddress}, + band_type => $result->{cambiumBandType}, + transmit_power => $result->{cambiumRadioState}, + radio_channel => $result->{cambiumRadioChannel} + }; + } + + return $results; +} + +sub run { + my ($self, %options) = @_; + + my $results = $self->manage_selection(snmp => $options{snmp}); + foreach my $oid_path (sort keys %$results) { + $self->{output}->output_add( + long_msg => sprintf( + '[id: %s][name: %s][radio channel: %s][transmit power: %s][band type: %s]', + $results->{$oid_path}->{id}, + $results->{$oid_path}->{name}, + $results->{$oid_path}->{radio_channel}, + $results->{$oid_path}->{transmit_power}, + $results->{$oid_path}->{band_type} + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List Radio' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['id', 'name', 'radio_channel', 'transmit_power', 'band_type']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $results = $self->manage_selection(snmp => $options{snmp}); + foreach my $oid_path (sort keys %$results) { + $self->{output}->add_disco_entry( + id => $results->{$oid_path}->{id}, + name => $results->{$oid_path}->{name}, + radio_channel => $results->{$oid_path}->{radio_channel}, + transmit_power => $results->{$oid_path}->{transmit_power}, + band_type => $results->{$oid_path}->{band_type} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List radio interfaces. + +=over 8 + +=back + +=cut diff --git a/src/network/cambium/cnpilot/snmp/mode/memory.pm b/src/network/cambium/cnpilot/snmp/mode/memory.pm new file mode 100644 index 000000000..9bcb7bd4e --- /dev/null +++ b/src/network/cambium/cnpilot/snmp/mode/memory.pm @@ -0,0 +1,139 @@ +# +# Copyright 2023 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::cambium::cnpilot::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_memory_output { + my ($self, %options) = @_; + + return "Memory '" . $options{instance_value}->{name} . "' "; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'used: %.2f %%', + $self->{result_values}->{used} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memories are ok' } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'memory-usage-prct', nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'name' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name'} + ] + } + } + ]; +} + +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-ap:s' => { name => 'filter_ap' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # Select relevant oids for Memory monitoring + my $mapping = { + cambiumAPName => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.2' }, + cambiumAPMemoryFree => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.7' } + }; + + # Point at the begining of the table + my $oid_cambiumAccessPointEntry = '.1.3.6.1.4.1.17713.22.1.1.1'; + + my $memory_result = $options{snmp}->get_table( + oid => $oid_cambiumAccessPointEntry, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$memory_result}) { + next if ($oid !~ /^$mapping->{cambiumAPName}->{oid}\.(.*)$/); + # Catch instance in table + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $memory_result, instance => $instance); + + if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' && + $result->{cambiumAPName} !~ /$self->{option_results}->{filter_ap}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{cambiumAPName} . "': no matching filter.", debug => 1); + next; + } + + $self->{memory}->{$instance} = { + name => $result->{cambiumAPName}, + free => $result->{cambiumAPMemoryFree}, + used => 100 - $result->{cambiumAPMemoryFree} + }; + } + + if (scalar(keys %{$self->{memory}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No AP matching with filter found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check memory usage. + +=over 8 + +=item B<--filter-ap> + +Filter on one or several AP. + +=item B<--warning> + +Warning threshold for Memory. + +=item B<--critical> + +Critical threshold for Memory. + +=back + +=cut diff --git a/src/network/cambium/cnpilot/snmp/mode/radios.pm b/src/network/cambium/cnpilot/snmp/mode/radios.pm new file mode 100644 index 000000000..ffea2e933 --- /dev/null +++ b/src/network/cambium/cnpilot/snmp/mode/radios.pm @@ -0,0 +1,198 @@ +# +# Copyright 2023 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::cambium::cnpilot::snmp::mode::radios; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use Digest::MD5 qw(md5_hex); + +sub prefix_radio_output { + my ($self, %options) = @_; + + return "radio interface '" . $options{instance_value}->{name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'radios', type => 1, cb_prefix_output => 'prefix_radio_output', message_multiple => 'All raadio interfaces are ok' } + ]; + + $self->{maps_counters}->{radios} = [ + { label => 'clients-connected', nlabel => 'radio.clients.connected.count', set => { + key_values => [ { name => 'num_clients' }, { name => 'name' } ], + output_template => 'clients connected: %s', + perfdatas => [ + { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'name' } + ] + } + }, + { label => 'status', type => 2, critical_default => '%{state} eq "off"', + set => { + key_values => [ { name => 'state' }, { name => 'name' } ], + output_template => 'state: %s', + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + }, + { label => 'noise-floor', nlabel => 'radio.interface.noise.floor.dbm', set => { + key_values => [ { name => 'noise_floor' } ], + output_template => 'noise floor: %s dBm', + perfdatas => [ + { template => '%s', min => 0, unit => 'dBm', label_extra_instance => 1, instance_use => 'name' } + ] + } + }, + { label => 'interference', nlabel => 'radio.interface.interference.dbm', set => { + key_values => [ { name => 'interference' } ], + output_template => 'interference: %s dBm', + perfdatas => [ + { template => '%s', min => 0, unit => 'dBm', label_extra_instance => 1, instance_use => 'name' } + ] + } + }, + { label => 'traffic-in', nlabel => 'radio.interface.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', per_second => 1 } ], + output_template => 'in: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name' } + ] + } + }, + { label => 'traffic-out', nlabel => 'radio.interface.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', per_second => 1 } ], + output_template => 'out: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name' } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # Select relevant oids for radio monitoring + my $mapping = { + cambiumRadioMACAddress => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.2' }, + cambiumRadioNumClients => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.5' }, + cambiumRadioTxDataBytes => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.9' }, + cambiumRadioRxDataBytes => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.10' }, + cambiumRadioState => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.13' }, + cambiumRadioNoiseFloor => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.16' }, + cambiumRadioInterference => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.17' } + }; + + # Point at the begining of the table + my $oid_cambiumRadioPointEntry = '.1.3.6.1.4.1.17713.22.1.2.1'; + + my $radio_result = $options{snmp}->get_table( + oid => $oid_cambiumRadioPointEntry, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$radio_result}) { + next if ($oid !~ /^$mapping->{cambiumRadioMACAddress}->{oid}\.(.*)$/); + # Catch instance in table + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $radio_result, instance => $instance); + + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{cambiumRadioMACAddress} !~ /$self->{option_results}->{filter_name}/); + + $self->{radios}->{$instance} = { + name => $result->{cambiumRadioMACAddress}, + num_clients => $result->{cambiumRadioNumClients}, + state => lc($result->{cambiumRadioState}), + traffic_out => $result->{cambiumRadioTxDataBytes} * 8, + traffic_in => $result->{cambiumRadioRxDataBytes} * 8, + noise_floor => $result->{cambiumRadioNoiseFloor}, + interference => $result->{cambiumRadioInterference} + }; + } + + if (scalar(keys %{$self->{radios}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No MACAddress matching with filter found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = 'cambium_cnpilot_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + md5_hex( + (defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '') . '_' . + (defined($self->{option_results}->{filter_name}) ? $self->{option_results}->{filter_name} : '') + ); +} + +1; + +__END__ + +=head1 MODE + +Check radio interfaces. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--filter-name> + +Filter interface by MACAdress + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{name} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} eq "expired"'). +Can used special variables like: %{status}, %{name} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'clients-connected', 'noise-floor', 'interference', 'traffic-in', 'traffic-out'. + +=back + +=cut diff --git a/src/network/cambium/cnpilot/snmp/plugin.pm b/src/network/cambium/cnpilot/snmp/plugin.pm new file mode 100644 index 000000000..326b2f56f --- /dev/null +++ b/src/network/cambium/cnpilot/snmp/plugin.pm @@ -0,0 +1,52 @@ +# +# Copyright 2023 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::cambium::cnpilot::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->{modes} = { + 'connection-status' => 'network::cambium::cnpilot::snmp::mode::connectionstatus', + 'cpu' => 'network::cambium::cnpilot::snmp::mode::cpu', + 'interfaces' => 'network::cambium::cnpilot::snmp::mode::interfaces', + 'list-radios' => 'network::cambium::cnpilot::snmp::mode::listradios', + 'memory' => 'network::cambium::cnpilot::snmp::mode::memory', + 'radios' => 'network::cambium::cnpilot::snmp::mode::radios' + }; + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Cambium cnPilot equipments through SNMP. + +=cut