From fd845dff888b820a36a46dab6b06009cfa7e22d9 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 7 Sep 2020 14:48:13 +0200 Subject: [PATCH] Fix #2159 #2187 #2166 #2165 #2144 (#2197) --- .../apps/protocols/nrpe/custom/nsclient.pm | 40 +++++++++------ .../apps/protocols/nrpe/mode/query.pm | 10 ++-- .../apps/protocols/nrpe/plugin.pm | 10 ++-- .../apps/voip/3cx/restapi/custom/api.pm | 39 +++++++-------- .../apps/voip/3cx/restapi/mode/extension.pm | 38 +++++++------- .../apps/voip/3cx/restapi/mode/system.pm | 42 +++++----------- .../apps/voip/3cx/restapi/plugin.pm | 8 +-- .../centreon/plugins/backend/http/curl.pm | 43 +++++++++++----- .../dell/idrac/snmp/mode/components/pdisk.pm | 49 +++++++++++++------ .../server/dell/idrac/snmp/mode/hardware.pm | 4 +- .../hardware/server/dell/idrac/snmp/plugin.pm | 8 +-- 11 files changed, 163 insertions(+), 128 deletions(-) diff --git a/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm b/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm index 4701af246..d5b42e700 100644 --- a/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm +++ b/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm @@ -46,16 +46,19 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - 'hostname:s' => { name => 'hostname' }, - 'port:s' => { name => 'port' }, - 'proto:s' => { name => 'proto' }, - 'credentials' => { name => 'credentials' }, - 'basic' => { name => 'basic' }, - 'username:s' => { name => 'username' }, - 'password:s' => { name => 'password' }, - 'legacy-password:s' => { name => 'legacy_password' }, - 'new-api' => { name => 'new_api' }, - 'timeout:s' => { name => 'timeout' } + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'credentials' => { name => 'credentials' }, + 'basic' => { name => 'basic' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'legacy-password:s' => { name => 'legacy_password' }, + 'new-api' => { name => 'new_api' }, + 'timeout:s' => { name => 'timeout' }, + 'unknown-http-status:s' => { name => 'unknown_http_status' }, + 'warning-http-status:s' => { name => 'warning_http_status' }, + 'critical-http-status:s' => { name => 'critical_http_status' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MODE OPTIONS', once => 1); @@ -84,9 +87,12 @@ sub check_options { $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef; $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef; $self->{legacy_password} = (defined($self->{option_results}->{legacy_password})) ? $self->{option_results}->{legacy_password} : undef; + $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300' ; + $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; + $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; - if (!defined($self->{hostname}) || $self->{hostname} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + if ($self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); $self->{output}->option_exit(); } return 0; @@ -100,9 +106,6 @@ sub build_options_for_httplib { $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; $self->{option_results}->{timeout} = $self->{timeout}; - $self->{option_results}->{warning_status} = ''; - $self->{option_results}->{critical_status} = ''; - $self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} >= 300'; if (defined($self->{username})) { $self->{option_results}->{username} = $self->{username}; @@ -228,7 +231,12 @@ sub request { } else { $url = '/query/' . $options{command} . '?' . $encoded_args } - my ($content) = $self->{http}->request(url_path => $url); + my ($content) = $self->{http}->request( + url_path => $url, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status} + ); if (!defined($content) || $content eq '') { $self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); $self->{output}->option_exit(); diff --git a/centreon-plugins/apps/protocols/nrpe/mode/query.pm b/centreon-plugins/apps/protocols/nrpe/mode/query.pm index 7b8007f29..6e54442aa 100644 --- a/centreon-plugins/apps/protocols/nrpe/mode/query.pm +++ b/centreon-plugins/apps/protocols/nrpe/mode/query.pm @@ -31,11 +31,11 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "command:s" => { name => 'command' }, - "arg:s@" => { name => 'arg' }, - "sanitize-message:s" => { name => 'sanitize_message' }, + 'command:s' => { name => 'command' }, + 'arg:s@' => { name => 'arg' }, + 'sanitize-message:s' => { name => 'sanitize_message' } }); - + return $self; } @@ -44,7 +44,7 @@ sub check_options { $self->SUPER::init(%options); if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') { - $self->{output}->add_option_msg(short_msg => "Please set --command option"); + $self->{output}->add_option_msg(short_msg => 'Please set --command option'); $self->{output}->option_exit(); } } diff --git a/centreon-plugins/apps/protocols/nrpe/plugin.pm b/centreon-plugins/apps/protocols/nrpe/plugin.pm index 48be13c25..b1273892b 100644 --- a/centreon-plugins/apps/protocols/nrpe/plugin.pm +++ b/centreon-plugins/apps/protocols/nrpe/plugin.pm @@ -30,12 +30,12 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'query' => 'apps::protocols::nrpe::mode::query', - ); + $self->{modes} = { + 'query' => 'apps::protocols::nrpe::mode::query' + }; - $self->{custom_modes}{nrpe} = 'apps::protocols::nrpe::custom::nrpe'; - $self->{custom_modes}{nsclient} = 'apps::protocols::nrpe::custom::nsclient'; + $self->{custom_modes}->{nrpe} = 'apps::protocols::nrpe::custom::nrpe'; + $self->{custom_modes}->{nsclient} = 'apps::protocols::nrpe::custom::nsclient'; return $self; } diff --git a/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm b/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm index 506373b11..76a30dfb5 100644 --- a/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm +++ b/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm @@ -45,12 +45,12 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - 'hostname:s' => { name => 'hostname' }, - 'port:s' => { name => 'port'}, - 'proto:s' => { name => 'proto' }, - 'api-username:s' => { name => 'api_username' }, - 'api-password:s' => { name => 'api_password' }, - 'timeout:s' => { name => 'timeout', default => 30 }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port'}, + 'proto:s' => { name => 'proto' }, + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'timeout:s' => { name => 'timeout', default => 30 }, 'unknown-http-status:s' => { name => 'unknown_http_status' }, 'warning-http-status:s' => { name => 'warning_http_status' }, 'critical-http-status:s' => { name => 'critical_http_status' } @@ -77,27 +77,27 @@ sub set_defaults {} sub check_options { my ($self, %options) = @_; - $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; $self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef; - $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : undef; - $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : ''; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : ''; $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300' ; $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; - if (!defined($self->{hostname}) || $self->{hostname} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + if ($self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); $self->{output}->option_exit(); } - if (!defined($self->{api_username}) || $self->{api_username} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + if ($self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --api-username option.'); $self->{output}->option_exit(); } - if (!defined($self->{api_password}) || $self->{api_password} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + if ($self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --api-password option.'); $self->{output}->option_exit(); } @@ -147,14 +147,15 @@ sub authenticate { my $content = $self->{http}->request( method => 'POST', query_form_post => $post_data, url_path => '/api/login', - warning_status => '', unknown_status => '', critical_status => '%{http_code} < 200 or %{http_code} >= 300' + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status} ); my $header = $self->{http}->get_header(name => 'Set-Cookie'); if (defined ($header) && $header =~ /(?:^| ).AspNetCore.Cookies=([^;]+);.*/) { $cookie = $1; } else { - $self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->add_option_msg(short_msg => "Error retrieving cookie"); $self->{output}->option_exit(); } @@ -184,7 +185,7 @@ sub request_api { %options, unknown_status => $self->{unknown_http_status}, warning_status => $self->{warning_http_status}, - critical_status => $self->{critical_http_status}, + critical_status => $self->{critical_http_status} ); # Some content may be strangely returned, for example : @@ -201,12 +202,10 @@ sub request_api { $decoded = JSON::XS->new->decode($content); }; if ($@) { - $self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); $self->{output}->option_exit(); } if (!defined($decoded)) { - $self->{output}->output_add(long_msg => $decoded, debug => 1); $self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)"); $self->{output}->option_exit(); } diff --git a/centreon-plugins/apps/voip/3cx/restapi/mode/extension.pm b/centreon-plugins/apps/voip/3cx/restapi/mode/extension.pm index 57d8c8a71..0c6852a06 100644 --- a/centreon-plugins/apps/voip/3cx/restapi/mode/extension.pm +++ b/centreon-plugins/apps/voip/3cx/restapi/mode/extension.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -56,14 +56,16 @@ sub set_counters { ]; $self->{maps_counters}->{extension} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'extension' }, { name => 'registered' }, { name => 'dnd' }, { name => 'profile' }, { name => 'status' }, { name => 'duration' } ], - closure_custom_calc => \&catalog_status_calc, + { label => 'status', type => 2, set => { + key_values => [ + { name => 'extension' }, { name => 'registered' }, { name => 'dnd' }, + { name => 'profile' }, { name => 'status' }, { name => 'duration' } + ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -78,25 +80,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - 'unknown-status:s' => { name => 'unknown_status', default => '' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, + 'filter-extension:s' => { name => 'filter_extension' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => [ - 'warning_status', 'critical_status', 'unknown_status', - ]); -} - sub manage_selection { my ($self, %options) = @_; @@ -116,6 +106,12 @@ sub manage_selection { my $extension = $options{custom}->api_extension_list(); $self->{extension} = {}; foreach my $item (@$extension) { + if (defined($self->{option_results}->{filter_extension}) && $self->{option_results}->{filter_extension} ne '' && + $item->{_str} !~ /$self->{option_results}->{filter_extension}/) { + $self->{output}->output_add(long_msg => "skipping extension '" . $item->{_str} . "': no matching filter.", debug => 1); + next; + } + $self->{extension}->{$item->{_str}} = { extension => $item->{_str}, registered => $item->{IsRegistered} ? 'true' : 'false', @@ -138,6 +134,10 @@ Check extentions status =over 8 +=item B<--filter-extension> + +Filter extension. + =item B<--unknown-status> Set unknown threshold for status. diff --git a/centreon-plugins/apps/voip/3cx/restapi/mode/system.pm b/centreon-plugins/apps/voip/3cx/restapi/mode/system.pm index 6f784e7d7..a45a906f3 100644 --- a/centreon-plugins/apps/voip/3cx/restapi/mode/system.pm +++ b/centreon-plugins/apps/voip/3cx/restapi/mode/system.pm @@ -24,14 +24,14 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; my $msg = ''; if ($self->{result_values}->{service} !~ /^Has[A-Z]/) { - $msg .= 'error '; + $msg .= 'error'; } $msg .= ': ' . $self->{result_values}->{error}; return $msg; @@ -48,33 +48,30 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'calls-active', nlabel => 'system.calls.active.current', set => { key_values => [ { name => 'calls_active' } ], - output_template => 'calls active : %s', + output_template => 'calls active: %s', perfdatas => [ - { label => 'calls_active', template => '%s', value => 'calls_active', - min => 0 }, - ], + { label => 'calls_active', template => '%s', min => 0 } + ] } }, - { label => 'extensions-registered', nlabel => 'system.extensions.registered.current', set => { + { label => 'extensions-registered', nlabel => 'system.extensions.registered.current', set => { key_values => [ { name => 'extensions_registered' } ], - output_template => 'extensions registered : %s', + output_template => 'extensions registered: %s', perfdatas => [ - { label => 'extensions_registered', template => '%s', value => 'extensions_registered', - min => 0 }, - ], + { label => 'extensions_registered', template => '%s', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{service} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{error} =~ /true/', set => { key_values => [ { name => 'error' }, { name => 'service' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -89,25 +86,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{error} =~ /true/' }, }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => [ - 'warning_status', 'critical_status', 'unknown_status', - ]); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/voip/3cx/restapi/plugin.pm b/centreon-plugins/apps/voip/3cx/restapi/plugin.pm index 2efcbc9d5..9c2f8dba4 100644 --- a/centreon-plugins/apps/voip/3cx/restapi/plugin.pm +++ b/centreon-plugins/apps/voip/3cx/restapi/plugin.pm @@ -31,12 +31,12 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( + $self->{modes} = { 'extension' => 'apps::voip::3cx::restapi::mode::extension', - 'system' => 'apps::voip::3cx::restapi::mode::system', - ); + 'system' => 'apps::voip::3cx::restapi::mode::system' + }; - $self->{custom_modes}{api} = 'apps::voip::3cx::restapi::custom::api'; + $self->{custom_modes}->{api} = 'apps::voip::3cx::restapi::custom::api'; return $self; } diff --git a/centreon-plugins/centreon/plugins/backend/http/curl.pm b/centreon-plugins/centreon/plugins/backend/http/curl.pm index 51b09ecfc..76510d499 100644 --- a/centreon-plugins/centreon/plugins/backend/http/curl.pm +++ b/centreon-plugins/centreon/plugins/backend/http/curl.pm @@ -32,7 +32,7 @@ sub new { if (!defined($options{noptions}) || $options{noptions} != 1) { $options{options}->add_options(arguments => { - 'curl-opt:s@' => { name => 'curl_opt' }, + 'curl-opt:s@' => { name => 'curl_opt' } }); $options{options}->add_help(package => __PACKAGE__, sections => 'BACKEND CURL OPTIONS', once => 1); } @@ -109,7 +109,7 @@ my $http_code_explained = { 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported', + 505 => 'HTTP Version Not Supported' }; sub cb_debug { @@ -208,7 +208,7 @@ sub set_auth { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_SSLKEY'), parameter => $options{request}->{key_file}); $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_KEYPASSWD'), parameter => $options{request}->{cert_pwd}); } - + $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_SSLCERTTYPE'), parameter => "PEM"); if (defined($options{request}->{cert_pkcs12})) { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_SSLCERTTYPE'), parameter => "P12"); @@ -231,17 +231,38 @@ sub set_proxy { sub set_extra_curl_opt { my ($self, %options) = @_; - my $fields = { key => '', value => '' }; + my $entries = {}; foreach (@{$options{request}->{curl_opt}}) { - ($fields->{key}, $fields->{value}) = split /=>/; - foreach my $label ('key', 'value') { - $fields->{$label} = centreon::plugins::misc::trim($fields->{$label}); - if ($fields->{$label} =~ /^CURLOPT|CURL/) { - $fields->{$label} = $self->{constant_cb}->(name => $fields->{$label}); - } + my ($key, $value) = split /=>/; + $key = centreon::plugins::misc::trim($key); + + if (!defined($entries->{$key})) { + $entries->{$key} = { val => [], force_array => 0 }; } - $self->curl_setopt(option => $fields->{key}, parameter => $fields->{value}); + $value = centreon::plugins::misc::trim($value); + if ($value =~ /^\[(.*)\]$/) { + $entries->{$key}->{force_array} = 1; + $value = centreon::plugins::misc::trim($1); + } + if ($value =~ /^CURLOPT|CURL/) { + $value = $self->{constant_cb}->(name => $value); + } + + push @{$entries->{$key}->{val}}, $value; + } + + foreach (keys %$entries) { + my $key = $_; + if (/^CURLOPT|CURL/) { + $key = $self->{constant_cb}->(name => $_); + } + + if ($entries->{$_}->{force_array} == 1 || scalar(@{$entries->{$_}->{val}}) > 1) { + $self->curl_setopt(option => $key, parameter => $entries->{$_}->{val}); + } else { + $self->curl_setopt(option => $key, parameter => pop @{$entries->{$_}->{val}}); + } } } diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/pdisk.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/pdisk.pm index b37e22ba4..f8fddcaf5 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/pdisk.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/pdisk.pm @@ -24,18 +24,25 @@ use strict; use warnings; use hardware::server::dell::idrac::snmp::mode::components::resources qw(%map_status %map_pdisk_state %map_pdisk_smartstate); +my $map_pdisk_sparestate = { + 1 => '', # notASpare + 2 => 'SpareDedicated', # dedicatedHotSpare + 3 => 'SpareGlobal' # globalHotSpare +}; + my $mapping = { physicalDiskState => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.4.1.4', map => \%map_pdisk_state }, + physicalDiskSpareState => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.4.1.22', map => $map_pdisk_sparestate }, physicalDiskComponentStatus => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.4.1.24', map => \%map_status }, physicalDiskSmartAlertIndication => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.4.1.31', map => \%map_pdisk_smartstate }, - physicalDiskFQDD => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.4.1.54' }, + physicalDiskFQDD => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.4.1.54' } }; my $oid_physicalDiskTableEntry = '.1.3.6.1.4.1.674.10892.5.5.1.20.130.4.1'; sub load { my ($self) = @_; - foreach (keys %{$mapping}) { + foreach (keys %$mapping) { push @{$self->{request}}, { oid => $mapping->{$_}->{oid} }; } } @@ -56,31 +63,45 @@ sub check { $oid =~ /^$mapping->{physicalDiskComponentStatus}->{oid}\.(.*)$/; my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); - + next if ($self->check_filter(section => 'pdisk', instance => $instance)); $self->{components}->{pdisk}->{total}++; - $self->{output}->output_add(long_msg => sprintf("physical disk '%s' status is '%s' [instance = %s] [state = %s] [smart alert = %s]", - $result->{physicalDiskFQDD}, $result->{physicalDiskComponentStatus}, $instance, - $result->{physicalDiskState}, $result->{physicalDiskSmartAlertIndication})); - + if ($result->{physicalDiskState} eq 'ready') { + $result->{physicalDiskState} .= $result->{physicalDiskSpareState}; + } + + $self->{output}->output_add( + long_msg => sprintf( + "physical disk '%s' status is '%s' [instance = %s] [state = %s] [smart alert = %s]", + $result->{physicalDiskFQDD}, $result->{physicalDiskComponentStatus}, $instance, + $result->{physicalDiskState}, $result->{physicalDiskSmartAlertIndication} + ) + ); + my $exit = $self->get_severity(section => 'pdisk.state', value => $result->{physicalDiskState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("physical disk '%s' state is '%s'", $result->{physicalDiskFQDD}, $result->{physicalDiskState})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("physical disk '%s' state is '%s'", $result->{physicalDiskFQDD}, $result->{physicalDiskState}) + ); next; } $exit = $self->get_severity(label => 'default.status', section => 'pdisk.status', value => $result->{physicalDiskComponentStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("physical disk '%s' status is '%s'", $result->{physicalDiskFQDD}, $result->{physicalDiskComponentStatus})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("physical disk '%s' status is '%s'", $result->{physicalDiskFQDD}, $result->{physicalDiskComponentStatus}) + ); } - + $exit = $self->get_severity(section => 'pdisk.smartalert', value => $result->{physicalDiskSmartAlertIndication}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("physical disk '%s' smart alert predictive failure is '%s'", $result->{physicalDiskFQDD}, $result->{physicalDiskSmartAlertIndication})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("physical disk '%s' smart alert predictive failure is '%s'", $result->{physicalDiskFQDD}, $result->{physicalDiskSmartAlertIndication}) + ); } } } diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/hardware.pm index 5ac968e59..9bb51a4c1 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/hardware.pm @@ -61,7 +61,9 @@ sub set_system { ], 'pdisk.state' => [ ['unknown', 'UNKNOWN'], - ['ready', 'OK'], + ['readySpareDedicated', 'OK'], + ['readySpareGlobal', 'OK'], + ['ready', 'WARNING'], ['online', 'OK'], ['foreign', 'OK'], ['offline', 'WARNING'], diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm index cf855bb63..81c66efe1 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm @@ -30,10 +30,10 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'global-status' => 'hardware::server::dell::idrac::snmp::mode::globalstatus', - 'hardware' => 'hardware::server::dell::idrac::snmp::mode::hardware', - ); + $self->{modes} = { + 'global-status' => 'hardware::server::dell::idrac::snmp::mode::globalstatus', + 'hardware' => 'hardware::server::dell::idrac::snmp::mode::hardware' + }; return $self; }