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:
Quentin Garnier 2013-10-06 12:42:45 +00:00
parent 452e7cdbbd
commit f75bf944ef
6 changed files with 206 additions and 75 deletions

View File

@ -30,6 +30,7 @@ my %OPTION = (
units => undef,
free => undef,
skip_errors => undef,
skip_not_running => undef,
filter => undef,
consolidation => undef,
@ -53,9 +54,11 @@ GetOptions(
"e|esx-host=s" => \$OPTION{'esx-host'},
"vm=s" => \$OPTION{vm},
"skip-errors" => \$OPTION{skip_errors},
"skip-not-running" => \$OPTION{skip_not_running},
"filter" => \$OPTION{filter},
"free" => \$OPTION{free},
"skip-errors" => \$OPTION{skip_errors},
"units=s" => \$OPTION{units},
"light-perfdata" => \$OPTION{'light-perfdata'},
"datastore=s" => \$OPTION{datastore},
@ -99,10 +102,10 @@ sub print_usage () {
print $PROGNAME."\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
print " -H centreon-esxd Host (required)\n";
print " -P centreon-esxd Port (default 5700)\n";
print " --vsphere vsphere name (default: none)\n";
print " -u (--usage) What to check. The list and args (required)\n";
print " -H centreon-esxd Host (required)\n";
print " -P centreon-esxd Port (default 5700)\n";
print " --vsphere vsphere name (default: none)\n";
print " -u (--usage) What to check. The list and args (required)\n";
print "\n";
print "'healthhost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
@ -184,6 +187,8 @@ sub print_usage () {
print "\n";
print "'toolsvm':\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 "'snapshotvm':\n";
print " --vm VM to check (required)\n";
@ -191,13 +196,16 @@ sub print_usage () {
print " --warning Warning threshold in seconds (default: 3 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 " --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 "'limitvm':\n";
print " --vm VM to check (required)\n";
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
print " --warn Warning threshold if set (default)\n";
print " --crit Critical threshold if set\n";
print " --check-disk Check Disk limits (since vsphere 5.0)\n";
print " --vm VM to check (required)\n";
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
print " --warn Warning threshold if set (default)\n";
print " --crit Critical threshold if set\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 "'datastoresvm':\n";
print " --vm VM to check (required)\n";
@ -216,9 +224,11 @@ sub print_usage () {
print "\n";
print "'thinprovisioningvm':\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 " --crit Critical\n";
print " --warn Warn\n";
print " --skip-errors Status OK if vms are disconnected (when you checks multiples)\n";
print "\n";
print "'listhost':\n";
print " None\n";
@ -572,12 +582,14 @@ sub toolsvm_check_arg {
print_usage();
exit $ERRORS{UNKNOWN};
}
$OPTION{filter} = (defined($OPTION{filter}) ? 1 : 0);
$OPTION{skip_errors} = (defined($OPTION{skip_errors}) ? 1 : 0);
return 0;
}
sub toolsvm_get_str {
return join($separatorin,
('toolsvm', $OPTION{vsphere}, $OPTION{vm}));
('toolsvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{skip_errors}));
}
sub snapshotvm_check_arg {
@ -588,6 +600,8 @@ sub snapshotvm_check_arg {
}
$OPTION{filter} = (defined($OPTION{filter}) ? 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})) {
$OPTION{warning} = 86400 * 3;
}
@ -599,7 +613,7 @@ sub snapshotvm_check_arg {
sub snapshotvm_get_str {
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 {
@ -609,6 +623,7 @@ sub limitvm_check_arg {
exit $ERRORS{UNKNOWN};
}
$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})) {
$OPTION{warn} = 1;
} else {
@ -621,7 +636,7 @@ sub limitvm_check_arg {
sub limitvm_get_str {
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 {
@ -693,12 +708,14 @@ sub thinprovisioningvm_check_arg {
$OPTION{on} = (defined($OPTION{on}) ? 1 : 0);
$OPTION{warn} = (defined($OPTION{warn}) ? 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;
}
sub thinprovisioningvm_get_str {
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 {

View File

@ -39,6 +39,7 @@ sub initArgs {
$self->{warn} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
$self->{crit} = (defined($_[3]) && $_[3] == 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) {
$self->{warn} = 1;
}
@ -55,7 +56,7 @@ sub run {
$filters{name} = qr/$self->{lvm}/;
}
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) {
push @properties, 'config.hardware.device';
}
@ -76,6 +77,15 @@ sub run {
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 $limit_set_warn = '';
my $limit_set_crit = '';
@ -115,10 +125,10 @@ sub run {
# Set
if ($limit_set_crit ne '') {
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 '') {
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
"[" . $virtual->{'name'}. "]$limit_set_warn");
"[" . $virtual->{name}. "]$limit_set_warn");
}
}

View File

@ -51,6 +51,8 @@ sub initArgs {
$self->{warning} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 86400 * 3);
$self->{critical} = ((defined($_[3]) and $_[3] ne '') ? $_[3] : 86400 * 5);
$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 {
@ -70,7 +72,7 @@ sub run {
$filters{name} = qr/$self->{lvm}/;
}
my @properties;
push @properties, 'snapshot.rootSnapshotList', 'name';
push @properties, 'snapshot.rootSnapshotList', 'name', 'runtime.connectionState', 'runtime.powerState';
if ($self->{consolidate} == 1) {
push @properties, 'runtime.consolidationNeeded';
}
@ -94,6 +96,20 @@ sub run {
my $consolidate_vms_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;
}
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)) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$consolidate_vms .= $consolidate_vms_append . '[' . $virtual->{'name'} . ']';

View File

@ -35,59 +35,79 @@ sub checkArgs {
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);
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
$self->{on} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 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 {
my $self = shift;
my %filters = ();
my %filters = ('name' => $self->{lvm});
my @properties = ('config.hardware.device', 'runtime.connectionState');
if ($self->{filter} == 0) {
$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);
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 $status = 0; # OK
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 . "'");
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");
}
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 . "'");
next;
}
my $output_disk = '';
foreach (@{$virtual->{'config.hardware.device'}}) {
if ($_->isa('VirtualDisk')) {
if ($self->{on} == 1 && $self->{warn} == 1 && $_->backing->thinProvisioned == 1) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
$output_disk .= ' [' . $_->backing->fileName . ']';
}
if ($self->{on} == 1 && $self->{crit} == 1 && $_->backing->thinProvisioned == 1) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$output_disk .= ' [' . $_->backing->fileName . ']';
}
if ($self->{on} == 0 && $self->{warn} == 1 && $_->backing->thinProvisioned != 1) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
$output_disk .= ' [' . $_->backing->fileName . ']';
}
if ($self->{on} == 0 && $self->{crit} == 1 && $_->backing->thinProvisioned != 1) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$output_disk .= ' [' . $_->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) {
$output = "VirtualDisks $output: thinprovisioning actived.";
$output = "VirtualDisks thinprovisioning actived - $output.";
} elsif ($output ne "" && $self->{on} == 0) {
$output = "VirtualDisks $output: thinprovisioning not actived.";
} else {
$output = "Thinprovisoning virtualdisks are ok.";
$output = "VirtualDisks thinprovisioning not actived - $output.";
}
if ($status == 0) {
$output .= $output_append . "Thinprovisoning virtualdisks are ok.";
}
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");

View File

@ -35,38 +35,88 @@ sub checkArgs {
sub initArgs {
my $self = shift;
$self->{lvm} = $_[0];
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
$self->{skip_errors} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
}
sub run {
my $self = shift;
my %filters = ();
my %filters = ('name' => $self->{lvm});
my @properties = ('summary.guest.toolsStatus', 'runtime.connectionState', 'runtime.powerState');
if ($self->{filter} == 0) {
$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);
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 = '';
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);
if ($tools_status eq 'toolsnotinstalled') {
$output = "VMTools not installed on VM '" . $self->{lvm} . "'.";
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
} elsif ($tools_status eq 'toolsnotrunning') {
$output = "VMTools not running on VM '" . $self->{lvm} . "'.";
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
} elsif ($tools_status eq 'toolsold') {
$output = "VMTools not up-to-date on VM '" . $self->{lvm} . "'.";
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
} else {
$output = "VMTools are OK on VM '" . $self->{lvm} . "'.";
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') {
$not_installed .= ' [' . $virtual->{name} . ']';
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
} elsif ($tools_status eq 'toolsnotrunning') {
$not_running .= ' [' . $virtual->{name} . ']';
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
} elsif ($tools_status eq 'toolsold') {
$not_up2date .= ' [' . $virtual->{name} . ']';
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
}
}
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");

View File

@ -58,9 +58,9 @@ sub connect_vsphere {
alarm(0);
};
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' Login to VirtualCentre server failed: $@");
$logger->writeLogError("'$whoaim' Login to VirtualCenter server failed: $@");
return 1;
}
# eval {
@ -311,6 +311,24 @@ sub is_accessible {
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 {
my ($obj_esxd, $ds, $accessible) = @_;