From 093ecd88e42bdc60d0ec2b6efcbb63e1554ca3cc Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 3 Feb 2020 11:41:55 +0100 Subject: [PATCH] optimize call dell me4 --- storage/dell/me4/restapi/custom/api.pm | 15 +++--- .../dell/me4/restapi/mode/components/disk.pm | 52 ++++++++++++++----- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/storage/dell/me4/restapi/custom/api.pm b/storage/dell/me4/restapi/custom/api.pm index e22be0ac2..825c7ce75 100644 --- a/storage/dell/me4/restapi/custom/api.pm +++ b/storage/dell/me4/restapi/custom/api.pm @@ -57,7 +57,8 @@ sub new { $self->{mode} = $options{mode}; $self->{http} = centreon::plugins::http->new(%options); $self->{cache} = centreon::plugins::statefile->new(%options); - + $self->{set_lang} = 0; + return $self; } @@ -195,25 +196,23 @@ sub request_api { } $self->settings(); - - my $lang = $self->{http}->request(method => 'GET', url_path => '/api/set/cli-parameters/locale/English'); - - $self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . $self->{port} . - $options{url_path} . "'", debug => 1); + if ($self->{set_lang} == 0) { + $self->{http}->request(method => 'GET', url_path => '/api/set/cli-parameters/locale/English'); + $self->{set_lang} = 1; + } my $content = $self->{http}->request(%options); 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(); } - + my $decoded; eval { $decoded = JSON::XS->new->utf8->decode($content); }; if ($@) { - $self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); $self->{output}->option_exit(); } diff --git a/storage/dell/me4/restapi/mode/components/disk.pm b/storage/dell/me4/restapi/mode/components/disk.pm index cf6cc9323..b15815bd0 100644 --- a/storage/dell/me4/restapi/mode/components/disk.pm +++ b/storage/dell/me4/restapi/mode/components/disk.pm @@ -44,31 +44,59 @@ sub check { $self->{components}->{disk}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Disk '%s' status is '%s', health is '%s', state is '%s' [instance = %s] [temperature = %s C]", - $result->{'serial-number'}, $result->{status}, $result->{health}, $result->{state}, $instance, - $result->{'temperature-numeric'})); - + $self->{output}->output_add( + long_msg => sprintf( + "Disk '%s' status is '%s', health is '%s', state is '%s' [instance = %s] [temperature = %s C]", + $result->{'serial-number'}, $result->{status}, $result->{health}, $result->{state}, $instance, + $result->{'temperature-numeric'} + ) + ); + my $exit1 = $self->get_severity(section => 'disk', value => $result->{status}); if (!$self->{output}->is_status(value => $exit1, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit1, - short_msg => sprintf("Disk '%s' status is '%s'", $result->{'serial-number'}, $result->{status})); + $self->{output}->output_add( + severity => $exit1, + short_msg => sprintf( + "Disk '%s' status is '%s'", + $result->{'serial-number'}, + $result->{status} + ) + ); } my $exit2 = $self->get_severity(section => 'disk', value => $result->{health}); if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("Disk '%s' health is '%s'", $result->{'serial-number'}, $result->{health})); + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf( + "Disk '%s' health is '%s'", + $result->{'serial-number'}, + $result->{health} + ) + ); } my $exit3 = $self->get_severity(section => 'disk', value => $result->{state}); if (!$self->{output}->is_status(value => $exit3, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit3, - short_msg => sprintf("Disk '%s' state is '%s'", $result->{'serial-number'}, $result->{state})); + $self->{output}->output_add( + severity => $exit3, + short_msg => sprintf( + "Disk '%s' state is '%s'", + $result->{'serial-number'}, + $result->{state} + ) + ); } next if ($result->{'temperature-numeric'} !~ /[0-9]/); my ($exit4, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'disk', instance => $instance, value => $result->{'temperature-numeric'}); if (!$self->{output}->is_status(value => $exit4, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit4, - short_msg => sprintf("Disk '%s' temperature is %s C", $result->{'serial-number'}, $result->{'temperature-numeric'})); + $self->{output}->output_add( + severity => $exit4, + short_msg => sprintf( + "Disk '%s' temperature is %s C", + $result->{'serial-number'}, + $result->{'temperature-numeric'} + ) + ); } $self->{output}->perfdata_add( label => 'temperature', unit => 'C',