From a72f89d7b19c74f18be5d60e390eef4e23e682a6 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 7 May 2020 10:41:36 +0200 Subject: [PATCH] add dell me4 interfaces + typo --- storage/dell/me4/restapi/mode/interfaces.pm | 265 ++++++++++++++++++ storage/dell/me4/restapi/plugin.pm | 3 +- .../restapi/mode/storagecontrollers.pm | 4 +- 3 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 storage/dell/me4/restapi/mode/interfaces.pm diff --git a/storage/dell/me4/restapi/mode/interfaces.pm b/storage/dell/me4/restapi/mode/interfaces.pm new file mode 100644 index 000000000..5aee01ee5 --- /dev/null +++ b/storage/dell/me4/restapi/mode/interfaces.pm @@ -0,0 +1,265 @@ +# +# Copyright 2020 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 storage::dell::me4::restapi::mode::interfaces; + +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); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s [health: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{health} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ports', type => 3, cb_prefix_output => 'prefix_port_output', cb_long_output => 'port_long_output', indent_long_output => ' ', message_multiple => 'All interfaces are ok', + group => [ + { name => 'port_global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'interfaces', display_long => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{port_global} = [ + { label => 'port-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'health'}, { name => 'display' } ], + 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 + } + }, + { label => 'read-iops', nlabel => 'port.io.read.usage.iops', set => { + key_values => [ { name => 'number_of_reads', diff => 1 }, { name => 'display' } ], + output_template => 'read iops: %.2f', + per_second => 1, + perfdatas => [ + { value => 'number_of_reads_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'write-iops', nlabel => 'port.io.write.usage.iops', set => { + key_values => [ { name => 'number_of_writes', diff => 1 }, { name => 'display' } ], + output_template => 'write iops: %.2f', + per_second => 1, + perfdatas => [ + { value => 'number_of_writes_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'read-traffic', nlabel => 'port.traffic.read.usage.bitspersecond', set => { + key_values => [ { name => 'data_read_numeric', diff => 1 }, { name => 'display' } ], + output_template => 'read traffic: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'data_read_numeric_per_second', template => '%d', + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'write-traffic', nlabel => 'port.traffic.write.usage.bitspersecond', set => { + key_values => [ { name => 'data_write_numeric' }, { name => 'display' } ], + output_template => 'write traffic: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'data_write_numeric_per_second', template => '%d', + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] + } + } + ]; + + $self->{maps_counters}->{interfaces} = [ + { label => 'interface-disparity-errors', nlabel => 'port.interface.disparity.errors.count', set => { + key_values => [ { name => 'disparity_errors' }, { name => 'display' } ], + output_template => 'disparity errors: %s', + perfdatas => [ + { value => 'disparity_errors_absolute', template => '%d', + min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'interface-lost-dwords', nlabel => 'port.interface.lost.dwords.count', set => { + key_values => [ { name => 'lost_dwords' }, { name => 'display' } ], + output_template => 'lost dwords: %s', + perfdatas => [ + { value => 'lost_dwords_absolute', template => '%d', + min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'interface-invalid-dwords', nlabel => 'port.interface.invalid.dwords.count', set => { + key_values => [ { name => 'lost_dwords' }, { name => 'display' } ], + output_template => 'invalid dwords: %s', + perfdatas => [ + { value => 'invalid_dwords_absolute', template => '%d', + min => 0, label_extra_instance => 1 } + ] + } + } + ]; +} + +sub port_long_output { + my ($self, %options) = @_; + + return "checking port '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_port_output { + my ($self, %options) = @_; + + return "port '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_interface_output { + my ($self, %options) = @_; + + return "interface '" . $options{instance_value}->{display} . "' "; +} + +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 => { + 'unknown-port-status:s' => { name => 'unknown_port_status', default => '%{health} =~ /unknown/i' }, + 'warning-port-status:s' => { name => 'warning_port_status', default => '%{health} =~ /degraded/i' }, + 'critical-port-status:s' => { name => 'critical_port_status', default => '%{health} =~ /fault/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_port_status', 'critical_port_status', 'unknown_port_status']); +} + +my $mapping_status = { + 0 => 'up', + 1 => 'down', + 2 => 'notInstalled' +}; +my $mapping_health = { + 0 => 'ok', 1 => 'degraded', 2 => 'fault', 3 => 'unknown', 4 => 'notAvailable' +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $result_ports = $options{custom}->request_api(method => 'GET', url_path => '/api/show/ports'); + my $result_ports_stats = $options{custom}->request_api(method => 'GET', url_path => '/api/show/host-port-statistics'); + my $result_logical_interfaces = $options{custom}->request_api(method => 'GET', url_path => '/api/show/host-phy-statistics'); + + my $mapping_ports = {}; + + $self->{ports} = {}; + foreach my $port (@{$result_ports->{port}}) { + my $port_name = $port->{port}; + $mapping_ports->{ $port->{'durable-id'} } = $port_name; + + $self->{ports}->{$port_name} = { + display => $port_name, + port_global => { + display => $port_name, + health => $mapping_health->{ $port->{'health-numeric'} }, + status => $mapping_status->{ $port->{'status-numeric'} } + }, + interfaces => {} + }; + } + + foreach (@{$result_ports_stats->{'host-port-statistics'}}) { + next if (!defined($mapping_ports->{ $_->{'durable-id'} })); + + $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{number_of_reads} = $_->{'number-of-reads'}; + $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{number_of_writes} = $_->{'number-of-writes'}; + $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{data_read_numeric} = $_->{'data-read-numeric'}; + $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{data_write_numeric} = $_->{'data-write-numeric'}; + + } + + foreach (@{$result_logical_interfaces->{'sas-host-phy-statistics'}}) { + next if ($self->{ports}->{ $_->{port} }); + + $self->{ports}->{ $_->{port} }->{interfaces}->{ $_->{phy} } = { + display => $_->{phy}, + disparity_errors => $_->{'disparity-errors'}, + invalid_dwords => $_->{'invalid-dwords'}, + lost_dwords => $_->{'lost-dwords'} + }; + } + + $self->{cache_name} = 'dell_me4_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--unknown-port-status> + +Set unknown threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status}, %{health}, %{display} + +=item B<--warning-port-status> + +Set warning threshold for status (Default: '%{status} =~ /degraded/i'). +Can used special variables like: %{status}, %{health}, %{display} + +=item B<--critical-port-status> + +Set critical threshold for status (Default: '%{status} =~ /fault/i'). +Can used special variables like: %{status}, %{health}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'read-iops', 'write-iops', 'read-traffic', 'write-traffic', +'interface-disparity-errors', 'interface-lost-dwords', 'interface-invalid-dwords'. + +=back + +=cut diff --git a/storage/dell/me4/restapi/plugin.pm b/storage/dell/me4/restapi/plugin.pm index e044c3d94..ddb9a2c2d 100644 --- a/storage/dell/me4/restapi/plugin.pm +++ b/storage/dell/me4/restapi/plugin.pm @@ -33,9 +33,10 @@ sub new { %{ $self->{modes} } = ( 'controller-statistics' => 'storage::dell::me4::restapi::mode::controllerstatistics', 'hardware' => 'storage::dell::me4::restapi::mode::hardware', + 'interfaces' => 'storage::dell::me4::restapi::mode::interfaces', 'list-controllers' => 'storage::dell::me4::restapi::mode::listcontrollers', 'list-volumes' => 'storage::dell::me4::restapi::mode::listvolumes', - 'volume-statistics' => 'storage::dell::me4::restapi::mode::volumestatistics', + 'volume-statistics' => 'storage::dell::me4::restapi::mode::volumestatistics' ); $self->{custom_modes}{api} = 'storage::dell::me4::restapi::custom::api'; diff --git a/storage/netapp/santricity/restapi/mode/storagecontrollers.pm b/storage/netapp/santricity/restapi/mode/storagecontrollers.pm index 7ac1d81e9..b8af42419 100644 --- a/storage/netapp/santricity/restapi/mode/storagecontrollers.pm +++ b/storage/netapp/santricity/restapi/mode/storagecontrollers.pm @@ -217,7 +217,7 @@ Check storage controllers. =item B<--filter-counters> Only display some counters (regexp can be used). -Example: --filter-counters='volume-status' +Example: --filter-counters='controller-status' =item B<--filter-storage-name> @@ -245,7 +245,7 @@ Can used special variables like: %{status}, %{display} =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'. +Can be: 'cpu-utilization' (%), 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'. =back