[vm] VMtools installé

git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@19 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2012-09-21 13:49:16 +00:00
parent 1a7c914784
commit 3114bde2da
3 changed files with 65 additions and 1 deletions

View File

@ -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'};

View File

@ -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},

View File

@ -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;