mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 07:34:35 +02:00
Permits globals checks on somme commands
git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@84 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
452e7cdbbd
commit
f75bf944ef
@ -30,6 +30,7 @@ my %OPTION = (
|
|||||||
units => undef,
|
units => undef,
|
||||||
free => undef,
|
free => undef,
|
||||||
skip_errors => undef,
|
skip_errors => undef,
|
||||||
|
skip_not_running => undef,
|
||||||
filter => undef,
|
filter => undef,
|
||||||
|
|
||||||
consolidation => undef,
|
consolidation => undef,
|
||||||
@ -53,9 +54,11 @@ GetOptions(
|
|||||||
"e|esx-host=s" => \$OPTION{'esx-host'},
|
"e|esx-host=s" => \$OPTION{'esx-host'},
|
||||||
"vm=s" => \$OPTION{vm},
|
"vm=s" => \$OPTION{vm},
|
||||||
|
|
||||||
|
"skip-errors" => \$OPTION{skip_errors},
|
||||||
|
"skip-not-running" => \$OPTION{skip_not_running},
|
||||||
|
|
||||||
"filter" => \$OPTION{filter},
|
"filter" => \$OPTION{filter},
|
||||||
"free" => \$OPTION{free},
|
"free" => \$OPTION{free},
|
||||||
"skip-errors" => \$OPTION{skip_errors},
|
|
||||||
"units=s" => \$OPTION{units},
|
"units=s" => \$OPTION{units},
|
||||||
"light-perfdata" => \$OPTION{'light-perfdata'},
|
"light-perfdata" => \$OPTION{'light-perfdata'},
|
||||||
"datastore=s" => \$OPTION{datastore},
|
"datastore=s" => \$OPTION{datastore},
|
||||||
@ -184,6 +187,8 @@ sub print_usage () {
|
|||||||
print "\n";
|
print "\n";
|
||||||
print "'toolsvm':\n";
|
print "'toolsvm':\n";
|
||||||
print " --vm VM to check (required)\n";
|
print " --vm VM to check (required)\n";
|
||||||
|
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
|
||||||
|
print " --skip-errors Status OK if vms are disconnected (when you checks multiples)\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "'snapshotvm':\n";
|
print "'snapshotvm':\n";
|
||||||
print " --vm VM to check (required)\n";
|
print " --vm VM to check (required)\n";
|
||||||
@ -191,6 +196,8 @@ sub print_usage () {
|
|||||||
print " --warning Warning threshold in seconds (default: 3 days)\n";
|
print " --warning Warning threshold in seconds (default: 3 days)\n";
|
||||||
print " --critical Critical threshold in seconds (default: 5 days)\n";
|
print " --critical Critical threshold in seconds (default: 5 days)\n";
|
||||||
print " --check-consolidation Check if VM needs consolidation (since vsphere 5.0)\n";
|
print " --check-consolidation Check if VM needs consolidation (since vsphere 5.0)\n";
|
||||||
|
print " --skip-errors Status OK if vms are disconnected (when you checks multiples)\n";
|
||||||
|
print " --skip-not-running Skip snapshots from vms not running\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "'limitvm':\n";
|
print "'limitvm':\n";
|
||||||
print " --vm VM to check (required)\n";
|
print " --vm VM to check (required)\n";
|
||||||
@ -198,6 +205,7 @@ sub print_usage () {
|
|||||||
print " --warn Warning threshold if set (default)\n";
|
print " --warn Warning threshold if set (default)\n";
|
||||||
print " --crit Critical threshold if set\n";
|
print " --crit Critical threshold if set\n";
|
||||||
print " --check-disk Check Disk limits (since vsphere 5.0)\n";
|
print " --check-disk Check Disk limits (since vsphere 5.0)\n";
|
||||||
|
print " --skip-errors Status OK if vms are disconencted (when you checks multiples)\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "'datastoresvm':\n";
|
print "'datastoresvm':\n";
|
||||||
print " --vm VM to check (required)\n";
|
print " --vm VM to check (required)\n";
|
||||||
@ -216,9 +224,11 @@ sub print_usage () {
|
|||||||
print "\n";
|
print "\n";
|
||||||
print "'thinprovisioningvm':\n";
|
print "'thinprovisioningvm':\n";
|
||||||
print " --vm VM to check (required)\n";
|
print " --vm VM to check (required)\n";
|
||||||
|
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
|
||||||
print " --on Warn or critical if thinprovisioning set\n";
|
print " --on Warn or critical if thinprovisioning set\n";
|
||||||
print " --crit Critical\n";
|
print " --crit Critical\n";
|
||||||
print " --warn Warn\n";
|
print " --warn Warn\n";
|
||||||
|
print " --skip-errors Status OK if vms are disconnected (when you checks multiples)\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "'listhost':\n";
|
print "'listhost':\n";
|
||||||
print " None\n";
|
print " None\n";
|
||||||
@ -572,12 +582,14 @@ sub toolsvm_check_arg {
|
|||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{UNKNOWN};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
|
$OPTION{filter} = (defined($OPTION{filter}) ? 1 : 0);
|
||||||
|
$OPTION{skip_errors} = (defined($OPTION{skip_errors}) ? 1 : 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub toolsvm_get_str {
|
sub toolsvm_get_str {
|
||||||
return join($separatorin,
|
return join($separatorin,
|
||||||
('toolsvm', $OPTION{vsphere}, $OPTION{vm}));
|
('toolsvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{skip_errors}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub snapshotvm_check_arg {
|
sub snapshotvm_check_arg {
|
||||||
@ -588,6 +600,8 @@ sub snapshotvm_check_arg {
|
|||||||
}
|
}
|
||||||
$OPTION{filter} = (defined($OPTION{filter}) ? 1 : 0);
|
$OPTION{filter} = (defined($OPTION{filter}) ? 1 : 0);
|
||||||
$OPTION{consolidation} = (defined($OPTION{consolidation}) ? 1 : 0);
|
$OPTION{consolidation} = (defined($OPTION{consolidation}) ? 1 : 0);
|
||||||
|
$OPTION{skip_errors} = (defined($OPTION{skip_errors}) ? 1 : 0);
|
||||||
|
$OPTION{skip_not_running} = (defined($OPTION{skip_not_running}) ? 1 : 0);
|
||||||
if (!defined($OPTION{warning})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{warning} = 86400 * 3;
|
$OPTION{warning} = 86400 * 3;
|
||||||
}
|
}
|
||||||
@ -599,7 +613,7 @@ sub snapshotvm_check_arg {
|
|||||||
|
|
||||||
sub snapshotvm_get_str {
|
sub snapshotvm_get_str {
|
||||||
return join($separatorin,
|
return join($separatorin,
|
||||||
('snapshotvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical}, $OPTION{consolidation}));
|
('snapshotvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical}, $OPTION{consolidation}, $OPTION{skip_errors}, $OPTION{skip_not_running}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub limitvm_check_arg {
|
sub limitvm_check_arg {
|
||||||
@ -609,6 +623,7 @@ sub limitvm_check_arg {
|
|||||||
exit $ERRORS{UNKNOWN};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
$OPTION{filter} = (defined($OPTION{filter}) ? 1 : 0);
|
$OPTION{filter} = (defined($OPTION{filter}) ? 1 : 0);
|
||||||
|
$OPTION{skip_errors} = (defined($OPTION{skip_errors}) ? 1 : 0);
|
||||||
if ((!defined($OPTION{warn}) && !defined($OPTION{crit})) || defined($OPTION{warn})) {
|
if ((!defined($OPTION{warn}) && !defined($OPTION{crit})) || defined($OPTION{warn})) {
|
||||||
$OPTION{warn} = 1;
|
$OPTION{warn} = 1;
|
||||||
} else {
|
} else {
|
||||||
@ -621,7 +636,7 @@ sub limitvm_check_arg {
|
|||||||
|
|
||||||
sub limitvm_get_str {
|
sub limitvm_get_str {
|
||||||
return join($separatorin,
|
return join($separatorin,
|
||||||
('limitvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{warn}, $OPTION{crit}, $OPTION{check_disk_limit}));
|
('limitvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{warn}, $OPTION{crit}, $OPTION{check_disk_limit}, $OPTION{skip_errors}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoresvm_check_arg {
|
sub datastoresvm_check_arg {
|
||||||
@ -693,12 +708,14 @@ sub thinprovisioningvm_check_arg {
|
|||||||
$OPTION{on} = (defined($OPTION{on}) ? 1 : 0);
|
$OPTION{on} = (defined($OPTION{on}) ? 1 : 0);
|
||||||
$OPTION{warn} = (defined($OPTION{warn}) ? 1 : 0);
|
$OPTION{warn} = (defined($OPTION{warn}) ? 1 : 0);
|
||||||
$OPTION{crit} = (defined($OPTION{crit}) ? 1 : 0);
|
$OPTION{crit} = (defined($OPTION{crit}) ? 1 : 0);
|
||||||
|
$OPTION{filter} = (defined($OPTION{filter}) ? 1 : 0);
|
||||||
|
$OPTION{skip_errors} = (defined($OPTION{skip_errors}) ? 1 : 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub thinprovisioningvm_get_str {
|
sub thinprovisioningvm_get_str {
|
||||||
return join($separatorin,
|
return join($separatorin,
|
||||||
('thinprovisioningvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{on}, $OPTION{warn}, $OPTION{crit}));
|
('thinprovisioningvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{on}, $OPTION{warn}, $OPTION{crit}, $OPTION{skip_errors}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listhost_check_arg {
|
sub listhost_check_arg {
|
||||||
|
@ -39,6 +39,7 @@ sub initArgs {
|
|||||||
$self->{warn} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
$self->{warn} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||||
$self->{crit} = (defined($_[3]) && $_[3] == 1) ? 1 : 0;
|
$self->{crit} = (defined($_[3]) && $_[3] == 1) ? 1 : 0;
|
||||||
$self->{disk} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
$self->{disk} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
||||||
|
$self->{skip_errors} = (defined($_[5]) && $_[5] == 1) ? 1 : 0;
|
||||||
if ($self->{warn} == 0 && $self->{crit} == 0) {
|
if ($self->{warn} == 0 && $self->{crit} == 0) {
|
||||||
$self->{warn} = 1;
|
$self->{warn} = 1;
|
||||||
}
|
}
|
||||||
@ -55,7 +56,7 @@ sub run {
|
|||||||
$filters{name} = qr/$self->{lvm}/;
|
$filters{name} = qr/$self->{lvm}/;
|
||||||
}
|
}
|
||||||
my @properties;
|
my @properties;
|
||||||
push @properties, 'name', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit';
|
push @properties, 'name', 'runtime.connectionState', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit';
|
||||||
if ($self->{disk} == 1) {
|
if ($self->{disk} == 1) {
|
||||||
push @properties, 'config.hardware.device';
|
push @properties, 'config.hardware.device';
|
||||||
}
|
}
|
||||||
@ -76,6 +77,15 @@ sub run {
|
|||||||
my $output_unknown_append = '';
|
my $output_unknown_append = '';
|
||||||
|
|
||||||
foreach my $virtual (@$result) {
|
foreach my $virtual (@$result) {
|
||||||
|
if (!centreon::esxd::common::is_connected($virtual->{'runtime.connectionState'}->val)) {
|
||||||
|
if ($self->{skip_errors} == 0 || $self->{filter} == 0) {
|
||||||
|
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN');
|
||||||
|
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||||
|
"'" . $virtual->{name} . "' not connected");
|
||||||
|
}
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
my $limit_set_warn = '';
|
my $limit_set_warn = '';
|
||||||
my $limit_set_crit = '';
|
my $limit_set_crit = '';
|
||||||
|
|
||||||
@ -115,10 +125,10 @@ sub run {
|
|||||||
# Set
|
# Set
|
||||||
if ($limit_set_crit ne '') {
|
if ($limit_set_crit ne '') {
|
||||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||||
"[" . $virtual->{'name'}. "]$limit_set_crit");
|
"[" . $virtual->{name}. "]$limit_set_crit");
|
||||||
} elsif ($limit_set_warn ne '') {
|
} elsif ($limit_set_warn ne '') {
|
||||||
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||||
"[" . $virtual->{'name'}. "]$limit_set_warn");
|
"[" . $virtual->{name}. "]$limit_set_warn");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@ sub initArgs {
|
|||||||
$self->{warning} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 86400 * 3);
|
$self->{warning} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 86400 * 3);
|
||||||
$self->{critical} = ((defined($_[3]) and $_[3] ne '') ? $_[3] : 86400 * 5);
|
$self->{critical} = ((defined($_[3]) and $_[3] ne '') ? $_[3] : 86400 * 5);
|
||||||
$self->{consolidate} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
$self->{consolidate} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
||||||
|
$self->{skip_errors} = (defined($_[5]) && $_[5] == 1) ? 1 : 0;
|
||||||
|
$self->{skip_not_running} = (defined($_[6]) && $_[6] == 1) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
@ -70,7 +72,7 @@ sub run {
|
|||||||
$filters{name} = qr/$self->{lvm}/;
|
$filters{name} = qr/$self->{lvm}/;
|
||||||
}
|
}
|
||||||
my @properties;
|
my @properties;
|
||||||
push @properties, 'snapshot.rootSnapshotList', 'name';
|
push @properties, 'snapshot.rootSnapshotList', 'name', 'runtime.connectionState', 'runtime.powerState';
|
||||||
if ($self->{consolidate} == 1) {
|
if ($self->{consolidate} == 1) {
|
||||||
push @properties, 'runtime.consolidationNeeded';
|
push @properties, 'runtime.consolidationNeeded';
|
||||||
}
|
}
|
||||||
@ -94,6 +96,20 @@ sub run {
|
|||||||
my $consolidate_vms_append = '';
|
my $consolidate_vms_append = '';
|
||||||
|
|
||||||
foreach my $virtual (@$result) {
|
foreach my $virtual (@$result) {
|
||||||
|
if (!centreon::esxd::common::is_connected($virtual->{'runtime.connectionState'}->val)) {
|
||||||
|
if ($self->{skip_errors} == 0 || $self->{filter} == 0) {
|
||||||
|
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN');
|
||||||
|
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||||
|
"'" . $virtual->{name} . "' not connected");
|
||||||
|
}
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($self->{skip_not_running} == 1 &&
|
||||||
|
!centreon::esxd::common::is_running($virtual->{'runtime.powerState'}->val)) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
if ($self->{consolidate} == 1 && defined($virtual->{'runtime.consolidationNeeded'}) && ($virtual->{'runtime.consolidationNeeded'} == 1 || $virtual->{'runtime.consolidationNeeded'} =~ /^true$/i)) {
|
if ($self->{consolidate} == 1 && defined($virtual->{'runtime.consolidationNeeded'}) && ($virtual->{'runtime.consolidationNeeded'} == 1 || $virtual->{'runtime.consolidationNeeded'} =~ /^true$/i)) {
|
||||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||||
$consolidate_vms .= $consolidate_vms_append . '[' . $virtual->{'name'} . ']';
|
$consolidate_vms .= $consolidate_vms_append . '[' . $virtual->{'name'} . ']';
|
||||||
|
@ -35,59 +35,79 @@ sub checkArgs {
|
|||||||
sub initArgs {
|
sub initArgs {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->{lvm} = $_[0];
|
$self->{lvm} = $_[0];
|
||||||
$self->{on} = ((defined($_[1]) and $_[1] ne '') ? $_[1] : 0);
|
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||||
$self->{warn} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 0);
|
$self->{on} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 0);
|
||||||
$self->{crit} = ((defined($_[3]) and $_[3] ne '') ? $_[3] : 0);
|
$self->{warn} = ((defined($_[3]) and $_[3] ne '') ? $_[3] : 0);
|
||||||
|
$self->{crit} = ((defined($_[4]) and $_[4] ne '') ? $_[4] : 0);
|
||||||
|
$self->{skip_errors} = (defined($_[5]) && $_[5] == 1) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my %filters = ();
|
||||||
|
|
||||||
my %filters = ('name' => $self->{lvm});
|
if ($self->{filter} == 0) {
|
||||||
my @properties = ('config.hardware.device', 'runtime.connectionState');
|
$filters{name} = qr/^\Q$self->{lvm}\E$/;
|
||||||
|
} else {
|
||||||
|
$filters{name} = qr/$self->{lvm}/;
|
||||||
|
}
|
||||||
|
my @properties = ('name', 'config.hardware.device', 'runtime.connectionState');
|
||||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||||
if (!defined($result)) {
|
if (!defined($result)) {
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm},
|
my $status = 0; # OK
|
||||||
$$result[0]->{'runtime.connectionState'}->val,
|
my $output = '';
|
||||||
undef, 1) == 0);
|
|
||||||
|
|
||||||
my $status = 0;
|
|
||||||
my $output = "";
|
|
||||||
my $output_append = '';
|
my $output_append = '';
|
||||||
foreach (@{$$result[0]->{'config.hardware.device'}}) {
|
my $output_unknown = '';
|
||||||
|
my $output_unknown_append = '';
|
||||||
|
|
||||||
|
foreach my $virtual (@$result) {
|
||||||
|
if (!centreon::esxd::common::is_connected($virtual->{'runtime.connectionState'}->val)) {
|
||||||
|
if ($self->{skip_errors} == 0 || $self->{filter} == 0) {
|
||||||
|
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN');
|
||||||
|
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||||
|
"'" . $virtual->{name} . "' not connected");
|
||||||
|
}
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $output_disk = '';
|
||||||
|
foreach (@{$virtual->{'config.hardware.device'}}) {
|
||||||
if ($_->isa('VirtualDisk')) {
|
if ($_->isa('VirtualDisk')) {
|
||||||
if ($self->{on} == 1 && $self->{warn} == 1 && $_->backing->thinProvisioned == 1) {
|
if ($self->{on} == 1 && $self->{warn} == 1 && $_->backing->thinProvisioned == 1) {
|
||||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||||
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
|
$output_disk .= ' [' . $_->backing->fileName . ']';
|
||||||
"'" . $_->backing->fileName . "'");
|
|
||||||
}
|
}
|
||||||
if ($self->{on} == 1 && $self->{crit} == 1 && $_->backing->thinProvisioned == 1) {
|
if ($self->{on} == 1 && $self->{crit} == 1 && $_->backing->thinProvisioned == 1) {
|
||||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||||
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
|
$output_disk .= ' [' . $_->backing->fileName . ']';
|
||||||
"'" . $_->backing->fileName . "'");
|
|
||||||
}
|
}
|
||||||
if ($self->{on} == 0 && $self->{warn} == 1 && $_->backing->thinProvisioned != 1) {
|
if ($self->{on} == 0 && $self->{warn} == 1 && $_->backing->thinProvisioned != 1) {
|
||||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||||
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
|
$output_disk .= ' [' . $_->backing->fileName . ']';
|
||||||
"'" . $_->backing->fileName . "'");
|
|
||||||
}
|
}
|
||||||
if ($self->{on} == 0 && $self->{crit} == 1 && $_->backing->thinProvisioned != 1) {
|
if ($self->{on} == 0 && $self->{crit} == 1 && $_->backing->thinProvisioned != 1) {
|
||||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||||
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
|
$output_disk .= ' [' . $_->backing->fileName . ']';
|
||||||
"'" . $_->backing->fileName . "'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($output_disk ne '') {
|
||||||
|
centreon::esxd::common::output_add(\$output, \$output_append, ", ",
|
||||||
|
'VM ' . $virtual->{name} . ':' . $output_disk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($output ne "" && $self->{on} == 1) {
|
if ($output ne "" && $self->{on} == 1) {
|
||||||
$output = "VirtualDisks $output: thinprovisioning actived.";
|
$output = "VirtualDisks thinprovisioning actived - $output.";
|
||||||
} elsif ($output ne "" && $self->{on} == 0) {
|
} elsif ($output ne "" && $self->{on} == 0) {
|
||||||
$output = "VirtualDisks $output: thinprovisioning not actived.";
|
$output = "VirtualDisks thinprovisioning not actived - $output.";
|
||||||
} else {
|
}
|
||||||
$output = "Thinprovisoning virtualdisks are ok.";
|
if ($status == 0) {
|
||||||
|
$output .= $output_append . "Thinprovisoning virtualdisks are ok.";
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||||
|
@ -35,38 +35,88 @@ sub checkArgs {
|
|||||||
sub initArgs {
|
sub initArgs {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->{lvm} = $_[0];
|
$self->{lvm} = $_[0];
|
||||||
|
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||||
|
$self->{skip_errors} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my %filters = ();
|
||||||
|
|
||||||
my %filters = ('name' => $self->{lvm});
|
if ($self->{filter} == 0) {
|
||||||
my @properties = ('summary.guest.toolsStatus', 'runtime.connectionState', 'runtime.powerState');
|
$filters{name} = qr/^\Q$self->{lvm}\E$/;
|
||||||
|
} else {
|
||||||
|
$filters{name} = qr/$self->{lvm}/;
|
||||||
|
}
|
||||||
|
|
||||||
|
my @properties = ('name', 'summary.guest.toolsStatus', 'runtime.connectionState', 'runtime.powerState');
|
||||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||||
if (!defined($result)) {
|
if (!defined($result)) {
|
||||||
return ;
|
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 $status = 0; # OK
|
||||||
my $output = '';
|
my $output = '';
|
||||||
|
my $output_append = '';
|
||||||
|
my $output_warning = '';
|
||||||
|
my $output_warning_append = '';
|
||||||
|
my $output_critical = '';
|
||||||
|
my $output_critical_append = '';
|
||||||
|
my $output_unknown = '';
|
||||||
|
my $output_unknown_append = '';
|
||||||
|
my $not_installed = '';
|
||||||
|
my $not_running = '';
|
||||||
|
my $not_up2date = '';
|
||||||
|
|
||||||
my $tools_status = lc($$result[0]->{'summary.guest.toolsStatus'}->val);
|
foreach my $virtual (@$result) {
|
||||||
|
if (!centreon::esxd::common::is_connected($virtual->{'runtime.connectionState'}->val)) {
|
||||||
|
if ($self->{skip_errors} == 0 || $self->{filter} == 0) {
|
||||||
|
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN');
|
||||||
|
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||||
|
"'" . $virtual->{name} . "' not connected");
|
||||||
|
}
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $tools_status = lc($virtual->{'summary.guest.toolsStatus'}->val);
|
||||||
if ($tools_status eq 'toolsnotinstalled') {
|
if ($tools_status eq 'toolsnotinstalled') {
|
||||||
$output = "VMTools not installed on VM '" . $self->{lvm} . "'.";
|
$not_installed .= ' [' . $virtual->{name} . ']';
|
||||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||||
} elsif ($tools_status eq 'toolsnotrunning') {
|
} elsif ($tools_status eq 'toolsnotrunning') {
|
||||||
$output = "VMTools not running on VM '" . $self->{lvm} . "'.";
|
$not_running .= ' [' . $virtual->{name} . ']';
|
||||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||||
} elsif ($tools_status eq 'toolsold') {
|
} elsif ($tools_status eq 'toolsold') {
|
||||||
$output = "VMTools not up-to-date on VM '" . $self->{lvm} . "'.";
|
$not_up2date .= ' [' . $virtual->{name} . ']';
|
||||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||||
} else {
|
}
|
||||||
$output = "VMTools are OK on VM '" . $self->{lvm} . "'.";
|
}
|
||||||
|
|
||||||
|
if ($not_installed ne '') {
|
||||||
|
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||||
|
"VMTools not installed on VM:" . $not_installed);
|
||||||
|
}
|
||||||
|
if ($not_running ne '') {
|
||||||
|
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||||
|
"VMTools not running on VM:" . $not_running);
|
||||||
|
}
|
||||||
|
if ($not_running ne '') {
|
||||||
|
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||||
|
"VMTools not up-to-date on VM:" . $not_running);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($output_unknown ne "") {
|
||||||
|
$output .= $output_append . "UNKNOWN - " . $output_unknown;
|
||||||
|
$output_append = ". ";
|
||||||
|
}
|
||||||
|
if ($output_critical ne "") {
|
||||||
|
$output .= $output_append . "CRITICAL - " . $output_critical;
|
||||||
|
$output_append = ". ";
|
||||||
|
}
|
||||||
|
if ($output_warning ne "") {
|
||||||
|
$output .= $output_append . "WARNING - " . $output_warning;
|
||||||
|
}
|
||||||
|
if ($status == 0) {
|
||||||
|
$output .= $output_append . "VMTools are OK.";
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||||
|
@ -58,9 +58,9 @@ sub connect_vsphere {
|
|||||||
alarm(0);
|
alarm(0);
|
||||||
};
|
};
|
||||||
if($@) {
|
if($@) {
|
||||||
$logger->writeLogError("'$whoaim' No response from VirtualCentre server") if($@ =~ /TIMEOUT/);
|
$logger->writeLogError("'$whoaim' No response from VirtualCenter server") if($@ =~ /TIMEOUT/);
|
||||||
$logger->writeLogError("'$whoaim' You need to upgrade HTTP::Message!") if($@ =~ /HTTP::Message/);
|
$logger->writeLogError("'$whoaim' You need to upgrade HTTP::Message!") if($@ =~ /HTTP::Message/);
|
||||||
$logger->writeLogError("'$whoaim' Login to VirtualCentre server failed: $@");
|
$logger->writeLogError("'$whoaim' Login to VirtualCenter server failed: $@");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
# eval {
|
# eval {
|
||||||
@ -311,6 +311,24 @@ sub is_accessible {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub is_connected {
|
||||||
|
my ($connection_state) = @_;
|
||||||
|
|
||||||
|
if ($connection_state !~ /^connected$/i) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub is_running {
|
||||||
|
my ($power_state) = @_;
|
||||||
|
|
||||||
|
if ($power_state !~ /^poweredOn$/i) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
sub datastore_state {
|
sub datastore_state {
|
||||||
my ($obj_esxd, $ds, $accessible) = @_;
|
my ($obj_esxd, $ds, $accessible) = @_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user