From 3114bde2da67db2fdbb4e26b97e1d3408019ad5a Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Fri, 21 Sep 2012 13:49:16 +0000 Subject: [PATCH] =?UTF-8?q?Evolution=20#3974=20[vm]=20VMtools=20install?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@19 a5eaa968-4c79-4d68-970d-af6011b5b055 --- connectors/vmware/centreon_esx_client.pl | 18 +++++++++- connectors/vmware/centreon_esxd | 2 ++ connectors/vmware/lib/command-toolsvm.pm | 46 ++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 connectors/vmware/lib/command-toolsvm.pm diff --git a/connectors/vmware/centreon_esx_client.pl b/connectors/vmware/centreon_esx_client.pl index e35f4dd0f..13ee3773d 100644 --- a/connectors/vmware/centreon_esx_client.pl +++ b/connectors/vmware/centreon_esx_client.pl @@ -116,6 +116,9 @@ sub print_usage () { print " -w (--warning) Warning Threshold in percent (default 80)\n"; print " -c (--critical) Critical Threshold in percent (default 90)\n"; print "\n"; + print "'toolsvm':\n"; + print " --vm VM to check (required)\n"; + print "\n"; print "'listhost':\n"; print " None\n"; print "\n"; @@ -355,6 +358,19 @@ sub cpuvm_get_str { return "cpuvm|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'}; } +sub toolsvm_check_arg { + if (!defined($OPTION{'vm'})) { + print "Option --vm is required\n"; + print_usage(); + exit $ERRORS{'UNKNOWN'}; + } + return 0; +} + +sub toolsvm_get_str { + return "toolsvm|" . $OPTION{'vm'}; +} + sub listhost_check_arg { return 0; } @@ -409,7 +425,7 @@ if (!defined($OPTION{'usage'})) { print_usage(); exit $ERRORS{'UNKNOWN'}; } -if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|cpuvm|listhost|listdatastore|listnichost|getmap)$/) { +if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|cpuvm|toolsvm|listhost|listdatastore|listnichost|getmap)$/) { print "Usage value is unknown\n"; print_usage(); exit $ERRORS{'UNKNOWN'}; diff --git a/connectors/vmware/centreon_esxd b/connectors/vmware/centreon_esxd index c186944e0..36d46c042 100644 --- a/connectors/vmware/centreon_esxd +++ b/connectors/vmware/centreon_esxd @@ -48,6 +48,7 @@ require $libpath . '/command-memhost.pm'; require $libpath . '/command-nethost.pm'; require $libpath . '/command-statushost.pm'; require $libpath . '/command-swaphost.pm'; +require $libpath . '/command-toolsvm.pm'; our $session_id; our %sockets = (); @@ -97,6 +98,7 @@ our %checks_descr = ( "memhost" => {'arg' => \&memhost_check_args, 'compute' => \&memhost_compute_args, 'exec' => \&memhost_do}, "swaphost" => {'arg' => \&swaphost_check_args, 'compute' => \&swaphost_compute_args, 'exec' => \&swaphost_do}, "cpuvm" => {'arg' => \&cpuvm_check_args, 'compute' => \&cpuvm_compute_args, 'exec' => \&cpuvm_do}, + "toolsvm" => {'arg' => \&toolsvm_check_args, 'compute' => \&toolsvm_compute_args, 'exec' => \&toolsvm_do}, "listhost" => {'arg' => \&listhost_check_args, 'compute' => \&listhost_compute_args, 'exec' => \&listhost_do}, "listdatastore" => {'arg' => \&listdatastore_check_args, 'compute' => \&listdatastore_compute_args, 'exec' => \&listdatastore_do}, "listnichost" => {'arg' => \&listnichost_check_args, 'compute' => \&listnichost_compute_args, 'exec' => \&listnichost_do}, diff --git a/connectors/vmware/lib/command-toolsvm.pm b/connectors/vmware/lib/command-toolsvm.pm new file mode 100644 index 000000000..f3808dd11 --- /dev/null +++ b/connectors/vmware/lib/command-toolsvm.pm @@ -0,0 +1,46 @@ + +sub toolsvm_check_args { + my ($vm) = @_; + if (!defined($vm) || $vm eq "") { + writeLogFile(LOG_ESXD_ERROR, "ARGS error: need vm hostname\n"); + return 1; + } + return 0; +} + +sub toolsvm_compute_args { + my $lvm = $_[0]; + return ($lvm); +} + +sub toolsvm_do { + my ($lvm) = @_; + + my %filters = ('name' => $lvm); + my @properties = ('summary.guest.toolsStatus'); + my $result = get_entities_host('VirtualMachine', \%filters, \@properties); + if (!defined($result)) { + return ; + } + + my $status = 0; # OK + my $output = ''; + + my $tools_status = lc($$result[0]->{'summary.guest.toolsStatus'}->val); + if ($tools_status eq 'toolsnotinstalled') { + $output = "VMTools not installed on VM '$lvm'."; + $status |= $MYERRORS_MASK{'CRITICAL'}; + } elsif ($tools_status eq 'toolsnotrunning') { + $output = "VMTools not running on VM '$lvm'."; + $status |= $MYERRORS_MASK{'CRITICAL'}; + } elsif ($tools_status eq 'toolsold') { + $output = "VMTools not up-to-date on VM '$lvm'."; + $status |= $MYERRORS_MASK{'WARNING'}; + } else { + $output = "VMTools are OK on VM '$lvm'."; + } + + print_response($ERRORS{$MYERRORS{$status}} . "|$output\n"); +} + +1;