From 19fc6affce478a9d92961f3aa39a862a79e104b2 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 29 Nov 2019 15:24:30 +0100 Subject: [PATCH] fix emc unisphere rest api plugin --- .../restapi/mode/components/battery.pm | 2 +- .../unisphere/restapi/mode/components/disk.pm | 2 +- .../unisphere/restapi/mode/components/dpe.pm | 2 +- .../unisphere/restapi/mode/components/fan.pm | 2 +- .../restapi/mode/components/iomodule.pm | 2 +- .../unisphere/restapi/mode/components/psu.pm | 2 +- .../unisphere/restapi/mode/components/sp.pm | 2 +- .../unisphere/restapi/mode/components/ssd.pm | 2 +- .../emc/unisphere/restapi/mode/listpools.pm | 2 +- .../restapi/mode/liststorageresources.pm | 2 +- storage/emc/unisphere/restapi/mode/pools.pm | 2 +- .../restapi/mode/storageresources.pm | 26 +++++++++++-------- 12 files changed, 26 insertions(+), 22 deletions(-) diff --git a/storage/emc/unisphere/restapi/mode/components/battery.pm b/storage/emc/unisphere/restapi/mode/components/battery.pm index 484c8d93a..3e5931e61 100644 --- a/storage/emc/unisphere/restapi/mode/components/battery.pm +++ b/storage/emc/unisphere/restapi/mode/components/battery.pm @@ -27,7 +27,7 @@ use storage::emc::unisphere::restapi::mode::components::resources qw($health_sta sub load { my ($self) = @_; - $self->{json_results}->{battery} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/battery/instances'); + $self->{json_results}->{battery} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/battery/instances?fields=name,health'); } sub check { diff --git a/storage/emc/unisphere/restapi/mode/components/disk.pm b/storage/emc/unisphere/restapi/mode/components/disk.pm index 1d1565256..c5afc2a5d 100644 --- a/storage/emc/unisphere/restapi/mode/components/disk.pm +++ b/storage/emc/unisphere/restapi/mode/components/disk.pm @@ -27,7 +27,7 @@ use storage::emc::unisphere::restapi::mode::components::resources qw($health_sta sub load { my ($self) = @_; - $self->{json_results}->{disks} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/disk/instances'); + $self->{json_results}->{disks} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/disk/instances?fields=name,health'); } sub check { diff --git a/storage/emc/unisphere/restapi/mode/components/dpe.pm b/storage/emc/unisphere/restapi/mode/components/dpe.pm index 473cea495..18dd9bde0 100644 --- a/storage/emc/unisphere/restapi/mode/components/dpe.pm +++ b/storage/emc/unisphere/restapi/mode/components/dpe.pm @@ -27,7 +27,7 @@ use storage::emc::unisphere::restapi::mode::components::resources qw($health_sta sub load { my ($self) = @_; - $self->{json_results}->{dpe} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/dpe/instances'); + $self->{json_results}->{dpe} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/dpe/instances?fields=name,health,currentPower,currentTemperature'); } sub check { diff --git a/storage/emc/unisphere/restapi/mode/components/fan.pm b/storage/emc/unisphere/restapi/mode/components/fan.pm index 468b575e1..f0b58d325 100644 --- a/storage/emc/unisphere/restapi/mode/components/fan.pm +++ b/storage/emc/unisphere/restapi/mode/components/fan.pm @@ -27,7 +27,7 @@ use storage::emc::unisphere::restapi::mode::components::resources qw($health_sta sub load { my ($self) = @_; - $self->{json_results}->{fans} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/fan/instances'); + $self->{json_results}->{fans} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/fan/instances?fields=health'); } sub check { diff --git a/storage/emc/unisphere/restapi/mode/components/iomodule.pm b/storage/emc/unisphere/restapi/mode/components/iomodule.pm index 9c3584859..b017f5153 100644 --- a/storage/emc/unisphere/restapi/mode/components/iomodule.pm +++ b/storage/emc/unisphere/restapi/mode/components/iomodule.pm @@ -27,7 +27,7 @@ use storage::emc::unisphere::restapi::mode::components::resources qw($health_sta sub load { my ($self) = @_; - $self->{json_results}->{iomodules} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/ioModule/instances'); + $self->{json_results}->{iomodules} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/ioModule/instances?fields=name,health'); } sub check { diff --git a/storage/emc/unisphere/restapi/mode/components/psu.pm b/storage/emc/unisphere/restapi/mode/components/psu.pm index 493f6cb4f..17506c514 100644 --- a/storage/emc/unisphere/restapi/mode/components/psu.pm +++ b/storage/emc/unisphere/restapi/mode/components/psu.pm @@ -27,7 +27,7 @@ use storage::emc::unisphere::restapi::mode::components::resources qw($health_sta sub load { my ($self) = @_; - $self->{json_results}->{psus} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/powerSupply/instances'); + $self->{json_results}->{psus} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/powerSupply/instances?fields=name,health'); } sub check { diff --git a/storage/emc/unisphere/restapi/mode/components/sp.pm b/storage/emc/unisphere/restapi/mode/components/sp.pm index fda696a87..3d98d42c2 100644 --- a/storage/emc/unisphere/restapi/mode/components/sp.pm +++ b/storage/emc/unisphere/restapi/mode/components/sp.pm @@ -27,7 +27,7 @@ use storage::emc::unisphere::restapi::mode::components::resources qw($health_sta sub load { my ($self) = @_; - $self->{json_results}->{sp} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/storageProcessor/instances'); + $self->{json_results}->{sp} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/storageProcessor/instances?fields=health'); } sub check { diff --git a/storage/emc/unisphere/restapi/mode/components/ssd.pm b/storage/emc/unisphere/restapi/mode/components/ssd.pm index 900475de2..49cd8760b 100644 --- a/storage/emc/unisphere/restapi/mode/components/ssd.pm +++ b/storage/emc/unisphere/restapi/mode/components/ssd.pm @@ -27,7 +27,7 @@ use storage::emc::unisphere::restapi::mode::components::resources qw($health_sta sub load { my ($self) = @_; - $self->{json_results}->{ssd} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/ssd/instances'); + $self->{json_results}->{ssd} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/ssd/instances?fields=health'); } sub check { diff --git a/storage/emc/unisphere/restapi/mode/listpools.pm b/storage/emc/unisphere/restapi/mode/listpools.pm index df1bce6ff..e3c7c7d86 100644 --- a/storage/emc/unisphere/restapi/mode/listpools.pm +++ b/storage/emc/unisphere/restapi/mode/listpools.pm @@ -46,7 +46,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - return $options{custom}->request_api(url_path => '/api/types/pool/instances'); + return $options{custom}->request_api(url_path => '/api/types/pool/instances?fields=name,health'); } sub run { diff --git a/storage/emc/unisphere/restapi/mode/liststorageresources.pm b/storage/emc/unisphere/restapi/mode/liststorageresources.pm index 6718703c4..49c9e91ab 100644 --- a/storage/emc/unisphere/restapi/mode/liststorageresources.pm +++ b/storage/emc/unisphere/restapi/mode/liststorageresources.pm @@ -46,7 +46,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - return $options{custom}->request_api(url_path => '/api/types/storageResource/instances'); + return $options{custom}->request_api(url_path => '/api/types/storageResource/instances?fields=name,health'); } sub run { diff --git a/storage/emc/unisphere/restapi/mode/pools.pm b/storage/emc/unisphere/restapi/mode/pools.pm index 97c128ad6..80c406091 100644 --- a/storage/emc/unisphere/restapi/mode/pools.pm +++ b/storage/emc/unisphere/restapi/mode/pools.pm @@ -159,7 +159,7 @@ sub prefix_pool_output { sub manage_selection { my ($self, %options) = @_; - my $results = $options{custom}->request_api(url_path => '/api/types/pool/instances'); + my $results = $options{custom}->request_api(url_path => '/api/types/pool/instances?fields=name,sizeFree,sizeSubscribed,sizeTotal,health'); $self->{pool} = {}; foreach (@{$results->{entries}}) { diff --git a/storage/emc/unisphere/restapi/mode/storageresources.pm b/storage/emc/unisphere/restapi/mode/storageresources.pm index 4dac3db47..04b5810de 100644 --- a/storage/emc/unisphere/restapi/mode/storageresources.pm +++ b/storage/emc/unisphere/restapi/mode/storageresources.pm @@ -68,7 +68,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'sr', type => 1, cb_prefix_output => 'prefix_sr_output', message_multiple => 'All storage resources are ok' }, + { name => 'sr', type => 1, cb_prefix_output => 'prefix_sr_output', message_multiple => 'All storage resources are ok', skipped_code => { -10 => 1 } }, ]; $self->{maps_counters}->{sr} = [ @@ -159,7 +159,7 @@ sub prefix_sr_output { sub manage_selection { my ($self, %options) = @_; - my $results = $options{custom}->request_api(url_path => '/api/types/storageResource/instances'); + my $results = $options{custom}->request_api(url_path => '/api/types/storageResource/instances?fields=name,health,sizeUsed,sizeAllocated,sizeTotal'); $self->{sr} = {}; foreach (@{$results->{entries}}) { @@ -173,16 +173,20 @@ sub manage_selection { display => $_->{content}->{name}, status => $health_status->{ $_->{content}->{health}->{value} }, total_space => $_->{content}->{sizeTotal}, - used_space => $_->{content}->{sizeUsed}, - free_space => $_->{content}->{sizeTotal} - $_->{content}->{sizeUsed}, - prct_used_space => $_->{content}->{sizeUsed} * 100 / $_->{content}->{sizeTotal}, - prct_free_space => 100 - ($_->{content}->{sizeUsed} * 100 / $_->{content}->{sizeTotal}), - - used_alloc => $_->{content}->{sizeAllocated}, - free_alloc => $_->{content}->{sizeTotal} - $_->{content}->{sizeAllocated}, - prct_used_alloc => $_->{content}->{sizeAllocated} * 100 / $_->{content}->{sizeTotal}, - prct_free_alloc => 100 - ($_->{content}->{sizeAllocated} * 100 / $_->{content}->{sizeTotal}), }; + + if (defined($_->{content}->{sizeUsed})) { + $self->{sr}->{$_->{content}->{id}}->{used_space} = $_->{content}->{sizeUsed}; + $self->{sr}->{$_->{content}->{id}}->{free_space} = $_->{content}->{sizeTotal} - $_->{content}->{sizeUsed}; + $self->{sr}->{$_->{content}->{id}}->{prct_used_space} = $_->{content}->{sizeUsed} * 100 / $_->{content}->{sizeTotal}; + $self->{sr}->{$_->{content}->{id}}->{prct_free_space} = 100 - ($_->{content}->{sizeUsed} * 100 / $_->{content}->{sizeTotal}); + } + if (defined($_->{content}->{sizeAllocated})) { + $self->{sr}->{$_->{content}->{id}}->{used_alloc} = $_->{content}->{sizeAllocated}; + $self->{sr}->{$_->{content}->{id}}->{free_alloc} = $_->{content}->{sizeTotal} - $_->{content}->{sizeAllocated}; + $self->{sr}->{$_->{content}->{id}}->{prct_used_alloc} = $_->{content}->{sizeAllocated} * 100 / $_->{content}->{sizeTotal}; + $self->{sr}->{$_->{content}->{id}}->{prct_free_alloc} = 100 - ($_->{content}->{sizeAllocated} * 100 / $_->{content}->{sizeTotal}); + } } if (scalar(keys %{$self->{sr}}) <= 0) {