diff --git a/hardware/server/dell/idrac/snmp/mode/globalstatus.pm b/hardware/server/dell/idrac/snmp/mode/globalstatus.pm index 247d0b163..19a3733c8 100644 --- a/hardware/server/dell/idrac/snmp/mode/globalstatus.pm +++ b/hardware/server/dell/idrac/snmp/mode/globalstatus.pm @@ -20,19 +20,66 @@ package hardware::server::dell::idrac::snmp::mode::globalstatus; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); -my %states = ( - 1 => ['other', 'WARNING'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['non critical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'WARNING'], -); +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("global status is '%s'", $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_storage_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("storage status is '%s'", $self->{result_values}->{status}); + return $msg; +} + +sub custom_storage_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_storage_status'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ', ', cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'storage-status', threshold => 0, set => { + key_values => [ { name => 'storage_status' } ], + closure_custom_calc => $self->can('custom_storage_status_calc'), + closure_custom_output => $self->can('custom_storage_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} sub new { my ($class, %options) = @_; @@ -40,41 +87,74 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + "unknown-status:s" => { name => 'unknown_status', default => '%{status} =~ /^unknown/i' }, + "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /nonRecoverable|non critical|other/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /^critical/i' }, + "unknown-storage-status:s" => { name => 'unknown_storage_status', default => '%{status} =~ /^unknown/i' }, + "warning-storage-status:s" => { name => 'warning_storage_status', default => '%{status} =~ /nonRecoverable|non critical|other/i' }, + "critical-storage-status:s" => { name => 'critical_storage_status', default => '%{status} =~ /^critical/i' }, + }); return $self; } -sub check_options { + +sub prefix_global_output { my ($self, %options) = @_; - $self->SUPER::init(%options); + + return "Card '" . $self->{global}->{display} . "' : "; } -sub run { +sub check_options { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; + $self->SUPER::check_options(%options); + $self->change_macros(macros => [ + 'unknown_storage_status', 'warning_storage_status', 'critical_storage_status', + 'unknown_status', 'warning_status', 'critical_status', + ]); +} + +my %states = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'non critical', + 5 => 'critical', + 6 => 'nonRecoverable', +); + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_racShortName = '.1.3.6.1.4.1.674.10892.5.1.1.2.0'; + my $oid_racVersion = '.1.3.6.1.4.1.674.10892.5.1.1.5.0'; my $oid_drsGlobalSystemStatus = '.1.3.6.1.4.1.674.10892.2.2.1.0'; my $oid_globalSystemStatus = '.1.3.6.1.4.1.674.10892.5.2.1.0'; my $oid_globalStorageStatus = '.1.3.6.1.4.1.674.10892.5.2.3.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_drsGlobalSystemStatus, $oid_globalSystemStatus, $oid_globalStorageStatus], nothing_quit => 1); + my $result = $options{snmp}->get_leef(oids => [ + $oid_racShortName, $oid_racVersion, $oid_drsGlobalSystemStatus, $oid_globalSystemStatus, $oid_globalStorageStatus + ], nothing_quit => 1); + my ($global_status, $storage_status); if (defined($result->{$oid_globalSystemStatus})) { - $self->{output}->output_add(severity => ${$states{$result->{$oid_globalSystemStatus}}}[1], - short_msg => sprintf("Overall global status is '%s'", - ${$states{$result->{$oid_globalSystemStatus}}}[0])); - $self->{output}->output_add(severity => ${$states{$result->{$oid_globalStorageStatus}}}[1], - short_msg => sprintf("Overall storage status is '%s'", - ${$states{$result->{$oid_globalStorageStatus}}}[0])); + $global_status = $states{$result->{$oid_globalSystemStatus}}; + $storage_status = defined($result->{$oid_globalStorageStatus}) ? $states{$result->{$oid_globalStorageStatus}} : undef; } else { - $self->{output}->output_add(severity => ${$states{$result->{$oid_drsGlobalSystemStatus}}}[1], - short_msg => sprintf("Overall global status is '%s'", - ${$states{$result->{$oid_drsGlobalSystemStatus}}}[0])); - } - $self->{output}->display(); - $self->{output}->exit(); + $global_status = $states{$result->{$oid_drsGlobalSystemStatus}}; + } + + my $display = 'unknown'; + $display = $result->{$oid_racShortName} + if (defined($result->{$oid_racShortName})); + $display .= '.' . $result->{$oid_racVersion} + if (defined($result->{$oid_racVersion})); + $self->{global} = { + display => $display, + status => $global_status, + storage_status => $storage_status, + }; } 1; @@ -87,6 +167,36 @@ Check the overall status of iDrac card. =over 8 +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{status} =~ /^unknown/i'). +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /nonRecoverable|non critical|other/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /^critical/i'). +Can used special variables like: %{status} + +=item B<--unknown-storage-status> + +Set warning threshold for status (Default: '%{status} =~ /^unknown/i'). +Can used special variables like: %{status} + +=item B<--warning-storage-status> + +Set warning threshold for status (Default: '%{status} =~ /nonRecoverable|non critical|other/i'). +Can used special variables like: %{status} + +=item B<--critical-storage-status> + +Set critical threshold for status (Default: '%{status} =~ /^critical/i'). +Can used special variables like: %{status} + =back =cut