From db879e33564212c4b88aa9639be604815afa049e Mon Sep 17 00:00:00 2001 From: qgarnier Date: Thu, 6 Oct 2022 10:25:10 +0200 Subject: [PATCH] (plugin) apps::vmware::vcsa::snmp - new (#3963) --- .../apps/vmware/vcsa/snmp/mode/cpu.pm | 64 ++++++ .../apps/vmware/vcsa/snmp/mode/interfaces.pm | 186 ++++++++++++++++++ .../vmware/vcsa/snmp/mode/listinterfaces.pm | 108 ++++++++++ .../apps/vmware/vcsa/snmp/mode/memory.pm | 151 ++++++++++++++ .../apps/vmware/vcsa/snmp/mode/storage.pm | 132 +++++++++++++ .../apps/vmware/vcsa/snmp/mode/uptime.pm | 77 ++++++++ .../apps/vmware/vcsa/snmp/plugin.pm | 53 +++++ 7 files changed, 771 insertions(+) create mode 100644 centreon-plugins/apps/vmware/vcsa/snmp/mode/cpu.pm create mode 100644 centreon-plugins/apps/vmware/vcsa/snmp/mode/interfaces.pm create mode 100644 centreon-plugins/apps/vmware/vcsa/snmp/mode/listinterfaces.pm create mode 100644 centreon-plugins/apps/vmware/vcsa/snmp/mode/memory.pm create mode 100644 centreon-plugins/apps/vmware/vcsa/snmp/mode/storage.pm create mode 100644 centreon-plugins/apps/vmware/vcsa/snmp/mode/uptime.pm create mode 100644 centreon-plugins/apps/vmware/vcsa/snmp/plugin.pm diff --git a/centreon-plugins/apps/vmware/vcsa/snmp/mode/cpu.pm b/centreon-plugins/apps/vmware/vcsa/snmp/mode/cpu.pm new file mode 100644 index 000000000..0e0299768 --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/snmp/mode/cpu.pm @@ -0,0 +1,64 @@ +# +# 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 apps::vmware::vcsa::snmp::mode::cpu; + +use base qw(snmp_standard::mode::cpu); + +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 cpu. + +=over 8 + +=item B<--warning-average> + +Warning threshold average CPU utilization. + +=item B<--critical-average> + +Critical threshold average CPU utilization. + +=item B<--warning-core> + +Warning thresholds for each CPU core + +=item B<--critical-core> + +Critical thresholds for each CPU core + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/vcsa/snmp/mode/interfaces.pm b/centreon-plugins/apps/vmware/vcsa/snmp/mode/interfaces.pm new file mode 100644 index 000000000..5ae9f18d9 --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/snmp/mode/interfaces.pm @@ -0,0 +1,186 @@ +# +# 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 apps::vmware::vcsa::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub default_oid_filter_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +sub default_oid_display_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +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<--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: ifDesc) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifDesc) (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/apps/vmware/vcsa/snmp/mode/listinterfaces.pm b/centreon-plugins/apps/vmware/vcsa/snmp/mode/listinterfaces.pm new file mode 100644 index 000000000..277e7cbb5 --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/snmp/mode/listinterfaces.pm @@ -0,0 +1,108 @@ +# +# 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 apps::vmware::vcsa::snmp::mode::listinterfaces; + +use base qw(snmp_standard::mode::listinterfaces); + +use strict; +use warnings; + +sub default_oid_filter_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +sub default_oid_display_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +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<--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 (in Mb). + +=item B<--skip-speed0> + +Don't display interface with speed 0. + +=item B<--filter-status> + +Display interfaces matching the filter (example: 'up'). + +=item B<--use-adminstatus> + +Display interfaces with AdminStatus 'up'. + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifDesc) (values: ifDesc, ifAlias, ifName). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifDesc) (values: ifDesc, ifAlias, ifName). + +=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<--add-extra-oid> + +Display an OID. +Example: --add-extra-oid='alias,.1.3.6.1.2.1.31.1.1.1.18' +or --add-extra-oid='vlan,.1.3.6.1.2.1.31.19,%{instance}\..*' + +=item B<--add-mac-address> + +Display interface mac address. + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/vcsa/snmp/mode/memory.pm b/centreon-plugins/apps/vmware/vcsa/snmp/mode/memory.pm new file mode 100644 index 000000000..3f87676dc --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/snmp/mode/memory.pm @@ -0,0 +1,151 @@ +# +# 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 apps::vmware::vcsa::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Ram Total: %s %s Used (-buffers/cache): %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), + $self->{result_values}->{prct_used}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), + $self->{result_values}->{prct_free} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ram', type => 0, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{ram} = [ + { label => 'usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + 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; + + return $self; +} + +my $mapping = { + hrStorageDescr => { oid => '.1.3.6.1.2.1.25.2.3.1.3' }, + hrStorageAllocationUnits => { oid => '.1.3.6.1.2.1.25.2.3.1.4' }, + hrStorageSize => { oid => '.1.3.6.1.2.1.25.2.3.1.5' }, + hrStorageUsed => { oid => '.1.3.6.1.2.1.25.2.3.1.6' } +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $storage_type_ram = '.1.3.6.1.2.1.25.2.1.2'; + my $oid_hrstoragetype = '.1.3.6.1.2.1.25.2.3.1.2'; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_hrstoragetype, nothing_quit => 1); + my $storages = []; + foreach (keys %$snmp_result) { + next if ($snmp_result->{$_} ne $storage_type_ram); + /^$oid_hrstoragetype\.(.*)$/; + push @$storages, $1; + } + + $options{snmp}->load( + oids => [map($_->{oid}, values(%$mapping))], + instances => $storages, + nothing_quit => 1 + ); + $snmp_result = $options{snmp}->get_leef(); + + my ($total, $used); + #.1.3.6.1.2.1.25.2.3.1.3.45 = STRING: Real Memory + foreach (@$storages) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + my $current = $result->{hrStorageUsed} * $result->{hrStorageAllocationUnits}; + next if ($current < 0); + + if ($result->{hrStorageDescr} =~ /Real\s+Memory/i) { + $used = $current; + $total = $result->{hrStorageSize} * $result->{hrStorageAllocationUnits}; + } + } + + $self->{ram} = { + total => $total, + used => $used, + free => $total - $used, + prct_used => $used * 100 / $total, + prct_free => 100 - ($used * 100 / $total) + }; +} + +1; + +__END__ + +=head1 MODE + +Check memory. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/vcsa/snmp/mode/storage.pm b/centreon-plugins/apps/vmware/vcsa/snmp/mode/storage.pm new file mode 100644 index 000000000..2f0397200 --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/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 apps::vmware::vcsa::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/apps/vmware/vcsa/snmp/mode/uptime.pm b/centreon-plugins/apps/vmware/vcsa/snmp/mode/uptime.pm new file mode 100644 index 000000000..d8e639e48 --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/snmp/mode/uptime.pm @@ -0,0 +1,77 @@ +# +# 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 apps::vmware::vcsa::snmp::mode::uptime; + +use base qw(snmp_standard::mode::uptime); + +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 uptime. + +=over 8 + +=item B<--warning-uptime> + +Threshold warning. + +=item B<--critical-uptime> + +Threshold critical. + +=item B<--add-sysdesc> + +Display system description. + +=item B<--force-oid> + +Can choose your oid (numeric format only). + +=item B<--check-overload> + +Uptime counter limit is 4294967296 and overflow. +With that option, we manage the counter going back. But there is a few chance we can miss a reboot. + +=item B<--reboot-window> + +To be used with check-overload option. Time in milliseconds (Default: 5000) +You increase the chance of not missing a reboot if you decrease that value. + +=item B<--unit> + +Select the unit for performance data and thresholds. May be 's' for seconds, 'm' for minutes, +'h' for hours, 'd' for days, 'w' for weeks. Default is seconds + +=back diff --git a/centreon-plugins/apps/vmware/vcsa/snmp/plugin.pm b/centreon-plugins/apps/vmware/vcsa/snmp/plugin.pm new file mode 100644 index 000000000..eb9d4d1d1 --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/snmp/plugin.pm @@ -0,0 +1,53 @@ +# +# 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 apps::vmware::vcsa::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} = { + 'cpu' => 'apps::vmware::vcsa::snmp::mode::cpu', + 'interfaces' => 'apps::vmware::vcsa::snmp::mode::interfaces', + 'list-interfaces' => 'apps::vmware::vcsa::snmp::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'memory' => 'apps::vmware::vcsa::snmp::mode::memory', + 'storage' => 'apps::vmware::vcsa::snmp::mode::storage', + 'uptime' => 'apps::vmware::vcsa::snmp::mode::uptime' + }; + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check vCenter Server Appliance (VCSA) in SNMP. + +=cut