enhance emc unisphere

This commit is contained in:
garnier-quentin 2020-12-01 11:33:41 +01:00
parent 789c44c2a9
commit 562c90650d
6 changed files with 121 additions and 138 deletions

View File

@ -25,9 +25,10 @@ use warnings;
use Exporter; use Exporter;
our $health_status; our $health_status;
our $replication_status;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT_OK = qw($health_status); our @EXPORT_OK = qw($health_status $replication_status);
$health_status = { $health_status = {
0 => 'unknown', 0 => 'unknown',

View File

@ -32,7 +32,7 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' }
}); });
return $self; return $self;
@ -45,7 +45,7 @@ sub check_options {
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
return $options{custom}->request_api(url_path => '/api/types/replicationSession/instances?fields=name,health,syncState,srcResourceId,dstResourceId'); return $options{custom}->request_api(url_path => '/api/types/replicationSession/instances?fields=name,health,syncState,srcResourceId,dstResourceId');
} }
@ -57,14 +57,16 @@ sub run {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $_->{content}->{name} !~ /$self->{option_results}->{filter_name}/); && $_->{content}->{name} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf( $self->{output}->output_add(
'[name = %s][health_status = %s][sync_status = %s][source_id = %s][destination_id = %s]', long_msg => sprintf(
$_->{content}->{name}, '[name = %s][health_status = %s][sync_status = %s][source_id = %s][destination_id = %s]',
$health_status->{ $_->{content}->{health}->{value} }, $_->{content}->{name},
$replication_status->{ $_->{content}->{syncState} }, $health_status->{ $_->{content}->{health}->{value} },
$_->{content}->{srcResourceId}, $replication_status->{ $_->{content}->{syncState} },
$_->{content}->{dstResourceId}, $_->{content}->{srcResourceId},
)); $_->{content}->{dstResourceId}
)
);
} }
$self->{output}->output_add( $self->{output}->output_add(
@ -77,8 +79,8 @@ sub run {
sub disco_format { sub disco_format {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name','health_status','sync_status','source_id','destination_id']); $self->{output}->add_disco_format(elements => ['name', 'health_status', 'sync_status', 'source_id', 'destination_id']);
} }
sub disco_show { sub disco_show {
@ -91,7 +93,7 @@ sub disco_show {
health_status => $health_status->{ $_->{content}->{health}->{value} }, health_status => $health_status->{ $_->{content}->{health}->{value} },
sync_status => $replication_status->{ $_->{content}->{syncState} }, sync_status => $replication_status->{ $_->{content}->{syncState} },
source_id => $_->{content}->{srcResourceId}, source_id => $_->{content}->{srcResourceId},
destination_id => $_->{content}->{dstResourceId}, destination_id => $_->{content}->{dstResourceId}
); );
} }
} }

View File

@ -25,13 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); use storage::emc::unisphere::restapi::mode::components::resources qw($health_status);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status}; return 'status : ' . $self->{result_values}->{status};
return $msg;
} }
sub custom_usage_output { sub custom_usage_output {
@ -40,12 +39,12 @@ sub custom_usage_output {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space}); my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
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 ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space});
my $msg = sprintf('space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', return sprintf(
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space} $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space}
); );
return $msg;
} }
sub custom_subscribed_output { sub custom_subscribed_output {
@ -56,75 +55,80 @@ sub custom_subscribed_output {
$self->{result_values}->{free_sub} = 0 if ($self->{result_values}->{free_sub} < 0); $self->{result_values}->{free_sub} = 0 if ($self->{result_values}->{free_sub} < 0);
$self->{result_values}->{prct_free_sub} = 0 if ($self->{result_values}->{prct_free_sub} < 0); $self->{result_values}->{prct_free_sub} = 0 if ($self->{result_values}->{prct_free_sub} < 0);
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_sub}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_sub});
my $msg = sprintf('subscribed usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', return sprintf(
$total_size_value . " " . $total_size_unit, 'subscribed usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_sub}, $total_size_value . " " . $total_size_unit,
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_sub} $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_sub},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_sub}
); );
return $msg;
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok' }, { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok' }
]; ];
$self->{maps_counters}->{pool} = [ $self->{maps_counters}->{pool} = [
{ label => 'status', threshold => 0, set => { {
label => 'status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /ok_but|degraded|minor/i',
critical_default => '%{status} =~ /major|critical|non_recoverable/i',
set => {
key_values => [ { name => 'status' }, { name => 'display' } ], key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'usage', nlabel => 'pool.space.usage.bytes', set => { { label => 'usage', nlabel => 'pool.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' }, ], 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'), closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [ perfdatas => [
{ value => 'used_space', template => '%d', min => 0, max => 'total_space', { template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { { label => 'usage-free', nlabel => 'pool.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' }, ], 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'), closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [ perfdatas => [
{ value => 'free_space', template => '%d', min => 0, max => 'total_space', { template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => { { label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], key_values => [ { name => 'prct_used_space' }, { name => 'display' } ],
output_template => 'used : %.2f %%', output_template => 'used : %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'prct_used_space', template => '%.2f', min => 0, max => 100, { template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' }, unit => '%', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'subscribed', nlabel => 'pool.subscribed.usage.bytes', display_ok => 0, set => { { label => 'subscribed', nlabel => 'pool.subscribed.usage.bytes', display_ok => 0, set => {
key_values => [ { name => 'used_sub' }, { name => 'free_sub' }, { name => 'prct_used_sub' }, { name => 'prct_free_sub' }, { name => 'total_space' }, { name => 'display' }, ], key_values => [ { name => 'used_sub' }, { name => 'free_sub' }, { name => 'prct_used_sub' }, { name => 'prct_free_sub' }, { name => 'total_space' }, { name => 'display' }, ],
closure_custom_output => $self->can('custom_subscribed_output'), closure_custom_output => $self->can('custom_subscribed_output'),
perfdatas => [ perfdatas => [
{ value => 'used_sub', template => '%d', min => 0, max => 'total_space', { template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'subscribed-prct', display_ok => 0, nlabel => 'pool.subscribed.usage.percentage', set => { { label => 'subscribed-prct', display_ok => 0, nlabel => 'pool.subscribed.usage.percentage', set => {
key_values => [ { name => 'prct_used_sub' }, { name => 'display' } ], key_values => [ { name => 'prct_used_sub' }, { name => 'display' } ],
output_template => 'subcribed used : %.2f %%', output_template => 'subcribed used : %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'prct_used_sub', template => '%.2f', min => 0, max => 100, { template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' }, unit => '%', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
} }
@ -134,22 +138,12 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' }
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' },
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /ok_but|degraded|minor/i' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /major|critical|non_recoverable/i' },
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
}
sub prefix_pool_output { sub prefix_pool_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -185,7 +179,7 @@ sub manage_selection {
prct_free_sub => 100 - ($_->{content}->{sizeSubscribed} * 100 / $_->{content}->{sizeTotal}), prct_free_sub => 100 - ($_->{content}->{sizeSubscribed} * 100 / $_->{content}->{sizeTotal}),
}; };
} }
if (scalar(keys %{$self->{pool}}) <= 0) { if (scalar(keys %{$self->{pool}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No pool found"); $self->{output}->add_option_msg(short_msg => "No pool found");
$self->{output}->option_exit(); $self->{output}->option_exit();

View File

@ -25,46 +25,54 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use storage::emc::unisphere::restapi::mode::components::resources qw($replication_status $health_status); use storage::emc::unisphere::restapi::mode::components::resources qw($replication_status $health_status);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_health_status_output { sub custom_health_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'health status : ' . $self->{result_values}->{health_status}; return 'health status: ' . $self->{result_values}->{health_status};
return $msg;
} }
sub custom_replication_status_output { sub custom_replication_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'replication status : ' . $self->{result_values}->{repl_status}; return 'replication status: ' . $self->{result_values}->{repl_status};
return $msg;
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'replication', type => 1, cb_prefix_output => 'prefix_replication_output', message_multiple => 'All replications are ok' }, { name => 'replication', type => 1, cb_prefix_output => 'prefix_replication_output', message_multiple => 'All replications are ok' }
]; ];
$self->{maps_counters}->{replication} = [ $self->{maps_counters}->{replication} = [
{ label => 'health-status', threshold => 0, set => { {
label => 'health-status',
type => 2,
unknown_default => '%{health_status} =~ /unknown/i',
warning_default => '%{health_status} =~ /ok_but|degraded|minor/i',
critical_default => '%{health_status} =~ /major|critical|non_recoverable/i',
set => {
key_values => [ { name => 'health_status' }, { name => 'display' } ], key_values => [ { name => 'health_status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_health_status_output'), closure_custom_output => $self->can('custom_health_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'replication-status', threshold => 0, set => { {
label => 'replication-status',
type => 2,
unknown_default => '%{repl_status} =~ /unknown/i',
warning_default => '%{repl_status} =~ /syncing/i',
critical_default => '%{repl_status} =~ /inconsistent/i',
set => {
key_values => [ { name => 'repl_status' }, { name => 'display' } ], key_values => [ { name => 'repl_status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_replication_status_output'), closure_custom_output => $self->can('custom_replication_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, }
]; ];
} }
@ -74,28 +82,12 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' }
'unknown-health-status:s' => { name => 'unknown_health_status', default => '%{health_status} =~ /unknown/i' },
'warning-health-status:s' => { name => 'warning_health_status', default => '%{health_status} =~ /ok_but|degraded|minor/i' },
'critical-health-status:s' => { name => 'critical_health_status', default => '%{health_status} =~ /major|critical|non_recoverable/i' },
'unknown-replication-status:s' => { name => 'unknown_repl_status', default => '%{repl_status} =~ /unknown/i' },
'warning-replication-status:s' => { name => 'warning_repl_status', default => '%{repl_status} =~ /syncing/i' },
'critical-replication-status:s' => { name => 'critical_repl_status', default => '%{repl_status} =~ /inconsistent/i' },
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => [
'warning_health_status', 'critical_health_status', 'unknown_health_status',
'warning_repl_status', 'critical_repl_status', 'unknown_repl_status',
]);
}
sub prefix_replication_output { sub prefix_replication_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -115,13 +107,13 @@ sub manage_selection {
next; next;
} }
$self->{replication}->{$_->{content}->{id}} = { $self->{replication}->{ $_->{content}->{id} } = {
display => $_->{content}->{name}, display => $_->{content}->{name},
health_status => $health_status->{ $_->{content}->{health}->{value} }, health_status => $health_status->{ $_->{content}->{health}->{value} },
repl_status => $replication_status->{ $_->{content}->{syncState} } }, repl_status => $replication_status->{ $_->{content}->{syncState} } },
}; };
} }
if (scalar(keys %{$self->{replication}}) <= 0) { if (scalar(keys %{$self->{replication}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No replications found"); $self->{output}->add_option_msg(short_msg => "No replications found");
$self->{output}->option_exit(); $self->{output}->option_exit();
@ -149,7 +141,7 @@ Filter replication name (can be a regexp).
=item B<--unknown-health-status> =item B<--unknown-health-status>
Set warning threshold for status (Default: '%{health_status} =~ /unknown/i'). Set unknown threshold for status (Default: '%{health_status} =~ /unknown/i').
Can used special variables like: %{health_status}, %{display} Can used special variables like: %{health_status}, %{display}
=item B<--warning-health-status> =item B<--warning-health-status>
@ -164,7 +156,7 @@ Can used special variables like: %{health_status}, %{display}
=item B<--unknown-repl-status> =item B<--unknown-repl-status>
Set warning threshold for status (Default: '%{repl_status} =~ /unknown/i'). Set unknown threshold for status (Default: '%{repl_status} =~ /unknown/i').
Can used special variables like: %{repl_status}, %{display} Can used special variables like: %{repl_status}, %{display}
=item B<--warning-repl-status> =item B<--warning-repl-status>

View File

@ -25,13 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); use storage::emc::unisphere::restapi::mode::components::resources qw($health_status);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status}; return 'status : ' . $self->{result_values}->{status};
return $msg;
} }
sub custom_usage_output { sub custom_usage_output {
@ -40,12 +39,12 @@ sub custom_usage_output {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space}); my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
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 ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space});
my $msg = sprintf('space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', return sprintf(
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space} $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space}
); );
return $msg;
} }
sub custom_allocated_output { sub custom_allocated_output {
@ -56,46 +55,51 @@ sub custom_allocated_output {
$self->{result_values}->{free_alloc} = 0 if ($self->{result_values}->{free_alloc} < 0); $self->{result_values}->{free_alloc} = 0 if ($self->{result_values}->{free_alloc} < 0);
$self->{result_values}->{prct_free_alloc} = 0 if ($self->{result_values}->{prct_free_alloc} < 0); $self->{result_values}->{prct_free_alloc} = 0 if ($self->{result_values}->{prct_free_alloc} < 0);
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_alloc}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_alloc});
my $msg = sprintf('allocated usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', return sprintf(
$total_size_value . " " . $total_size_unit, 'allocated usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_alloc}, $total_size_value . " " . $total_size_unit,
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_alloc} $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_alloc},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_alloc}
); );
return $msg;
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'sr', type => 1, cb_prefix_output => 'prefix_sr_output', message_multiple => 'All storage resources are ok', skipped_code => { -10 => 1 } }, { 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} = [ $self->{maps_counters}->{sr} = [
{ label => 'status', threshold => 0, set => { {
label => 'status',
type => 2,
unknown_default => '%{health_status} =~ /unknown/i',
warning_default => '%{health_status} =~ /ok_but|degraded|minor/i',
critical_default => '%{health_status} =~ /major|critical|non_recoverable/i',
set => {
key_values => [ { name => 'status' }, { name => 'display' } ], key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'usage', nlabel => 'storageresource.space.usage.bytes', set => { { label => 'usage', nlabel => 'storageresource.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' }, ], 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'), closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [ perfdatas => [
{ value => 'used_space', template => '%d', min => 0, max => 'total_space', { template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'usage-free', nlabel => 'storageresource.space.free.bytes', display_ok => 0, set => { { label => 'usage-free', nlabel => 'storageresource.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' }, ], 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'), closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [ perfdatas => [
{ value => 'free_space', template => '%d', min => 0, max => 'total_space', { template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'usage-prct', nlabel => 'storageresource.space.usage.percentage', display_ok => 0, set => { { label => 'usage-prct', nlabel => 'storageresource.space.usage.percentage', display_ok => 0, set => {
@ -103,28 +107,28 @@ sub set_counters {
output_template => 'used : %.2f %%', output_template => 'used : %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'prct_used_space', template => '%.2f', min => 0, max => 100, { value => 'prct_used_space', template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' }, unit => '%', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'allocated', nlabel => 'storageresource.allocated.usage.bytes', display_ok => 0, set => { { label => 'allocated', nlabel => 'storageresource.allocated.usage.bytes', display_ok => 0, set => {
key_values => [ { name => 'used_alloc' }, { name => 'free_alloc' }, { name => 'prct_used_alloc' }, { name => 'prct_free_alloc' }, { name => 'total_space' }, { name => 'display' }, ], key_values => [ { name => 'used_alloc' }, { name => 'free_alloc' }, { name => 'prct_used_alloc' }, { name => 'prct_free_alloc' }, { name => 'total_space' }, { name => 'display' }, ],
closure_custom_output => $self->can('custom_allocated_output'), closure_custom_output => $self->can('custom_allocated_output'),
perfdatas => [ perfdatas => [
{ value => 'used_alloc', template => '%d', min => 0, max => 'total_space', { template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'allocated-prct', display_ok => 0, nlabel => 'storageresource.allocated.usage.percentage', set => { { label => 'allocated-prct', display_ok => 0, nlabel => 'storageresource.allocated.usage.percentage', set => {
key_values => [ { name => 'prct_used_alloc' }, { name => 'display' } ], key_values => [ { name => 'prct_used_alloc' }, { name => 'display' } ],
output_template => 'allocated used : %.2f %%', output_template => 'allocated used : %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'prct_used_alloc', template => '%.2f', min => 0, max => 100, { template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' }, unit => '%', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
} }
@ -134,22 +138,12 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' }
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' },
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /ok_but|degraded|minor/i' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /major|critical|non_recoverable/i' },
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
}
sub prefix_sr_output { sub prefix_sr_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -188,7 +182,7 @@ sub manage_selection {
$self->{sr}->{$_->{content}->{id}}->{prct_free_alloc} = 100 - ($_->{content}->{sizeAllocated} * 100 / $_->{content}->{sizeTotal}); $self->{sr}->{$_->{content}->{id}}->{prct_free_alloc} = 100 - ($_->{content}->{sizeAllocated} * 100 / $_->{content}->{sizeTotal});
} }
} }
if (scalar(keys %{$self->{sr}}) <= 0) { if (scalar(keys %{$self->{sr}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No storage resource found"); $self->{output}->add_option_msg(short_msg => "No storage resource found");
$self->{output}->option_exit(); $self->{output}->option_exit();

View File

@ -30,17 +30,17 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{version} = '0.1';
%{ $self->{modes} } = ( $self->{modes} = {
'hardware' => 'storage::emc::unisphere::restapi::mode::hardware', 'hardware' => 'storage::emc::unisphere::restapi::mode::hardware',
'list-pools' => 'storage::emc::unisphere::restapi::mode::listpools', 'list-pools' => 'storage::emc::unisphere::restapi::mode::listpools',
'list-replications' => 'storage::emc::unisphere::restapi::mode::listreplications', 'list-replications' => 'storage::emc::unisphere::restapi::mode::listreplications',
'list-storage-resources' => 'storage::emc::unisphere::restapi::mode::liststorageresources', 'list-storage-resources' => 'storage::emc::unisphere::restapi::mode::liststorageresources',
'pools' => 'storage::emc::unisphere::restapi::mode::pools', 'pools' => 'storage::emc::unisphere::restapi::mode::pools',
'replications' => 'storage::emc::unisphere::restapi::mode::replications', 'replications' => 'storage::emc::unisphere::restapi::mode::replications',
'storage-resources' => 'storage::emc::unisphere::restapi::mode::storageresources', 'storage-resources' => 'storage::emc::unisphere::restapi::mode::storageresources'
); };
$self->{custom_modes}{api} = 'storage::emc::unisphere::restapi::custom::api'; $self->{custom_modes}->{api} = 'storage::emc::unisphere::restapi::custom::api';
return $self; return $self;
} }