diff --git a/storage/dell/fluidfs/snmp/mode/volumeusage.pm b/storage/dell/fluidfs/snmp/mode/volumeusage.pm index e9d092b16..74fb6404f 100644 --- a/storage/dell/fluidfs/snmp/mode/volumeusage.pm +++ b/storage/dell/fluidfs/snmp/mode/volumeusage.pm @@ -211,7 +211,6 @@ Units of thresholds (Default: '%') ('%', 'B'). Thresholds are on free space left. - =back =cut diff --git a/storage/purestorage/restapi/custom/api.pm b/storage/purestorage/restapi/custom/api.pm index 5fe476a4a..01389dc05 100644 --- a/storage/purestorage/restapi/custom/api.pm +++ b/storage/purestorage/restapi/custom/api.pm @@ -130,14 +130,15 @@ sub settings { sub request_api { my ($self, %options) = @_; - my $response = $self->{http}->request(method => $options{method}, url_path => $options{url}, + my $content = $self->{http}->request(method => $options{method}, url_path => $options{url_path}, query_form_post => $options{query_form_post}, critical_status => '', warning_status => '', unknown_status => ''); + my $response = $self->{http}->get_response(); my $decoded; eval { - $decoded = decode_json($response); + $decoded = decode_json($content); }; if ($@) { - $self->{output}->output_add(long_msg => $response, debug => 1); + $self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); $self->{output}->option_exit(); } diff --git a/storage/purestorage/restapi/mode/volumeusage.pm b/storage/purestorage/restapi/mode/volumeusage.pm index 2b6c25061..b1c5964f1 100644 --- a/storage/purestorage/restapi/mode/volumeusage.pm +++ b/storage/purestorage/restapi/mode/volumeusage.pm @@ -25,6 +25,72 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my $instance_mode; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_size'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_volumes'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + sub set_counters { my ($self, %options) = @_; @@ -33,40 +99,39 @@ sub set_counters { ]; $self->{maps_counters}->{volume} = [ - { label => 'iops', set => { - key_values => [ { name => 'iops_avg' }, { name => 'display' } ], - output_template => 'Average IOPs : %s', + { label => 'usage', set => { + key_values => [ { name => 'display' }, { name => 'volumes' }, { name => 'size' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + { label => 'data-reduction', set => { + key_values => [ { name => 'data_reduction' }, { name => 'display' } ], + output_template => 'Data Reduction : %.3f', perfdatas => [ - { label => 'iops', value => 'iops_avg_absolute', template => '%s', - min => 0, unit => 'iops', label_extra_instance => 1, instance_use => 'display_absolute' }, + { label => 'data_reduction', value => 'data_reduction_absolute', template => '%.3f', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, - { label => 'throughput', set => { - key_values => [ { name => 'throughput_avg' }, { name => 'display' } ], - output_template => 'Average Throughput : %s %s', + { label => 'total-reduction', set => { + key_values => [ { name => 'total_reduction' }, { name => 'display' } ], + output_template => 'Total Reduction : %.3f', + perfdatas => [ + { label => 'total_reduction', value => 'total_reduction_absolute', template => '%.3f', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'snapshots', set => { + key_values => [ { name => 'snapshots' }, { name => 'display' } ], + output_template => 'Snapshots : %s %s', output_change_bytes => 1, perfdatas => [ - { label => 'throughput', value => 'throughput_avg_absolute', template => '%s', - min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - { label => 'latency-inner', set => { - key_values => [ { name => 'latency_inner' }, { name => 'display' } ], - output_template => 'Latency Inner : %.6fms', - perfdatas => [ - { label => 'latency_inner', value => 'latency_inner_absolute', template => '%.6f', - min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - { label => 'latency-outer', set => { - key_values => [ { name => 'latency_outer' }, { name => 'display' } ], - output_template => 'Latency Outer : %.6fms', - perfdatas => [ - { label => 'latency_outer', value => 'latency_outer_absolute', template => '%.6f', - min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display_absolute' }, + { label => 'snapshots', value => 'snapshots_absolute', template => '%s', + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, @@ -82,11 +147,20 @@ sub new { $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, }); return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + sub prefix_volume_output { my ($self, %options) = @_; @@ -98,10 +172,12 @@ sub manage_selection { $self->{volume} = {}; my $result = $options{custom}->get_object(path => '/volume?space=true'); - use Data::Dumper; - print Data::Dumper::Dumper($result); - exit(1); - foreach my $entry (@{$result->{hits}}) { + + #[ + # {"total": 328750479478, "name": "PURE-M50R2-ADM24-CLU04-Oracle-prod1", "system": null, "snapshots": 1454226866, "volumes": 327296252612, "data_reduction": 5.436245544153763, "size": 3298534883328, "shared_space": null, "thin_provisioning": 0.387090105873843, "total_reduction": 8.86956728264988} + # ... + #] + foreach my $entry (@{$result}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $entry->{volume_name} !~ /$self->{option_results}->{filter_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $entry->{volume_name} . "': no matching filter.", debug => 1); @@ -137,12 +213,20 @@ Filter volume name (can be a regexp). =item B<--warning-*> Threshold warning. -Can be: 'latency-inner', 'latency-outer', 'iops', 'throughput' +Can be: 'usage', 'data-reduction', 'total-reduction'. =item B<--critical-*> Threshold critical. -Can be: 'latency-inner', 'latency-outer', 'iops', 'throughput' +Can be: 'usage', 'data-reduction', 'total-reduction'. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. =back