From 87006e17ea76f37f8dbe9d27f11fd9f96a02ec51 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Tue, 2 Jul 2013 08:56:22 +0000 Subject: [PATCH] Ref #5494 git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@59 a5eaa968-4c79-4d68-970d-af6011b5b055 --- connectors/vmware/centreonesxd.pm | 2 ++ connectors/vmware/lib/cmdcpuvm.pm | 6 +++- connectors/vmware/lib/cmddatastoreio.pm | 4 ++- connectors/vmware/lib/cmddatastoresvm.pm | 6 +++- connectors/vmware/lib/cmddatastoreusage.pm | 34 ++++++++++------------ connectors/vmware/lib/cmdmemvm.pm | 6 +++- connectors/vmware/lib/cmdswapvm.pm | 6 +++- connectors/vmware/lib/cmdtoolsvm.pm | 7 ++++- connectors/vmware/lib/common.pm | 33 +++++++++++++++++++++ 9 files changed, 80 insertions(+), 24 deletions(-) diff --git a/connectors/vmware/centreonesxd.pm b/connectors/vmware/centreonesxd.pm index 0eeecee2c..c995bdec4 100644 --- a/connectors/vmware/centreonesxd.pm +++ b/connectors/vmware/centreonesxd.pm @@ -67,6 +67,8 @@ sub new { timeout_kill => 30, refresh_keeper_session => 15, port => 5700, + datastore_state_error => 'UNKNOWN', + vm_state_error => 'UNKNOWN', vsphere_server => { #'default' => {'url' => 'https://XXXXXX/sdk', # 'username' => 'XXXXX', diff --git a/connectors/vmware/lib/cmdcpuvm.pm b/connectors/vmware/lib/cmdcpuvm.pm index 16304b158..85b79904f 100644 --- a/connectors/vmware/lib/cmdcpuvm.pm +++ b/connectors/vmware/lib/cmdcpuvm.pm @@ -61,11 +61,15 @@ sub run { } my %filters = ('name' => $self->{lvm}); - my @properties = ('name'); + my @properties = ('name', 'runtime.connectionState', 'runtime.powerState'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties); if (!defined($result)) { return ; } + + return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm}, + $$result[0]->{'runtime.connectionState'}->val, + $$result[0]->{'runtime.powerState'}->val) == 0); my @instances = ('*'); diff --git a/connectors/vmware/lib/cmddatastoreio.pm b/connectors/vmware/lib/cmddatastoreio.pm index 349d1f0c6..d4563b806 100644 --- a/connectors/vmware/lib/cmddatastoreio.pm +++ b/connectors/vmware/lib/cmddatastoreio.pm @@ -61,11 +61,13 @@ sub run { } my %filters = ('summary.name' => $self->{ds}); - my @properties = ('summary.name'); + my @properties = ('summary.name', 'summary.accessible'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'Datastore', \%filters, \@properties); if (!defined($result)) { return ; } + + return if (centreon::esxd::common::datastore_state($self->{obj_esxd}, $self->{ds}, $$result[0]->{'summary.accessible'}) == 0); my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd}, $$result[0], diff --git a/connectors/vmware/lib/cmddatastoresvm.pm b/connectors/vmware/lib/cmddatastoresvm.pm index 32b1b66b7..549b6ebb7 100644 --- a/connectors/vmware/lib/cmddatastoresvm.pm +++ b/connectors/vmware/lib/cmddatastoresvm.pm @@ -61,11 +61,15 @@ sub run { } my %filters = ('name' => $self->{lvm}); - my @properties = ('datastore'); + my @properties = ('datastore', 'runtime.connectionState', 'runtime.powerState'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties); if (!defined($result)) { return ; } + + return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm}, + $$result[0]->{'runtime.connectionState'}->val, + $$result[0]->{'runtime.powerState'}->val) == 0); my @ds_array = (); foreach my $entity_view (@$result) { diff --git a/connectors/vmware/lib/cmddatastoreusage.pm b/connectors/vmware/lib/cmddatastoreusage.pm index 09739c282..e88981db3 100644 --- a/connectors/vmware/lib/cmddatastoreusage.pm +++ b/connectors/vmware/lib/cmddatastoreusage.pm @@ -61,28 +61,26 @@ sub run { if (!defined($result)) { return ; } + + return if (centreon::esxd::common::datastore_state($self->{obj_esxd}, $self->{ds}, $$result[0]->summary->accessible) == 0); my $status = 0; # OK my $output = ""; - if ($$result[0]->summary->accessible == 1) { - my $dsName = $$result[0]->summary->name; - my $capacity = $$result[0]->summary->capacity; - my $free = $$result[0]->summary->freeSpace; - my $pct = ($capacity - $free) / $capacity * 100; - - my $usedD = ($capacity - $free) / 1024 / 1024 / 1024; - my $sizeD = $capacity / 1024 / 1024 / 1024; - $output = "Datastore $dsName - used ".sprintf("%.2f", $usedD)." Go / ".sprintf("%.2f", $sizeD)." Go (".sprintf("%.2f", $pct)." %) |used=".($capacity - $free)."o;;;0;".$capacity." size=".$capacity."o\n"; - if ($pct >= $self->{warn}) { - $status = centreon::esxd::common::errors_mask($status, 'WARNING'); - } - if ($pct > $self->{crit}) { - $status = centreon::esxd::common::errors_mask($status, 'CRITICAL'); - } - } else { - $output = "Datastore '" . $self->{ds} . "' summary not accessible."; - $status = centreon::esxd::common::errors_mask($status, 'UNKNOWN'); + my $dsName = $$result[0]->summary->name; + my $capacity = $$result[0]->summary->capacity; + my $free = $$result[0]->summary->freeSpace; + my $pct = ($capacity - $free) / $capacity * 100; + + my $usedD = ($capacity - $free) / 1024 / 1024 / 1024; + my $sizeD = $capacity / 1024 / 1024 / 1024; + + $output = "Datastore $dsName - used ".sprintf("%.2f", $usedD)." Go / ".sprintf("%.2f", $sizeD)." Go (".sprintf("%.2f", $pct)." %) |used=".($capacity - $free)."o;;;0;".$capacity." size=".$capacity."o\n"; + if ($pct >= $self->{warn}) { + $status = centreon::esxd::common::errors_mask($status, 'WARNING'); + } + if ($pct > $self->{crit}) { + $status = centreon::esxd::common::errors_mask($status, 'CRITICAL'); } $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n"); } diff --git a/connectors/vmware/lib/cmdmemvm.pm b/connectors/vmware/lib/cmdmemvm.pm index 9b0d7835e..801abbcc1 100644 --- a/connectors/vmware/lib/cmdmemvm.pm +++ b/connectors/vmware/lib/cmdmemvm.pm @@ -61,11 +61,15 @@ sub run { } my %filters = ('name' => $self->{lvm}); - my @properties = ('summary.config.memorySizeMB'); + my @properties = ('summary.config.memorySizeMB', 'runtime.connectionState', 'runtime.powerState'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties); if (!defined($result)) { return ; } + + return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm}, + $$result[0]->{'runtime.connectionState'}->val, + $$result[0]->{'runtime.powerState'}->val) == 0); my $memory_size = $$result[0]->{'summary.config.memorySizeMB'} * 1024 * 1024; diff --git a/connectors/vmware/lib/cmdswapvm.pm b/connectors/vmware/lib/cmdswapvm.pm index 2760d268c..4db072210 100644 --- a/connectors/vmware/lib/cmdswapvm.pm +++ b/connectors/vmware/lib/cmdswapvm.pm @@ -61,11 +61,15 @@ sub run { } my %filters = ('name' => $self->{lvm}); - my @properties = ('name'); + my @properties = ('name', 'runtime.connectionState', 'runtime.powerState'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties); if (!defined($result)) { return ; } + + return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm}, + $$result[0]->{'runtime.connectionState'}->val, + $$result[0]->{'runtime.powerState'}->val) == 0); my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd}, $$result[0], diff --git a/connectors/vmware/lib/cmdtoolsvm.pm b/connectors/vmware/lib/cmdtoolsvm.pm index 9edde29a4..442778631 100644 --- a/connectors/vmware/lib/cmdtoolsvm.pm +++ b/connectors/vmware/lib/cmdtoolsvm.pm @@ -41,12 +41,17 @@ sub run { my $self = shift; my %filters = ('name' => $self->{lvm}); - my @properties = ('summary.guest.toolsStatus'); + my @properties = ('summary.guest.toolsStatus', 'runtime.connectionState', 'runtime.powerState'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties); if (!defined($result)) { return ; } + return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm}, + $$result[0]->{'runtime.connectionState'}->val, + $$result[0]->{'runtime.powerState'}->val) == 0); + + my $status = 0; # OK my $output = ''; diff --git a/connectors/vmware/lib/common.pm b/connectors/vmware/lib/common.pm index 3a0add393..b0c092ce3 100644 --- a/connectors/vmware/lib/common.pm +++ b/connectors/vmware/lib/common.pm @@ -231,6 +231,39 @@ sub get_entities_host { return $entity_views; } +sub datastore_state { + my ($obj_esxd, $ds, $accessible) = @_; + + if ($accessible !~ /^true|1$/) { + my $output = "Datastore '" . $ds . "' not accessible. Can be disconnected."; + my $status = errors_mask(0, $obj_esxd->{centreonesxd_config}->{datastore_state_error}); + $obj_esxd->print_response(get_status($status) . "|$output\n"); + return 0; + } + + return 1; +} + +sub vm_state { + my ($obj_esxd, $vm, $connection_state, $power_state) = @_; + + if ($connection_state !~ /^connected$/i) { + my $output = "VM '" . $vm . "' not connected. Current Connection State: '$connection_state'."; + my $status = errors_mask(0, $obj_esxd->{centreonesxd_config}->{vm_state_error}); + $obj_esxd->print_response(get_status($status) . "|$output\n"); + return 0; + } + + if ($power_state !~ /^poweredOn$/i) { + my $output = "VM '" . $vm . "' not running. Current Power State: '$power_state'."; + my $status = errors_mask(0, $obj_esxd->{centreonesxd_config}->{vm_state_error}); + $obj_esxd->print_response(get_status($status) . "|$output\n"); + return 0; + } + + return 1; +} + sub stats_info { my ($obj_esxd, $rh, $current_fileno, $args) = @_; my $output;