git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@61 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2013-07-02 09:55:19 +00:00
parent 66b27cab26
commit e6303ecc4f
4 changed files with 145 additions and 11 deletions

View File

@ -6,7 +6,7 @@ use IO::Socket;
use Getopt::Long;
my $PROGNAME = $0;
my $VERSION = "1.3";
my $VERSION = "1.4";
my %ERRORS = ('OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3, 'DEPENDENT' => 4);
my $socket;
@ -24,7 +24,8 @@ my %OPTION = (
"datastore" => undef,
"nic" => undef,
"warning" => undef,
"critical" => undef
"critical" => undef,
"on" => undef,
);
Getopt::Long::Configure('bundling');
@ -48,6 +49,8 @@ GetOptions(
"older=i" => \$OPTION{'older'},
"warn" => \$OPTION{'warn'},
"crit" => \$OPTION{'crit'},
"on" => \$OPTION{'on'},
"w|warning=i" => \$OPTION{'warning'},
"c|critical=i" => \$OPTION{'critical'},
@ -161,6 +164,12 @@ sub print_usage () {
print " -w (--warning) Warning Threshold in MB/s (default 0.8)\n";
print " -c (--critical) Critical Threshold in MB/s (default 1)\n";
print "\n";
print "'thinprovisioningvm':\n";
print " --vm VM to check (required)\n";
print " --on Warn or critical if thinprovisioning set\n";
print " --crit Critical\n";
print " --warn Warn\n";
print "\n";
print "'listhost':\n";
print " None\n";
print "\n";
@ -180,7 +189,7 @@ sub print_usage () {
sub print_help () {
print "##############################################\n";
print "# Copyright (c) 2005-2012 Centreon #\n";
print "# Copyright (c) 2005-2013 Centreon #\n";
print "# Bugs to http://redmine.merethis.net/ #\n";
print "##############################################\n";
print "\n";
@ -482,11 +491,11 @@ sub snapshotvm_get_str {
}
sub datastoresvm_check_arg {
if (!defined($OPTION{'vm'})) {
print "Option --vm is required\n";
print_usage();
exit $ERRORS{'UNKNOWN'};
}
if (!defined($OPTION{'vm'})) {
print "Option --vm is required\n";
print_usage();
exit $ERRORS{'UNKNOWN'};
}
if (!defined($OPTION{'warning'})) {
$OPTION{'warning'} = '';
}
@ -538,6 +547,34 @@ sub swapvm_get_str {
return "swapvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
}
sub thinprovisioningvm_check_arg {
if (!defined($OPTION{'vm'})) {
print "Option --vm is required\n";
print_usage();
exit $ERRORS{'UNKNOWN'};
}
if (!defined($OPTION{'on'})) {
$OPTION{'on'} = 0;
} else {
$OPTION{'on'} = 1;
}
if (!defined($OPTION{'warn'})) {
$OPTION{'warn'} = 0;
} else {
$OPTION{'warn'} = 1;
}
if (!defined($OPTION{'crit'})) {
$OPTION{'crit'} = 0;
} else {
$OPTION{'crit'} = 1;
}
return 0;
}
sub thinprovisioningvm_get_str {
return "thinprovisioningvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'on'} . "|" . $OPTION{'warn'} . "|" . $OPTION{'crit'};
}
sub listhost_check_arg {
return 0;
@ -607,7 +644,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|countvmhost|uptimehost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|swapvm|listhost|listdatastore|listnichost|getmap|stats)$/) {
if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|uptimehost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|swapvm|thinprovisioningvm|listhost|listdatastore|listnichost|getmap|stats)$/) {
print "Usage value is unknown\n";
print_usage();
exit $ERRORS{'UNKNOWN'};

View File

@ -41,6 +41,7 @@ my @load_modules = ('centreon::esxd::cmdcountvmhost',
'centreon::esxd::cmdstatushost',
'centreon::esxd::cmdswaphost',
'centreon::esxd::cmdswapvm',
'centreon::esxd::cmdthinprovisioningvm',
'centreon::esxd::cmdtoolsvm',
'centreon::esxd::cmduptimehost'
);

View File

@ -0,0 +1,96 @@
package centreon::esxd::cmdthinprovisioningvm;
use strict;
use warnings;
use centreon::esxd::common;
sub new {
my $class = shift;
my $self = {};
$self->{logger} = shift;
$self->{obj_esxd} = shift;
$self->{commandName} = 'thinprovisioningvm';
bless $self, $class;
return $self;
}
sub getCommandName {
my $self = shift;
return $self->{commandName};
}
sub checkArgs {
my $self = shift;
my ($vm, $warn, $crit) = @_;
if (!defined($vm) || $vm eq "") {
$self->{logger}->writeLogError("ARGS error: need vm name");
return 1;
}
return 0;
}
sub initArgs {
my $self = shift;
$self->{lvm} = $_[0];
$self->{on} = ((defined($_[1]) and $_[1] ne '') ? $_[1] : 0);
$self->{warn} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 0);
$self->{crit} = ((defined($_[3]) and $_[3] ne '') ? $_[3] : 0);
}
sub run {
my $self = shift;
my %filters = ('name' => $self->{lvm});
my @properties = ('config.hardware.device', 'runtime.connectionState');
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,
undef, 1) == 0);
my $status = 0;
my $output = "";
my $output_append = '';
foreach (@{$$result[0]->{'config.hardware.device'}}) {
if ($_->isa('VirtualDisk')) {
if ($self->{on} == 1 && $self->{warn} == 1 && $_->backing->thinProvisioned == 1) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
"'" . $_->backing->fileName . "'");
}
if ($self->{on} == 1 && $self->{crit} == 1 && $_->backing->thinProvisioned == 1) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
"'" . $_->backing->fileName . "'");
}
if ($self->{on} == 0 && $self->{warn} == 1 && $_->backing->thinProvisioned != 1) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
"'" . $_->backing->fileName . "'");
}
if ($self->{on} == 0 && $self->{crit} == 1 && $_->backing->thinProvisioned != 1) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
"'" . $_->backing->fileName . "'");
}
}
}
if ($output ne "" && $self->{on} == 1) {
$output = "VirtualDisks $output: thinprovisioning actived.";
} elsif ($output ne "" && $self->{on} == 0) {
$output = "VirtualDisks $output: thinprovisioning not actived.";
} else {
$output = "Thinprovisoning virtualdisks are ok.";
}
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
}
1;

View File

@ -245,7 +245,7 @@ sub datastore_state {
}
sub vm_state {
my ($obj_esxd, $vm, $connection_state, $power_state) = @_;
my ($obj_esxd, $vm, $connection_state, $power_state, $nocheck_ps) = @_;
if ($connection_state !~ /^connected$/i) {
my $output = "VM '" . $vm . "' not connected. Current Connection State: '$connection_state'.";
@ -254,7 +254,7 @@ sub vm_state {
return 0;
}
if ($power_state !~ /^poweredOn$/i) {
if (!defined($nocheck_ps) && $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");