From 13f4d63b1dad030deb32b562c2b6b500cbd18d3d Mon Sep 17 00:00:00 2001 From: Mathieu Cinquin Date: Fri, 17 Apr 2015 14:32:27 +0200 Subject: [PATCH] Change type of the variable for json parsing --- apps/elasticsearch/mode/indices.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/elasticsearch/mode/indices.pm b/apps/elasticsearch/mode/indices.pm index c29796d37..c23baf50f 100644 --- a/apps/elasticsearch/mode/indices.pm +++ b/apps/elasticsearch/mode/indices.pm @@ -41,6 +41,7 @@ use strict; use warnings; use centreon::plugins::httplib; use JSON; +use Data::Dumper; my $thresholds = { indices => [ @@ -133,9 +134,10 @@ sub get_severity { sub run { my ($self, %options) = @_; - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."_cluster/health?level=indices"; + $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."_cluster/health"; + my $query_form_get = { level => 'indices' }; - my $jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical'); + my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical'); my $json = JSON->new; @@ -154,21 +156,21 @@ sub run { short_msg => sprintf("All indices are in green state.")); my $exit = 'OK'; - my $status; - foreach my $indicename (sort(keys $webcontent->{indices})) { - my $tmp_exit = $self->get_severity(section => 'indices', value => $webcontent->{indices}->{$indicename}->{status}); + + foreach my $indicename (sort (keys %{$webcontent->{indices}})) { + my $tmp_exit = $self->get_severity(section => 'indices', value => $webcontent->{indices}->{$indicename}->{status}); $exit = $self->{output}->get_most_critical(status => [ $tmp_exit, $exit ]); if (!$self->{output}->is_status(value => $tmp_exit, compare => 'OK', litteral => 1)) { $self->{output}->output_add(long_msg => sprintf("Indice %s status is in %s state", $indicename, $webcontent->{indices}->{$indicename}->{status})); } } + $self->{output}->output_add(severity => $exit, short_msg => sprintf("One or some indices are in %s state", $map_states_indices{$exit})); $self->{output}->display(force_long_output => 1); $self->{output}->exit(); - } 1;