Begin refactoring of commands
This commit is contained in:
Quentin Garnier 2014-10-21 16:34:43 +02:00
parent 0870631b9f
commit 301cdc07ae
2 changed files with 42 additions and 13 deletions

View File

@ -52,18 +52,39 @@ sub set_connector {
sub run { sub run {
my $self = shift; my $self = shift;
my %filters = (name => $self->{esx_hostname}); my %filters = ();
my @properties = ('runtime.healthSystemRuntime.hardwareStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo', 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'); 'runtime.connectionState');
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties);
if (!defined($result)) { if (!defined($result)) {
return ; return ;
} }
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{esx_hostname}, if (scalar(@$result) > 1) {
$$result[0]->{'runtime.connectionState'}->val) == 0); $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) { 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 $OKCount = 0;
my $CAlertCount = 0; my $CAlertCount = 0;
my $WAlertCount = 0; my $WAlertCount = 0;
@ -71,6 +92,7 @@ sub run {
my $memoryStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{memoryStatusInfo}; my $memoryStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{memoryStatusInfo};
my $storageStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{storageStatusInfo}; my $storageStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{storageStatusInfo};
my $numericSensorInfo = $entity_view->{'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo'}; my $numericSensorInfo = $entity_view->{'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo'};
$self->{manager}->{output}->output_add(long_msg => sprintf("Checking %s", $entity_view->{name}));
# CPU # CPU
if (defined($cpuStatusInfo)) { if (defined($cpuStatusInfo)) {
@ -136,16 +158,19 @@ sub run {
threshold => [ { label => 'warning', exit_litteral => 'warning' } ]); threshold => [ { label => 'warning', exit_litteral => 'warning' } ]);
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{manager}->{output}->output_add(severity => $exit, $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' } ]); $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)) { if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{manager}->{output}->output_add(severity => $exit, $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(long_msg => sprintf("%s health checks are green", $OKCount));
if ($multiple == 0) {
$self->{manager}->{output}->output_add(severity => 'OK', $self->{manager}->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s health checks are green", $OKCount)); short_msg => sprintf("'%s' %s health checks are green", $entity_view->{name}, $OKCount));
}
} }
} }

View File

@ -385,12 +385,16 @@ sub vm_state {
} }
sub host_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) { if ($options{state} !~ /^connected$/i) {
my $output = "Host '" . $host . "' not connected. Current Connection State: '$connection_state'."; my $output = "Host '" . $options{hostname} . "' not connected. Current Connection State: '$options{state}'.";
$manager_display->{output}->output_add(severity => $obj_esxd->{centreonesxd_config}->{host_state_error}, 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); short_msg => $output);
}
return 0; return 0;
} }