(plugin) cloud::azure::storage::storageaccount - mode file-share-quota fix used value (#4206)

This commit is contained in:
qgarnier 2023-02-08 14:57:06 +00:00 committed by GitHub
parent 5f43c84bf8
commit 83a86c3d05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,9 +28,8 @@ use warnings;
sub custom_usage_perfdata { sub custom_usage_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
my $label = 'capacity-usage';
my $value_perf = $self->{result_values}->{used_space}; my $value_perf = $self->{result_values}->{used_space};
my %total_options = (); my %total_options = ();
if ($self->{instance_mode}->{option_results}->{units} eq '%') { if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{total_capacity}; $total_options{total} = $self->{result_values}->{total_capacity};
@ -38,12 +37,12 @@ sub custom_usage_perfdata {
} }
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => $label, unit => 'B', nlabel => 'fileshare.capacity.usage.bytes',
nlabel => 'fileshare.capacity.usage.bytes', unit => 'B',
value => $value_perf, value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
min => 0, max => $self->{result_values}->{total_capacity}, min => 0, max => $self->{result_values}->{total_capacity}
); );
} }
@ -55,9 +54,13 @@ sub custom_usage_threshold {
if ($self->{instance_mode}->{option_results}->{units} eq '%') { if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used}; $threshold_value = $self->{result_values}->{prct_used};
} }
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, $exit = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, value => $threshold_value,
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]); threshold => [
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
]
);
return $exit; return $exit;
} }
@ -66,11 +69,13 @@ sub custom_usage_output {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_capacity} ); my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_capacity} );
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space} ); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space} );
my $msg = sprintf("Fileshare '%s' from storage account '%s' used capacity: %s (%.2f%%), total size %s", my $msg = sprintf(
$self->{result_values}->{fileshare}, "Fileshare '%s' from storage account '%s' used capacity: %s (%.2f%%), total size %s",
$self->{result_values}->{storageaccount}, $self->{result_values}->{fileshare},
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $self->{result_values}->{storageaccount},
$total_size_value . " " . $total_size_unit); $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_size_value . " " . $total_size_unit
);
return $msg; return $msg;
} }
@ -89,7 +94,7 @@ sub custom_usage_calc {
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'fileshare', type => 0 } { name => 'fileshare', type => 0 }
]; ];
@ -100,7 +105,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'), closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'), closure_custom_threshold_check => $self->can('custom_usage_threshold')
} }
} }
] ]
@ -111,13 +116,12 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'resource-group:s' => { name => 'resource_group' },
"resource-group:s" => { name => 'resource_group' }, 'storage-account:s' => { name => 'storage_account' },
"storage-account:s" => { name => 'storage_account' }, 'units:s' => { name => 'units', default => '%' },
"units:s" => { name => 'units', default => '%' }, 'fileshare:s' => { name => 'fileshare' }
"fileshare:s" => { name => 'fileshare' } });
});
return $self; return $self;
} }
@ -140,21 +144,22 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Need to specify --fileshare <name>"); $self->{output}->add_option_msg(short_msg => "Need to specify --fileshare <name>");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $results; my $results;
$results = $options{custom}->azure_get_file_share_stats(resource_group => $self->{option_results}->{resource_group}, storage_account => $self->{option_results}->{storage_account}, $results = $options{custom}->azure_get_file_share_stats(
fileshare => $self->{option_results}->{fileshare}, api_version => $self->{api_version}); resource_group => $self->{option_results}->{resource_group}, storage_account => $self->{option_results}->{storage_account},
fileshare => $self->{option_results}->{fileshare}, api_version => $self->{api_version}
);
$self->{fileshare} = { $self->{fileshare} = {
storage_account => $self->{option_results}->{storage_account}, storage_account => $self->{option_results}->{storage_account},
fileshare => $self->{option_results}->{fileshare}, fileshare => $self->{option_results}->{fileshare},
total_capacity => $results->{properties}->{shareQuota}, total_capacity => $results->{properties}->{shareQuota},
used_space => $results->{properties}->{shareUsageBytes} * 1024 ** 3 used_space => $results->{properties}->{shareUsageBytes}
}; };
if (scalar(keys %{$self->{fileshare}}) <= 0) { if (scalar(keys %{$self->{fileshare}}) <= 0) {