From 9b0495633eb7a4fda4d3c91a4c7481d592df3eae Mon Sep 17 00:00:00 2001 From: lchrdn <89968908+lchrdn@users.noreply.github.com> Date: Mon, 7 Nov 2022 16:23:19 +0100 Subject: [PATCH] (plugin) storage::netapp:ontap::restapi - fix missing counters for space usage and bug in listvolumes (#4041) * fix missing filter option and missing counters * fix 'uninitialized value in sprintf' in listvol --- .../netapp/ontap/restapi/mode/aggregates.pm | 34 +++++++++++++++++++ .../netapp/ontap/restapi/mode/listvolumes.pm | 8 +++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/storage/netapp/ontap/restapi/mode/aggregates.pm b/centreon-plugins/storage/netapp/ontap/restapi/mode/aggregates.pm index 5f2b45f39..e430f08e9 100644 --- a/centreon-plugins/storage/netapp/ontap/restapi/mode/aggregates.pm +++ b/centreon-plugins/storage/netapp/ontap/restapi/mode/aggregates.pm @@ -73,6 +73,33 @@ sub set_counters { closure_custom_threshold_check => \&catalog_status_threshold_ng } }, + { label => 'usage', nlabel => 'aggregate.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space', template => '%d', min => 0, max => 'total_space', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'usage-free', nlabel => 'aggregate.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space', template => '%d', min => 0, max => 'total_space', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'usage-prct', nlabel => 'aggregate.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'prct_used_space', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, { label => 'read', nlabel => 'aggregate.io.read.usage.bytespersecond', display_ok => 0, set => { key_values => [ { name => 'read' } ], output_template => 'read: %s %s/s', @@ -183,6 +210,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, }); return $self; @@ -195,6 +223,8 @@ sub manage_selection { $self->{aggregates} = {}; foreach (@{$aggregates->{records}}) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_name}/); my $name = $_->{name}; my $uuid = $_->{uuid}; @@ -206,6 +236,10 @@ sub manage_selection { total_space => $_->{space}->{block_storage}->{size}, used_space => $_->{space}->{block_storage}->{used}, free_space => $_->{space}->{block_storage}->{available}, + prct_used_space => + ($_->{space}->{block_storage}->{used} * 100 / $_->{space}->{block_storage}->{size}), + prct_free_space => + ($_->{space}->{block_storage}->{available} * 100 / $_->{space}->{block_storage}->{size}), read => $agg->{metric}->{throughput}->{read}, write => $agg->{metric}->{throughput}->{write}, other => $agg->{metric}->{throughput}->{other}, diff --git a/centreon-plugins/storage/netapp/ontap/restapi/mode/listvolumes.pm b/centreon-plugins/storage/netapp/ontap/restapi/mode/listvolumes.pm index ec16bf06f..67cd70132 100644 --- a/centreon-plugins/storage/netapp/ontap/restapi/mode/listvolumes.pm +++ b/centreon-plugins/storage/netapp/ontap/restapi/mode/listvolumes.pm @@ -53,10 +53,11 @@ sub run { my $volumes = $self->manage_selection(%options); foreach (@{$volumes->{records}}) { my $vserver_name = defined($_->{svm}) && $_->{svm}->{name} ne '' ? $_->{svm}->{name} : '-'; + my $volume_state = defined($_->{state}) && $_->{state} ne '' ? $_->{state} : '-'; $self->{output}->output_add(long_msg => sprintf( '[name = %s][state = %s][vserver = %s]', $_->{name}, - $_->{state}, + $volume_state, $vserver_name )); } @@ -81,10 +82,11 @@ sub disco_show { my $volumes = $self->manage_selection(%options); foreach (@{$volumes->{records}}) { my $vserver_name = defined($_->{svm}) && $_->{svm}->{name} ne '' ? $_->{svm}->{name} : '-'; + my $volume_state = defined($_->{state}) && $_->{state} ne '' ? $_->{state} : '-'; $self->{output}->add_disco_entry( name => $_->{name}, - state => $_->{state}, - vserver_name => $_->{svm}->{name} + state => $volume_state, + vserver_name => $vserver_name ); } }