From 72a44823757bbb0605a873d3f7f194340447807e Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 31 May 2022 09:29:04 +0200 Subject: [PATCH] (plugin) network::libraesva::snmp - metrics v2 (#3697) --- .../network/libraesva/snmp/mode/interfaces.pm | 182 ++++++++++++++++++ .../network/libraesva/snmp/mode/load.pm | 60 ++++++ .../network/libraesva/snmp/mode/memory.pm | 67 +++++++ .../network/libraesva/snmp/mode/storage.pm | 132 +++++++++++++ .../network/libraesva/snmp/mode/swap.pm | 57 ++++++ .../network/libraesva/snmp/mode/system.pm | 60 +++--- .../network/libraesva/snmp/plugin.pm | 15 +- 7 files changed, 529 insertions(+), 44 deletions(-) create mode 100644 centreon-plugins/network/libraesva/snmp/mode/interfaces.pm create mode 100644 centreon-plugins/network/libraesva/snmp/mode/load.pm create mode 100644 centreon-plugins/network/libraesva/snmp/mode/memory.pm create mode 100644 centreon-plugins/network/libraesva/snmp/mode/storage.pm create mode 100644 centreon-plugins/network/libraesva/snmp/mode/swap.pm diff --git a/centreon-plugins/network/libraesva/snmp/mode/interfaces.pm b/centreon-plugins/network/libraesva/snmp/mode/interfaces.pm new file mode 100644 index 000000000..72f1fef4f --- /dev/null +++ b/centreon-plugins/network/libraesva/snmp/mode/interfaces.pm @@ -0,0 +1,182 @@ +# +# Copyright 2022 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::libraesva::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/centreon-plugins/network/libraesva/snmp/mode/load.pm b/centreon-plugins/network/libraesva/snmp/mode/load.pm new file mode 100644 index 000000000..10b398d60 --- /dev/null +++ b/centreon-plugins/network/libraesva/snmp/mode/load.pm @@ -0,0 +1,60 @@ +# +# Copyright 2022 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::libraesva::snmp::mode::load; + +use base qw(snmp_standard::mode::loadaverage); + +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 system load-average. + +=over 8 + +=item B<--warning> + +Threshold warning (1min,5min,15min). + +=item B<--critical> + +Threshold critical (1min,5min,15min). + +=item B<--average> + +Load average for the number of CPUs. + +=back + +=cut diff --git a/centreon-plugins/network/libraesva/snmp/mode/memory.pm b/centreon-plugins/network/libraesva/snmp/mode/memory.pm new file mode 100644 index 000000000..d605d914d --- /dev/null +++ b/centreon-plugins/network/libraesva/snmp/mode/memory.pm @@ -0,0 +1,67 @@ +# +# Copyright 2022 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::libraesva::snmp::mode::memory; + +use base qw(snmp_standard::mode::memory); + +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 memory usage (UCD-SNMP-MIB). + +=over 8 + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'absolute') (Deprecated. Please use new counters directly) + +=item B<--free> + +Thresholds are on free space left (Deprecated. Please use new counters directly) + +=item B<--swap> + +Check swap also. + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), +'swap' (B), 'swap-free' (B), 'swap-prct' (%), +'buffer' (B), 'cached' (B), 'shared' (B). + +=back + +=cut diff --git a/centreon-plugins/network/libraesva/snmp/mode/storage.pm b/centreon-plugins/network/libraesva/snmp/mode/storage.pm new file mode 100644 index 000000000..773b4af0d --- /dev/null +++ b/centreon-plugins/network/libraesva/snmp/mode/storage.pm @@ -0,0 +1,132 @@ +# +# Copyright 2022 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::libraesva::snmp::mode::storage; + +use base qw(snmp_standard::mode::storage); + +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 + +=over 8 + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=item B<--warning-access> + +Threshold warning. + +=item B<--critical-access> + +Threshold critical. +Check if storage is readOnly: --critical-access=readOnly + +=item B<--add-access> + +Check storage access (readOnly, readWrite). + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=item B<--storage> + +Set the storage (number expected) ex: 1, 2,... (empty means 'check all storage'). + +=item B<--name> + +Allows to use storage name with option --storage instead of storage oid index. + +=item B<--regexp> + +Allows to use regexp to filter storage (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--path-best-match> + +Allows to select best path mount point (with --name). + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter storage (default: hrStorageDescr) (values: hrStorageDescr, hrFSMountPoint). + +=item B<--oid-display> + +Choose OID used to display storage (default: hrStorageDescr) (values: hrStorageDescr, hrFSMountPoint). + +=item B<--display-transform-src> + +Regexp src to transform display value. (security risk!!!) + +=item B<--display-transform-dst> + +Regexp dst to transform display value. (security risk!!!) + +=item B<--show-cache> + +Display cache storage datas. + +=item B<--space-reservation> + +Some filesystem has space reserved (like ext4 for root). +The value is in percent of total (Default: none) (results like 'df' command). + +=item B<--filter-duplicate> + +Filter duplicate storages (in used size and total size). + +=item B<--filter-storage-type> + +Filter storage types with a regexp (Default: '^(hrStorageFixedDisk|hrStorageNetworkDisk|hrFSBerkeleyFFS)$'). + +=back + +=cut diff --git a/centreon-plugins/network/libraesva/snmp/mode/swap.pm b/centreon-plugins/network/libraesva/snmp/mode/swap.pm new file mode 100644 index 000000000..3d288e937 --- /dev/null +++ b/centreon-plugins/network/libraesva/snmp/mode/swap.pm @@ -0,0 +1,57 @@ +# +# Copyright 2022 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::libraesva::snmp::mode::swap; + +use base qw(snmp_standard::mode::swap); + +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 swap memory (UCD-SNMP-MIB). + +=over 8 + +=item B<--no-swap> + +Threshold if no active swap (default: 'critical'). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/network/libraesva/snmp/mode/system.pm b/centreon-plugins/network/libraesva/snmp/mode/system.pm index 32f1df254..4343cffee 100644 --- a/centreon-plugins/network/libraesva/snmp/mode/system.pm +++ b/centreon-plugins/network/libraesva/snmp/mode/system.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -37,7 +37,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ @@ -45,74 +45,73 @@ sub set_counters { key_values => [ { name => 'mailSent', diff => 1 } ], output_template => 'mails sent: %s', perfdatas => [ - { value => 'mailSent', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'mails-received', nlabel => 'system.mails.received.count', set => { key_values => [ { name => 'mailReceived', diff => 1 } ], output_template => 'mails received: %s', perfdatas => [ - { value => 'mailReceived', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'mails-rejected', nlabel => 'system.mails.rejected.count', set => { key_values => [ { name => 'mailRejected', diff => 1 } ], output_template => 'mails rejected: %s', perfdatas => [ - { value => 'mailRejected', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'mails-bounced', nlabel => 'system.mails.bounced.count', display_ok => 0, set => { key_values => [ { name => 'mailBounced', diff => 1 } ], output_template => 'mails bounced: %s', perfdatas => [ - { value => 'mailBounced', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'messages-spam', nlabel => 'system.messages.spam.count', set => { key_values => [ { name => 'spamMessages', diff => 1 } ], output_template => 'spam messages: %s', perfdatas => [ - { value => 'spamMessages', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'messages-virus', nlabel => 'system.messages.virus.count', set => { key_values => [ { name => 'virusMessages', diff => 1 } ], output_template => 'virus messages: %s', perfdatas => [ - { value => 'virusMessages', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'mails-queue-in', nlabel => 'system.mails.queue.in.count', set => { key_values => [ { name => 'incomingMailQueue' } ], output_template => 'mails queue in: %s', perfdatas => [ - { value => 'incomingMailQueue', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'mails-queue-out', nlabel => 'system.mails.queue.ou.count', set => { key_values => [ { name => 'outgoingMailQueue' } ], output_template => 'mails queue out: %s', perfdatas => [ - { value => 'outgoingMailQueue', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, - { label => 'cluster-status', threshold => 0, set => { + { label => 'cluster-status', type => 2, critical_default => '%{cluster_status} =~ /error/i', set => { key_values => [ { name => 'cluster_status' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; } @@ -121,22 +120,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => { - 'unknown-cluster-status:s' => { name => 'unknown_cluster_status', default => '' }, - 'warning-cluster-status:s' => { name => 'warning_cluster_status', default => '' }, - 'critical-cluster-status:s' => { name => 'critical_cluster_status', default => '%{cluster_status} =~ /error/i' }, - }); + $options{options}->add_options(arguments => {}); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_cluster_status', 'critical_cluster_status', 'unknown_cluster_status']); -} - my $map_cluster_status = { -1 => 'nocluster', 0 => 'healthy', 1 => 'error' }; @@ -150,7 +138,7 @@ my $mapping = { virusMessages => { oid => '.1.3.6.1.4.1.41091.1.1.6' }, incomingMailQueue => { oid => '.1.3.6.1.4.1.41091.1.1.8' }, outgoingMailQueue => { oid => '.1.3.6.1.4.1.41091.1.1.9' }, - cluster_status => { oid => '.1.3.6.1.4.1.41091.1.1.10', map => $map_cluster_status }, + cluster_status => { oid => '.1.3.6.1.4.1.41091.1.1.10', map => $map_cluster_status } }; sub manage_selection { @@ -160,7 +148,7 @@ sub manage_selection { oids => [ map($_->{oid} . '.0', values(%$mapping)) ], nothing_quit => 1 ); - $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); $self->{cache_name} = 'libraesva_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); diff --git a/centreon-plugins/network/libraesva/snmp/plugin.pm b/centreon-plugins/network/libraesva/snmp/plugin.pm index f8b6610f9..1e779e763 100644 --- a/centreon-plugins/network/libraesva/snmp/plugin.pm +++ b/centreon-plugins/network/libraesva/snmp/plugin.pm @@ -29,17 +29,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'load' => 'snmp_standard::mode::loadaverage', - 'interfaces' => 'snmp_standard::mode::interfaces', + $self->{modes} = { + 'load' => 'network::libraesva::snmp::mode::load', + 'interfaces' => 'network::libraesva::snmp::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', - 'memory' => 'snmp_standard::mode::memory', - 'storage' => 'snmp_standard::mode::storage', + 'memory' => 'network::libraesva::snmp::mode::memory', + 'storage' => 'network::libraesva::snmp::mode::storage', 'system' => 'network::libraesva::snmp::mode::system', - 'swap' => 'snmp_standard::mode::swap', - ); + 'swap' => 'network::libraesva::snmp::mode::swap' + }; return $self; }