enhance exagrid

This commit is contained in:
garnier-quentin 2020-10-14 15:37:05 +02:00
parent 5750a1c375
commit 93c59512cd
1 changed files with 37 additions and 53 deletions

View File

@ -24,20 +24,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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 { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'Server Status : ' . $self->{result_values}->{status}; return 'Server Status : ' . $self->{result_values}->{status};
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
return 0;
} }
sub custom_usage_perfdata { sub custom_usage_perfdata {
@ -60,7 +52,7 @@ sub custom_usage_perfdata {
sub custom_usage_threshold { sub custom_usage_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
return $exit; return $exit;
} }
@ -70,12 +62,13 @@ sub custom_usage_output {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); 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_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 ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("%s Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", return sprintf(
ucfirst($self->{result_values}->{label}), '%s Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit, ucfirst($self->{result_values}->{label}),
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_size_value . " " . $total_size_unit,
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
return $msg; $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
} }
sub custom_usage_calc { sub custom_usage_calc {
@ -90,9 +83,9 @@ sub custom_usage_calc {
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; $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}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
} else { } else {
$self->{result_values}->{free} = '0'; $self->{result_values}->{free} = 0;
$self->{result_values}->{prct_used} = '0'; $self->{result_values}->{prct_used} = 0;
$self->{result_values}->{prct_free} = '0'; $self->{result_values}->{prct_free} = 0;
} }
return 0; return 0;
} }
@ -101,16 +94,20 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'server', type => 0, message_separator => ' - ' }, { name => 'server', type => 0, message_separator => ' - ' }
]; ];
$self->{maps_counters}->{server} = [ $self->{maps_counters}->{server} = [
{ label => 'status', threshold => 0, set => { {
label => 'status',
type => 2,
warning_default => '%{status} =~ /warning/i',
critical_default => '%{status} =~ /error/i',
set => {
key_values => [ { name => 'status' } ], key_values => [ { name => 'status' } ],
closure_custom_calc => $self->can('custom_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 => 'landing-usage', set => { { label => 'landing-usage', set => {
@ -118,7 +115,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'landing' }, closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'landing' },
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')
} }
}, },
{ label => 'retention-usage', set => { { label => 'retention-usage', set => {
@ -126,7 +123,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'retention' }, closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'retention' },
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')
} }
}, },
]; ];
@ -137,49 +134,41 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /warning/i' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /error/i' },
}); });
return $self; return $self;
} }
sub check_options { my $map_status = {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
my %map_status = (
1 => 'ok', 1 => 'ok',
2 => 'warning', 2 => 'warning',
3 => 'error', 3 => 'error'
); };
my $mapping = { my $mapping = {
egLandingSpaceConfiguredWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.1.1' }, egLandingSpaceConfiguredWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.1.1' },
egLandingSpaceAvailableWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.1.3' }, egLandingSpaceAvailableWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.1.3' },
egRetentionSpaceConfiguredWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.2.1' }, egRetentionSpaceConfiguredWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.2.1' },
egRetentionSpaceAvailableWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.2.3' }, egRetentionSpaceAvailableWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.2.3' },
egServerAlarmState => { oid => '.1.3.6.1.4.1.14941.4.6.1', map => \%map_status }, egServerAlarmState => { oid => '.1.3.6.1.4.1.14941.4.6.1', map => $map_status }
}; };
my $oid_exagridServerData = '.1.3.6.1.4.1.14941.4'; my $oid_exagridServerData = '.1.3.6.1.4.1.14941.4';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_table(
my $results = $options{snmp}->get_table(oid => $oid_exagridServerData, oid => $oid_exagridServerData,
nothing_quit => 1); nothing_quit => 1
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => '0'); );
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
$self->{server} = { $self->{server} = {
status => $result->{egServerAlarmState}, status => $result->{egServerAlarmState},
retention_total => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000, retention_total => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000,
retention_used => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egRetentionSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000, retention_used => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egRetentionSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000,
landing_total => $result->{egLandingSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000, landing_total => $result->{egLandingSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000,
landing_used => $result->{egLandingSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egLandingSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000, landing_used => $result->{egLandingSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egLandingSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000
}; };
} }
@ -208,14 +197,9 @@ Can used special variables like: %{status}
Set critical threshold for status (Default: '%{status} =~ /error/i'). Set critical threshold for status (Default: '%{status} =~ /error/i').
Can used special variables like: %{status} Can used special variables like: %{status}
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'retention-usage' (%), 'landing-usage' (%).
=item B<--critical-*>
Threshold critical.
Can be: 'retention-usage' (%), 'landing-usage' (%). Can be: 'retention-usage' (%), 'landing-usage' (%).
=back =back