Fix critical bug

Manage problem better

git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@65 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2013-07-21 19:36:01 +00:00
parent 03c41987a7
commit 9295f468b4
14 changed files with 61 additions and 32 deletions

View File

@ -6,7 +6,7 @@ use IO::Socket;
use Getopt::Long;
my $PROGNAME = $0;
my $VERSION = "1.4";
my $VERSION = "1.4.1";
my %ERRORS = ('OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3, 'DEPENDENT' => 4);
my $socket;
@ -702,7 +702,7 @@ my $status_return = $1;
$return =~ s/^(-?[0-9]*?)\|//;
print $return . "\n";
if ($status_return == -1) {
if ($status_return < 0) {
$status_return = 3;
}
exit $status_return;

View File

@ -1,10 +1,10 @@
$centreonesxd_config = {
%centreonesxd_config = (
vsphere_server => {
'default' => {'url' => 'https://vcenter/sdk',
'username' => 'qgarnier@merethis.net',
'username' => 'XXXXXX',
'password' => 'XXXXXX'}
}
};
);
1;

View File

@ -517,7 +517,7 @@ sub run {
}
my @results = split(/\|/, $data_element);
my ($id, $counter) = split(/\./, $results[0]);
if (!defined($self->{sockets}->{$id}) || $self->{counter} != $self->{sockets}->{$id}->{'counter'}) {
if (!defined($self->{sockets}->{$id}) || $counter != $self->{sockets}->{$id}->{'counter'}) {
$self->{logger}->writeLogInfo("Too much time to get response.");
next;
}

View File

@ -64,9 +64,7 @@ sub run {
my %filters = ('name' => $self->{lhost});
my @properties = ('name', 'runtime.connectionState');
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties);
if (!defined($result)) {
return ;
}
return if (!defined($result));
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{lhost},
$$result[0]->{'runtime.connectionState'}->val) == 0);
@ -77,7 +75,8 @@ sub run {
$$result[0],
[{'label' => 'cpu.usage.average', 'instances' => \@instances}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $status = 0; # OK
my $output = '';
my $total_cpu_average = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"}[0] * 0.01));

View File

@ -78,6 +78,7 @@ sub run {
[{'label' => 'cpu.usage.average', 'instances' => \@instances},
{'label' => 'cpu.usagemhz.average', 'instances' => \@instances}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $status = 0; # OK
my $output = '';

View File

@ -74,6 +74,7 @@ sub run {
[{'label' => 'datastore.read.average', 'instances' => ['']},
{'label' => 'datastore.write.average', 'instances' => ['']}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $read_counter = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'datastore.read.average'}->{'key'} . ":"}[0]));
my $write_counter = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'datastore.write.average'}->{'key'} . ":"}[0]));

View File

@ -100,6 +100,7 @@ sub run {
[{'label' => 'datastore.totalReadLatency.average', 'instances' => ['*']},
{'label' => 'datastore.totalWriteLatency.average', 'instances' => ['*']}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $status = 0; # OK
my $output = '';

View File

@ -108,6 +108,7 @@ sub run {
[{'label' => 'disk.numberRead.summation', 'instances' => ['*']},
{'label' => 'disk.numberWrite.summation', 'instances' => ['*']}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
foreach (keys %$values) {
my ($id, $disk_name) = split(/:/);

View File

@ -77,6 +77,7 @@ sub run {
[{'label' => 'mem.consumed.average', 'instances' => ['']},
{'label' => 'mem.overhead.average', 'instances' => ['']}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $mem_used = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"}[0]));
my $mem_overhead = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"}[0]));

View File

@ -81,6 +81,7 @@ sub run {
{'label' => 'mem.consumed.average', 'instances' => ['']},
{'label' => 'mem.shared.average', 'instances' => ['']}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $mem_consumed = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"}[0]));
my $mem_active = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.active.average'}->{'key'} . ":"}[0]));

View File

@ -94,6 +94,7 @@ sub run {
[{'label' => 'net.received.average', 'instances' => [$self->{pnic}]},
{'label' => 'net.transmitted.average', 'instances' => [$self->{pnic}]}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $traffic_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'net.received.average'}->{'key'} . ":" . $self->{pnic}}[0]));
my $traffic_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'net.transmitted.average'}->{'key'} . ":" . $self->{pnic}}[0]));

View File

@ -75,6 +75,7 @@ sub run {
[{'label' => 'mem.swapinRate.average', 'instances' => ['']},
{'label' => 'mem.swapoutRate.average', 'instances' => ['']}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $swap_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"}[0]));
my $swap_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"}[0]));

View File

@ -76,6 +76,7 @@ sub run {
[{'label' => 'mem.swapinRate.average', 'instances' => ['']},
{'label' => 'mem.swapoutRate.average', 'instances' => ['']}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $swap_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"}[0]));
my $swap_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"}[0]));

View File

@ -32,6 +32,19 @@ sub response_client1 {
close $rh;
}
sub vmware_error {
my ($obj_esxd, $lerror) = @_;
$obj_esxd->{logger}->writeLogError("'" . $obj_esxd->{whoaim} . "' $lerror");
$lerror =~ s/\n/ /g;
if ($lerror =~ /NoPermissionFault/i) {
$obj_esxd->print_response("-2|Error: Not enough permissions\n");
} else {
$obj_esxd->print_response("-1|Error: " . $lerror . "\n");
}
return undef;
}
sub connect_vsphere {
my ($logger, $whoaim, $timeout_vsphere, $session1, $service_url, $username, $password) = @_;
$logger->writeLogInfo("'$whoaim' Vsphere connection in progress");
@ -86,10 +99,7 @@ sub get_views {
$results = $obj_esxd->{session1}->get_views(mo_ref_array => $_[0], properties => $_[1]);
};
if ($@) {
$obj_esxd->{logger}->writeLogError("'" . $obj_esxd->{whoaim} . "' $@");
my $lerror = $@;
$lerror =~ s/\n/ /g;
$obj_esxd->print_response("-1|Error: " . $lerror . "\n");
vmware_error($obj_esxd, $@);
return undef;
}
return $results;
@ -103,10 +113,7 @@ sub get_view {
$results = $obj_esxd->{session1}->get_view(mo_ref => $_[0], properties => $_[1]);
};
if ($@) {
$obj_esxd->{logger}->writeLogError("'" . $obj_esxd->{whoaim} . "' $@");
my $lerror = $@;
$lerror =~ s/\n/ /g;
$obj_esxd->print_response("-1|Error: " . $lerror . "\n");
vmware_error($obj_esxd, $@);
return undef;
}
return $results;
@ -129,10 +136,7 @@ sub search_in_datastore {
searchSpec=>$hostdb_search_spec);
};
if ($@) {
$obj_esxd->{logger}->writeLogError("'" . $obj_esxd->{whoaim} . "' $@");
my $lerror = $@;
$lerror =~ s/\n/ /g;
$obj_esxd->print_response("-1|Error: " . $lerror . "\n");
vmware_error($obj_esxd, $@);
return undef;
}
return $result;
@ -141,20 +145,22 @@ sub search_in_datastore {
sub get_perf_metric_ids {
my $obj_esxd = shift;
my $perf_names = $_[0];
my @filtered_list;
my $filtered_list = [];
foreach (@$perf_names) {
if (defined($obj_esxd->{perfcounter_cache}->{$_->{'label'}})) {
foreach my $instance (@{$_->{'instances'}}) {
my $metric = PerfMetricId->new(counterId => $obj_esxd->{perfcounter_cache}->{$_->{'label'}}{'key'},
instance => $instance);
push @filtered_list, $metric;
push @$filtered_list, $metric;
}
} else {
$obj_esxd->{logger}->writeLogError("Metric '" . $_->{'label'} . "' unavailable.");
$obj_esxd->print_response("-3|Error: Counter doesn't exist. VMware version can be too old.\n");
return undef;
}
}
return \@filtered_list;
return $filtered_list;
}
sub generic_performance_values_historic {
@ -163,7 +169,8 @@ sub generic_performance_values_historic {
my %results;
eval {
my @perf_metric_ids = get_perf_metric_ids($obj_esxd, $perfs);
my $perf_metric_ids = get_perf_metric_ids($obj_esxd, $perfs);
return undef if (!defined($perf_metric_ids));
my $perf_query_spec;
my $tstamp = time();
@ -174,9 +181,10 @@ sub generic_performance_values_historic {
my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
# $obj_esxd->{logger}->writeLogError(@perf_metric_ids);
if ($interval == 20) {
$perf_query_spec = PerfQuerySpec->new(entity => $view,
metricId => @perf_metric_ids,
metricId => $perf_metric_ids,
format => 'normal',
intervalId => 20,
startTime => $startTime,
@ -184,7 +192,7 @@ sub generic_performance_values_historic {
maxSample => 1);
} else {
$perf_query_spec = PerfQuerySpec->new(entity => $view,
metricId => @perf_metric_ids,
metricId => $perf_metric_ids,
format => 'normal',
intervalId => $interval,
startTime => $startTime,
@ -193,8 +201,16 @@ sub generic_performance_values_historic {
#maxSample => 1);
}
my $perfdata = $obj_esxd->{perfmanager_view}->QueryPerf(querySpec => $perf_query_spec);
if (!$$perfdata[0]) {
$obj_esxd->print_response("-3|Error: Cannot get value for couters. Maybe there is time sync problem (check the esxd server and the target also).\n");
return undef;
}
foreach (@{$$perfdata[0]->value}) {
$results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $_->value;
if (!defined($_->value)) {
$obj_esxd->print_response("-3|Error: Cannot get value for couters. Maybe there is time sync problem (check the esxd server and the target also).\n");
return undef;
}
}
};
if ($@) {
@ -248,10 +264,7 @@ sub get_entities_host {
$entity_views = $obj_esxd->{session1}->find_entity_views(view_type => $view_type, properties => $properties, filter => $filters);
};
if ($@) {
$obj_esxd->{logger}->writeLogError("'" . $obj_esxd->{whoaim} . "' $@");
my $lerror = $@;
$lerror =~ s/\n/ /g;
$obj_esxd->print_response("-1|Error: " . Data::Dumper::Dumper($lerror) . "\n");
vmware_error($obj_esxd, $@);
return undef;
}
}
@ -274,6 +287,14 @@ sub get_entities_host {
return $entity_views;
}
sub performance_errors {
my ($obj_esxd, $values) = @_;
# Error counter not available or orther from function
return 1 if (!defined($values) || scalar(keys(%$values)) <= 0);
return 0;
}
sub datastore_state {
my ($obj_esxd, $ds, $accessible) = @_;