From 4a7e0a0eabdb1c0998ebcc9cd4c7937c2eab1933 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 21 Dec 2020 11:01:55 +0100 Subject: [PATCH] enhance netapp ontap rest api volumes --- storage/netapp/ontap/restapi/mode/cluster.pm | 18 +++--------- storage/netapp/ontap/restapi/mode/luns.pm | 18 +++--------- .../netapp/ontap/restapi/mode/snapmirrors.pm | 18 +++--------- storage/netapp/ontap/restapi/mode/volumes.pm | 28 ++++++------------- 4 files changed, 21 insertions(+), 61 deletions(-) diff --git a/storage/netapp/ontap/restapi/mode/cluster.pm b/storage/netapp/ontap/restapi/mode/cluster.pm index 0085e5b71..be0da1891 100644 --- a/storage/netapp/ontap/restapi/mode/cluster.pm +++ b/storage/netapp/ontap/restapi/mode/cluster.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use Digest::MD5 qw(md5_hex); sub custom_status_output { @@ -121,11 +121,11 @@ sub set_counters { ]; $self->{maps_counters}->{nodes} = [ - { label => 'node-status', threshold => 0, set => { + { label => 'node-status', type => 2, critical_default => '%{state} ne "online"', set => { key_values => [ { name => 'state' }, { name => 'link_status' }, { name => 'display' } ], 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 } } ]; @@ -136,22 +136,12 @@ 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-node-status:s' => { name => 'unknown_node_status', default => '' }, - 'warning-node-status:s' => { name => 'warning_node_status', default => '' }, - 'critical-node-status:s' => { name => 'critical_node_status', default => '%{state} ne "online"' } + $options{options}->add_options(arguments => { }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_node_status', 'critical_node_status', 'unknown_node_status']); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/storage/netapp/ontap/restapi/mode/luns.pm b/storage/netapp/ontap/restapi/mode/luns.pm index 104cd72b2..9cf25cccd 100644 --- a/storage/netapp/ontap/restapi/mode/luns.pm +++ b/storage/netapp/ontap/restapi/mode/luns.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -50,11 +50,11 @@ sub set_counters { ]; $self->{maps_counters}->{luns} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{state} !~ /online/i', set => { key_values => [ { name => 'state' }, { name => 'container_state' }, { name => 'display' } ], 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 } } ]; @@ -66,22 +66,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' }, - 'unknown-status:s' => { name => 'unknown_status', default => '' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /online/i' } + 'filter-name:s' => { name => 'filter_name' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/storage/netapp/ontap/restapi/mode/snapmirrors.pm b/storage/netapp/ontap/restapi/mode/snapmirrors.pm index 31d223d96..c98672e8f 100644 --- a/storage/netapp/ontap/restapi/mode/snapmirrors.pm +++ b/storage/netapp/ontap/restapi/mode/snapmirrors.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -51,11 +51,11 @@ sub set_counters { ]; $self->{maps_counters}->{snapmirrors} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{healthy} ne "true" or %{state} eq "broken_off"', set => { key_values => [ { name => 'healthy' }, { name => 'state' }, { name => 'transfer_state' }, { name => 'display' } ], 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 } } ]; @@ -67,22 +67,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' }, - 'unknown-status:s' => { name => 'unknown_status', default => '' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{healthy} ne "true" or %{state} eq "broken_off"' } + 'filter-name:s' => { name => 'filter_name' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/storage/netapp/ontap/restapi/mode/volumes.pm b/storage/netapp/ontap/restapi/mode/volumes.pm index c90dd6976..d35257e63 100644 --- a/storage/netapp/ontap/restapi/mode/volumes.pm +++ b/storage/netapp/ontap/restapi/mode/volumes.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -60,11 +60,11 @@ sub set_counters { ]; $self->{maps_counters}->{volumes} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{state} !~ /online/i', set => { key_values => [ { name => 'state' }, { name => 'display' } ], 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 } }, { label => 'usage', nlabel => 'volume.space.usage.bytes', set => { @@ -86,8 +86,8 @@ sub set_counters { } }, { label => 'usage-prct', nlabel => 'volume.space.usage.percentage', display_ok => 0, set => { - key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], - output_template => 'space used: %.2f %%', + key_values => [ { name => 'prct_used_space' }, { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } @@ -153,22 +153,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' }, - 'unknown-status:s' => { name => 'unknown_status', default => '' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /online/i' } + 'filter-name:s' => { name => 'filter_name' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); -} - sub manage_selection { my ($self, %options) = @_; @@ -189,8 +179,8 @@ sub manage_selection { total_space => $_->{space}->{size}, used_space => $_->{space}->{used}, free_space => $_->{space}->{available}, - prct_used_space => $_->{space}->{used} * 100 / $_->{space}->{size}, - prct_free_space => $_->{space}->{available} * 100 / $_->{space}->{size}, + prct_used_space => (defined($_->{space}->{size}) && $_->{space}->{size} > 0) ? $_->{space}->{used} * 100 / $_->{space}->{size} : undef, + prct_free_space => (defined($_->{space}->{size}) && $_->{space}->{size} > 0) ? $_->{space}->{available} * 100 / $_->{space}->{size} : undef, read => $_->{metric}->{throughput}->{read}, write => $_->{metric}->{throughput}->{write}, @@ -200,7 +190,7 @@ sub manage_selection { write_latency => $_->{metric}->{latency}->{write} }; } - + if (scalar(keys %{$self->{volumes}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No volume found"); $self->{output}->option_exit();