From 512685c6c7c16e8f48aeeab8870049b839f6f708 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 16 Oct 2020 15:56:38 +0200 Subject: [PATCH] Fix 2250 (#2260) * Fix #2250 --- storage/emc/vplex/restapi/custom/vplexapi.pm | 24 +++++++++++-------- .../restapi/mode/clustercommunication.pm | 18 +++++++------- .../emc/vplex/restapi/mode/clusterdevices.pm | 15 +++++++----- storage/emc/vplex/restapi/mode/directors.pm | 15 +++++++----- .../vplex/restapi/mode/distributeddevices.pm | 5 ++-- storage/emc/vplex/restapi/mode/fans.pm | 13 ++++++---- storage/emc/vplex/restapi/mode/psus.pm | 13 ++++++---- .../emc/vplex/restapi/mode/storagevolumes.pm | 9 +++---- storage/emc/vplex/restapi/plugin.pm | 8 +++---- 9 files changed, 67 insertions(+), 53 deletions(-) diff --git a/storage/emc/vplex/restapi/custom/vplexapi.pm b/storage/emc/vplex/restapi/custom/vplexapi.pm index 294d28856..385a092f0 100644 --- a/storage/emc/vplex/restapi/custom/vplexapi.pm +++ b/storage/emc/vplex/restapi/custom/vplexapi.pm @@ -107,8 +107,12 @@ sub get_items { $self->settings(); if (defined($options{parent})) { - if (defined($options{$options{parent}}) && $options{$options{parent}} ne '') { - $options{url} .= $options{parent} . '-' . $options{engine} . '/'; + if (defined($options{parent_filter}) && $options{parent_filter} ne '') { + if ($options{parent_filter} =~ /^[0-9\-]+$/) { + $options{url} .= $options{parent_filter_prefix} . $options{parent_filter} . '/'; + } else { + $options{url} .= $options{parent_filter} . '/'; + } } else { $options{url} .= '*' . '/'; } @@ -117,7 +121,7 @@ sub get_items { $options{url} .= $options{obj} . '/'; } $options{url} .= '*'; - + my $response = $self->{http}->request(url_path => $options{url}); my $decoded; eval { @@ -127,26 +131,26 @@ sub get_items { $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); $self->{output}->option_exit(); } - + my $items = {}; foreach my $context (@{$decoded->{response}->{context}}) { my $engine_name; if (defined($options{parent})) { - $context->{parent} =~ /\/$options{parent}-(.*?)\//; - $engine_name = $options{parent} . '-' . $1; + $context->{parent} =~ /$options{parent_select}/; + $engine_name = $1; $items->{$engine_name} = {} if (!defined($items->{$engine_name})); } - + my $attributes = {}; foreach my $attribute (@{$context->{attributes}}) { - $attributes->{$attribute->{name}} = $attribute->{value}; + $attributes->{ $attribute->{name} } = $attribute->{value}; } if (defined($engine_name)) { - $items->{$engine_name}->{$attributes->{name}} = $attributes; + $items->{$engine_name}->{ $attributes->{name} } = $attributes; } else { - $items->{$attributes->{name}} = $attributes; + $items->{ $attributes->{name} } = $attributes; } } diff --git a/storage/emc/vplex/restapi/mode/clustercommunication.pm b/storage/emc/vplex/restapi/mode/clustercommunication.pm index 235b3f648..a07ac47fc 100644 --- a/storage/emc/vplex/restapi/mode/clustercommunication.pm +++ b/storage/emc/vplex/restapi/mode/clustercommunication.pm @@ -29,8 +29,8 @@ my $thresholds = { component_opstatus => [ ['cluster-in-contact', 'OK'], ['in-contact', 'OK'], - ['.*', 'CRITICAL'], - ], + ['.*', 'CRITICAL'] + ] }; sub new { @@ -38,11 +38,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter:s@" => { name => 'filter' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); + $options{options}->add_options(arguments => { + 'filter:s@' => { name => 'filter' }, + 'threshold-overload:s@' => { name => 'threshold_overload' } + }); return $self; } @@ -92,9 +91,8 @@ sub run { $self->{output}->output_add(severity => 'OK', short_msg => 'All Cluster Witness components are OK'); - - my $urlbase = '/vplex/cluster-witness/components/'; - my $items = $vplex->get_items(url => $urlbase); + + my $items = $vplex->get_items(url => '/vplex/cluster-witness/components/'); foreach my $name (sort keys %{$items}) { my $instance = $name; diff --git a/storage/emc/vplex/restapi/mode/clusterdevices.pm b/storage/emc/vplex/restapi/mode/clusterdevices.pm index 132afab97..027d76fbf 100644 --- a/storage/emc/vplex/restapi/mode/clusterdevices.pm +++ b/storage/emc/vplex/restapi/mode/clusterdevices.pm @@ -89,12 +89,15 @@ sub check_options { sub run { my ($self, %options) = @_; my $vplex = $options{custom}; - - my $urlbase = '/vplex/clusters/'; - my $items = $vplex->get_items(url => $urlbase, - parent => 'cluster', - engine => $self->{option_results}->{cluster}, - obj => 'devices'); + + my $items = $vplex->get_items( + url => '/vplex/clusters/', + parent => 1, + parent_filter => $self->{option_results}->{cluster}, + parent_filter_prefix => 'cluster-', + parent_select => '/clusters/(.*?)/', + obj => 'devices' + ); $self->{output}->output_add(severity => 'OK', short_msg => 'All Cluster Devices are OK'); diff --git a/storage/emc/vplex/restapi/mode/directors.pm b/storage/emc/vplex/restapi/mode/directors.pm index ccd6cd731..ea538fed7 100644 --- a/storage/emc/vplex/restapi/mode/directors.pm +++ b/storage/emc/vplex/restapi/mode/directors.pm @@ -104,12 +104,15 @@ sub check_options { sub run { my ($self, %options) = @_; my $vplex = $options{custom}; - - my $urlbase = '/vplex/engines/'; - my $items = $vplex->get_items(url => $urlbase, - parent => 'engine', - engine => $self->{option_results}->{engine}, - obj => 'directors'); + + my $items = $vplex->get_items( + url => '/vplex/engines/', + parent => 1, + parent_filter => $self->{option_results}->{engine}, + parent_filter_prefix => 'engine-', + parent_select => '/engines/(.*?)/', + obj => 'directors' + ); $self->{output}->output_add(severity => 'OK', short_msg => 'All Directors are OK'); diff --git a/storage/emc/vplex/restapi/mode/distributeddevices.pm b/storage/emc/vplex/restapi/mode/distributeddevices.pm index dedd656fb..69a65dbf3 100644 --- a/storage/emc/vplex/restapi/mode/distributeddevices.pm +++ b/storage/emc/vplex/restapi/mode/distributeddevices.pm @@ -99,9 +99,8 @@ sub run { $self->{output}->output_add(severity => 'OK', short_msg => 'All Distributed devices are OK'); - - my $urlbase = '/vplex/distributed-storage/distributed-devices/'; - my $items = $vplex->get_items(url => $urlbase); + + my $items = $vplex->get_items(url => '/vplex/distributed-storage/distributed-devices/'); foreach my $name (sort keys %{$items}) { my $instance = $name; diff --git a/storage/emc/vplex/restapi/mode/fans.pm b/storage/emc/vplex/restapi/mode/fans.pm index fcc658ede..aa6f5630c 100644 --- a/storage/emc/vplex/restapi/mode/fans.pm +++ b/storage/emc/vplex/restapi/mode/fans.pm @@ -94,14 +94,17 @@ sub run { my ($self, %options) = @_; my $vplex = $options{custom}; - my $urlbase = '/vplex/engines/'; $self->{output}->output_add(severity => 'OK', short_msg => 'All Fans are OK'); - my $items = $vplex->get_items(url => $urlbase, - parent => 'engine', - engine => $self->{option_results}->{engine}, - obj => 'fans'); + my $items = $vplex->get_items( + url => '/vplex/engines/', + parent => 1, + parent_filter => $self->{option_results}->{engine}, + parent_filter_prefix => 'engine-', + parent_select => '/engines/(.*?)/', + obj => 'fans' + ); foreach my $engine_name (sort keys %{$items}) { foreach my $fan_name (sort keys %{$items->{$engine_name}}) { my $instance = $engine_name . '_' . $fan_name; diff --git a/storage/emc/vplex/restapi/mode/psus.pm b/storage/emc/vplex/restapi/mode/psus.pm index 5cf7ba059..1a17b8e72 100644 --- a/storage/emc/vplex/restapi/mode/psus.pm +++ b/storage/emc/vplex/restapi/mode/psus.pm @@ -94,11 +94,14 @@ sub run { my ($self, %options) = @_; my $vplex = $options{custom}; - my $urlbase = '/vplex/engines/'; - my $items = $vplex->get_items(url => $urlbase, - parent => 'engine', - engine => $self->{option_results}->{engine}, - obj => 'power-supplies'); + my $items = $vplex->get_items( + url => '/vplex/engines/', + parent => 1, + parent_filter => $self->{option_results}->{engine}, + parent_filter_prefix => 'engine-', + parent_select => '/engines/(.*?)/', + obj => 'power-supplies' + ); $self->{output}->output_add(severity => 'OK', short_msg => 'All Power supplies are OK'); diff --git a/storage/emc/vplex/restapi/mode/storagevolumes.pm b/storage/emc/vplex/restapi/mode/storagevolumes.pm index 2ad79f666..3c352a99b 100644 --- a/storage/emc/vplex/restapi/mode/storagevolumes.pm +++ b/storage/emc/vplex/restapi/mode/storagevolumes.pm @@ -89,11 +89,12 @@ sub run { my ($self, %options) = @_; my $vplex = $options{custom}; - my $urlbase = '/vplex/clusters/'; my $items = $vplex->get_items( - url => $urlbase, - parent => 'cluster', - engine => $self->{option_results}->{cluster}, + url => '/vplex/clusters/', + parent => 1, + parent_filter => $self->{option_results}->{cluster}, + parent_filter_prefix => 'cluster-', + parent_select => '/clusters/(.*?)/', obj => 'storage-elements/storage-volumes' ); diff --git a/storage/emc/vplex/restapi/plugin.pm b/storage/emc/vplex/restapi/plugin.pm index 853fc65af..3b58a5066 100644 --- a/storage/emc/vplex/restapi/plugin.pm +++ b/storage/emc/vplex/restapi/plugin.pm @@ -30,17 +30,17 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( + $self->{modes} = { 'psus' => 'storage::emc::vplex::restapi::mode::psus', 'fans' => 'storage::emc::vplex::restapi::mode::fans', 'distributed-devices' => 'storage::emc::vplex::restapi::mode::distributeddevices', 'cluster-devices' => 'storage::emc::vplex::restapi::mode::clusterdevices', 'storage-volumes' => 'storage::emc::vplex::restapi::mode::storagevolumes', 'directors' => 'storage::emc::vplex::restapi::mode::directors', - 'cluster-communication' => 'storage::emc::vplex::restapi::mode::clustercommunication', - ); + 'cluster-communication' => 'storage::emc::vplex::restapi::mode::clustercommunication' + }; - $self->{custom_modes}{vplexapi} = 'storage::emc::vplex::restapi::custom::vplexapi'; + $self->{custom_modes}->{vplexapi} = 'storage::emc::vplex::restapi::custom::vplexapi'; return $self; }