From 75cc803fabae2b523f20b3c95a3ddf464c3c9cf3 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 Feb 2019 14:16:19 +0100 Subject: [PATCH] enhance health status return --- .../src/centreon/vmware/cmdhealthhost.pm | 54 +++++-------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm b/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm index 14d935bff..b47868de1 100644 --- a/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm @@ -67,65 +67,39 @@ sub run { # CPU if (defined($cpuStatusInfo)) { - $data->{$entity_value}->{cpu_info} = { ok => 0, yellow => 0, red => 0, summary_red => [], summary_yellow => [] }; + $data->{$entity_value}->{cpu_info} = []; foreach (@$cpuStatusInfo) { - if ($_->status->key =~ /^red$/i) { - push @{$data->{$entity_value}->{cpu_info}->{summary_red}}, { name => $_->name, summary => $_->status->summary }; - $data->{$entity_value}->{cpu_info}->{red}++; - } elsif ($_->status->key =~ /^yellow$/i) { - push @{$data->{$entity_value}->{cpu_info}->{summary_yellow}}, { name => $_->name, summary => $_->status->summary }; - $data->{$entity_value}->{cpu_info}->{yellow}++; - } else { - $data->{$entity_value}->{cpu_info}->{ok}++; - } + push @{$data->{$entity_value}->{cpu_info}}, { status => $_->status->key, name => $_->name, summary => $_->status->summary }; } } # Memory if (defined($memoryStatusInfo)) { - $data->{$entity_value}->{memory_info} = { ok => 0, yellow => 0, red => 0, summary_red => [], summary_yellow => [] }; + $data->{$entity_value}->{memory_info} = []; foreach (@$memoryStatusInfo) { - if ($_->status->key =~ /^red$/i) { - push @{$data->{$entity_value}->{memory_info}->{summary_red}}, { name => $_->name, summary => $_->status->summary }; - $data->{$entity_value}->{memory_info}->{red}++; - } elsif ($_->status->key =~ /^yellow$/i) { - push @{$data->{$entity_value}->{memory_info}->{summary_yellow}}, { name => $_->name, summary => $_->status->summary }; - $data->{$entity_value}->{memory_info}->{yellow}++; - } else { - $data->{$entity_value}->{memory_info}->{ok}++; - } + push @{$data->{$entity_value}->{memory_info}}, { status => $_->status->key, name => $_->name, summary => $_->status->summary }; } } # Storage if (defined($self->{storage_status}) && defined($storageStatusInfo)) { - $data->{$entity_value}->{storage_info} = { ok => 0, yellow => 0, red => 0, summary_red => [], summary_yellow => [] }; + $data->{$entity_value}->{storage_info} = []; foreach (@$storageStatusInfo) { - if ($_->status->key =~ /^red$/i) { - push @{$data->{$entity_value}->{storage_info}->{summary_red}}, { name => $_->name, summary => $_->status->summary }; - $data->{$entity_value}->{storage_info}->{red}++; - } elsif ($_->status->key =~ /^yellow$/i) { - push @{$data->{$entity_value}->{storage_info}->{summary_yellow}}, { name => $_->name, summary => $_->status->summary }; - $data->{$entity_value}->{storage_info}->{yellow}++; - } else { - $data->{$entity_value}->{storage_info}->{ok}++; - } + push @{$data->{$entity_value}->{storage_info}}, { status => $_->status->key, name => $_->name, summary => $_->status->summary }; } } # Sensor if (defined($numericSensorInfo)) { - $data->{$entity_value}->{sensor_info} = { ok => 0, yellow => 0, red => 0, summary_red => [], summary_yellow => [] }; + $data->{$entity_value}->{sensor_info} = []; foreach (@$numericSensorInfo) { - if ($_->healthState->key =~ /^red$/i) { - push @{$data->{$entity_value}->{sensor_info}->{summary_red}}, { type => $_->sensorType, name => $_->name, summary => $_->healthState->summary }; - $data->{$entity_value}->{sensor_info}->{red}++; - } elsif ($_->healthState->key =~ /^yellow$/i) { - push @{$data->{$entity_value}->{sensor_info}->{summary_yellow}}, { type => $_->sensorType, name => $_->name, summary => $_->healthState->summary }; - $data->{$entity_value}->{sensor_info}->{yellow}++; - } else { - $data->{$entity_value}->{sensor_info}->{ok}++; - } + push @{$data->{$entity_value}->{sensor_info}}, { + status => $_->healthState->key, + type => $_->sensorType, name => $_->name, summary => $_->healthState->summary, + current_reading => $_->currentReading, + power10 => $_->unitModifier, + unit => $_->baseUnits + }; } } }