From 301cdc07ae97027990355de159d39a6d8226f514 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Tue, 21 Oct 2014 16:34:43 +0200 Subject: [PATCH] Refs #7246 Begin refactoring of commands --- .../vmware/src/centreon/esxd/cmdhealthhost.pm | 41 +++++++++++++++---- connectors/vmware/src/centreon/esxd/common.pm | 14 ++++--- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/connectors/vmware/src/centreon/esxd/cmdhealthhost.pm b/connectors/vmware/src/centreon/esxd/cmdhealthhost.pm index 5f132c61d..b0d48f725 100644 --- a/connectors/vmware/src/centreon/esxd/cmdhealthhost.pm +++ b/connectors/vmware/src/centreon/esxd/cmdhealthhost.pm @@ -52,18 +52,39 @@ sub set_connector { sub run { my $self = shift; - my %filters = (name => $self->{esx_hostname}); - my @properties = ('runtime.healthSystemRuntime.hardwareStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo', + my %filters = (); + my $multiple = 0; + + if (defined($self->{esx_hostname}) && !defined($self->{filter})) { + $filters{name} = qr/^\Q$self->{esx_hostname}\E$/; + } elsif (!defined($self->{esx_hostname})) { + $filters{name} = qr/.*/; + } else { + $filters{name} = qr/$self->{esx_hostname}/; + } + + my @properties = ('name', 'runtime.healthSystemRuntime.hardwareStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo', 'runtime.connectionState'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties); if (!defined($result)) { return ; } - return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{esx_hostname}, - $$result[0]->{'runtime.connectionState'}->val) == 0); + if (scalar(@$result) > 1) { + $multiple = 1; + } + if ($multiple == 1) { + $self->{manager}->{output}->output_add(severity => 'OK', + short_msg => sprintf("All ESX health checks are ok")); + } foreach my $entity_view (@$result) { + next if (centreon::esxd::common::host_state(connector => $self->{obj_esxd}, + hostname => $entity_view->{name}, + state => $entity_view->{'runtime.connectionState'}->val, + status => $self->{disconnect_status}, + multiple => $multiple) == 0); + my $OKCount = 0; my $CAlertCount = 0; my $WAlertCount = 0; @@ -71,6 +92,7 @@ sub run { my $memoryStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{memoryStatusInfo}; my $storageStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{storageStatusInfo}; my $numericSensorInfo = $entity_view->{'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo'}; + $self->{manager}->{output}->output_add(long_msg => sprintf("Checking %s", $entity_view->{name})); # CPU if (defined($cpuStatusInfo)) { @@ -136,16 +158,19 @@ sub run { threshold => [ { label => 'warning', exit_litteral => 'warning' } ]); if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{manager}->{output}->output_add(severity => $exit, - short_msg => sprintf("%s health issue(s) found", $WAlertCount)); + short_msg => sprintf("'%s' %s health issue(s) found", $entity_view->{name}, $WAlertCount)); } $exit = $self->{manager}->{perfdata}->threshold_check(value => $CAlertCount, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' } ]); if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{manager}->{output}->output_add(severity => $exit, - short_msg => sprintf("%s health issue(s) found", $CAlertCount)); + short_msg => sprintf("'%s' %s health issue(s) found", $entity_view->{name}, $CAlertCount)); } - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s health checks are green", $OKCount)); + $self->{manager}->{output}->output_add(long_msg => sprintf("%s health checks are green", $OKCount)); + if ($multiple == 0) { + $self->{manager}->{output}->output_add(severity => 'OK', + short_msg => sprintf("'%s' %s health checks are green", $entity_view->{name}, $OKCount)); + } } } diff --git a/connectors/vmware/src/centreon/esxd/common.pm b/connectors/vmware/src/centreon/esxd/common.pm index bee505f0f..3db0d33e5 100644 --- a/connectors/vmware/src/centreon/esxd/common.pm +++ b/connectors/vmware/src/centreon/esxd/common.pm @@ -385,12 +385,16 @@ sub vm_state { } sub host_state { - my ($obj_esxd, $host, $connection_state) = @_; + my (%options) = @_; + my $status = defined($options{status}) ? $options{status} : $options{connector}->{centreonesxd_config}->{host_state_error}; - if ($connection_state !~ /^connected$/i) { - my $output = "Host '" . $host . "' not connected. Current Connection State: '$connection_state'."; - $manager_display->{output}->output_add(severity => $obj_esxd->{centreonesxd_config}->{host_state_error}, - short_msg => $output); + if ($options{state} !~ /^connected$/i) { + my $output = "Host '" . $options{hostname} . "' not connected. Current Connection State: '$options{state}'."; + if ($options{multiple} == 0 || + !$manager_display->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) { + $manager_display->{output}->output_add(severity => $status, + short_msg => $output); + } return 0; }