This commit is contained in:
Quentin Garnier 2014-08-18 11:35:46 +02:00
parent 9de2bc5145
commit 9618d5e771
5 changed files with 110 additions and 60 deletions

View File

@ -6,7 +6,7 @@ use IO::Socket;
use Getopt::Long;
my $PROGNAME = $0;
my $VERSION = "1.5.5";
my $VERSION = "1.5.6";
my %ERRORS = (OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, DEPENDENT => 4);
my $socket;
my $separatorin = '~';
@ -37,6 +37,8 @@ my %OPTION = (
check_disk_limit => undef,
details_value => undef,
storage_status => undef,
# For Autodisco
xml => undef,
show_attributes => undef,
@ -81,6 +83,8 @@ GetOptions(
"details-value:s" => \$OPTION{details_value},
"storage-status" => \$OPTION{storage_status},
"xml" => \$OPTION{xml},
"show-attributes" => \$OPTION{show_attributes},
);
@ -111,6 +115,7 @@ sub print_usage () {
print "\n";
print "'healthhost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
print " --storage-status Check storage of ESX\n";
print "\n";
print "'maintenancehost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
@ -198,9 +203,10 @@ sub print_usage () {
print " --critical2 Critical Threshold in percent for cpu ready (default 10)\n";
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 " --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 " --skip-not-running Skip vmtools for vms not running (also template)\n";
print "\n";
print "'snapshotvm':\n";
print " --vm VM to check (required)\n";
@ -209,7 +215,7 @@ sub print_usage () {
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 " --skip-not-running Skip snapshots for vms not running\n";
print "\n";
print "'limitvm':\n";
print " --vm VM to check (required)\n";
@ -226,8 +232,8 @@ sub print_usage () {
print "\n";
print "'memvm':\n";
print " --vm VM to check (required)\n";
print " -w (--warning) Warning Threshold in percent (default 80)\n";
print " -c (--critical) Critical Threshold in percent (default 90)\n";
print " -w (--warning) Warning Threshold in percent\n";
print " -c (--critical) Critical Threshold in percent\n";
print "\n";
print "'swapvm':\n";
print " --vm VM to check (required)\n";
@ -326,12 +332,13 @@ sub healthhost_check_arg {
print_usage();
exit $ERRORS{UNKNOWN};
}
$OPTION{storage_status} = (defined($OPTION{storage_status}) ? 1 : 0);
return 0;
}
sub healthhost_get_str {
return join($separatorin,
('healthhost', $OPTION{vsphere}, $OPTION{'esx-host'}));
('healthhost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{storage_status}));
}
sub datastoreusage_check_arg {
@ -627,12 +634,13 @@ sub toolsvm_check_arg {
}
$OPTION{filter} = (defined($OPTION{filter}) ? 1 : 0);
$OPTION{skip_errors} = (defined($OPTION{skip_errors}) ? 1 : 0);
$OPTION{skip_not_running} = (defined($OPTION{skip_not_running}) ? 1 : 0);
return 0;
}
sub toolsvm_get_str {
return join($separatorin,
('toolsvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{skip_errors}));
('toolsvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{skip_errors}, $OPTION{skip_not_running}));
}
sub snapshotvm_check_arg {
@ -709,10 +717,10 @@ sub memvm_check_arg {
exit $ERRORS{UNKNOWN};
}
if (!defined($OPTION{warning})) {
$OPTION{warning} = 80;
$OPTION{warning} = '';
}
if (!defined($OPTION{critical})) {
$OPTION{critical} = 90;
$OPTION{critical} = '';
}
return 0;
}

View File

@ -20,7 +20,7 @@ BEGIN {
use base qw(centreon::script);
use vars qw(%centreonesxd_config);
my $VERSION = "1.5.5";
my $VERSION = "1.5.6";
my %handlers = (TERM => {}, HUP => {}, CHLD => {});
my @load_modules = ('centreon::esxd::cmdcountvmhost',
'centreon::esxd::cmdcpuhost',

View File

@ -35,13 +35,14 @@ sub checkArgs {
sub initArgs {
my $self = shift;
$self->{lhost} = $_[0];
$self->{storage_status} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
}
sub run {
my $self = shift;
my %filters = ('name' => $self->{lhost});
my @properties = ('runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo',
my @properties = ('runtime.healthSystemRuntime.hardwareStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo',
'runtime.connectionState');
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties);
if (!defined($result)) {
@ -49,7 +50,7 @@ sub run {
}
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{lhost},
$$result[0]->{'runtime.connectionState'}->val) == 0);
$$result[0]->{'runtime.connectionState'}->val) == 0);
my $status = 0; # OK
my $output_critical = '';
@ -62,49 +63,84 @@ sub run {
my $CAlertCount = 0;
my $WAlertCount = 0;
foreach my $entity_view (@$result) {
my $cpuStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo'};
my $cpuStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{cpuStatusInfo};
my $memoryStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{memoryStatusInfo};
my $storageStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{storageStatusInfo};
my $numericSensorInfo = $entity_view->{'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo'};
if (!defined($cpuStatusInfo)) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
"API error - unable to get cpuStatusInfo");
}
if (!defined($numericSensorInfo)) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
"API error - unable to get numericSensorInfo");
}
# CPU
foreach (@$cpuStatusInfo) {
if ($_->status->key =~ /^red$/i) {
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
$_->name . ": " . $_->status->summary);
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$CAlertCount++;
} elsif ($_->status->key =~ /^yellow$/i) {
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
$_->name . ": " . $_->status->summary);
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
$WAlertCount++;
} else {
$OKCount++;
if (defined($cpuStatusInfo)) {
foreach (@$cpuStatusInfo) {
if ($_->status->key =~ /^red$/i) {
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
$_->name . ": " . $_->status->summary);
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$CAlertCount++;
} elsif ($_->status->key =~ /^yellow$/i) {
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
$_->name . ": " . $_->status->summary);
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
$WAlertCount++;
} else {
$OKCount++;
}
}
}
# Memory
if (defined($memoryStatusInfo)) {
foreach (@$memoryStatusInfo) {
if ($_->status->key =~ /^red$/i) {
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
$_->name . ": " . $_->status->summary);
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$CAlertCount++;
} elsif ($_->status->key =~ /^yellow$/i) {
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
$_->name . ": " . $_->status->summary);
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
$WAlertCount++;
} else {
$OKCount++;
}
}
}
# Storage
if ($self->{storage_status} == 1 && defined($storageStatusInfo)) {
foreach (@$storageStatusInfo) {
if ($_->status->key =~ /^red$/i) {
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
$_->name . ": " . $_->status->summary);
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$CAlertCount++;
} elsif ($_->status->key =~ /^yellow$/i) {
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
$_->name . ": " . $_->status->summary);
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
$WAlertCount++;
} else {
$OKCount++;
}
}
}
# Sensor
foreach (@$numericSensorInfo) {
if ($_->healthState->key =~ /^red$/i) {
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
$_->sensorType . " sensor " . $_->name . ": ".$_->healthState->summary);
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$CAlertCount++;
} elsif ($_->healthState->key =~ /^yellow$/i) {
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
$_->sensorType . " sensor " . $_->name . ": ".$_->healthState->summary);
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
$WAlertCount++;
} else {
$OKCount++;
if (defined($numericSensorInfo)) {
foreach (@$numericSensorInfo) {
if ($_->healthState->key =~ /^red$/i) {
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
$_->sensorType . " sensor " . $_->name . ": ".$_->healthState->summary);
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
$CAlertCount++;
} elsif ($_->healthState->key =~ /^yellow$/i) {
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
$_->sensorType . " sensor " . $_->name . ": ".$_->healthState->summary);
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
$WAlertCount++;
} else {
$OKCount++;
}
}
}
}

View File

@ -29,15 +29,15 @@ sub checkArgs {
$self->{logger}->writeLogError("ARGS error: need vm name");
return 1;
}
if (defined($warn) && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
if (defined($warn) && $warn ne '' && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
$self->{logger}->writeLogError("ARGS error: warn threshold must be a positive number");
return 1;
}
if (defined($crit) && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
if (defined($crit) && $crit ne '' && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number");
return 1;
}
if (defined($warn) && defined($crit) && $warn > $crit) {
if (defined($warn) && defined($crit) && $warn ne '' && $crit ne '' && $warn > $crit) {
$self->{logger}->writeLogError("ARGS error: warn threshold must be lower than crit threshold");
return 1;
}
@ -47,8 +47,8 @@ sub checkArgs {
sub initArgs {
my $self = shift;
$self->{lvm} = $_[0];
$self->{warn} = (defined($_[1]) ? $_[1] : 80);
$self->{crit} = (defined($_[2]) ? $_[2] : 90);
$self->{warn} = (defined($_[1]) ? $_[1] : undef);
$self->{crit} = (defined($_[2]) ? $_[2] : undef);
}
sub run {
@ -91,15 +91,15 @@ sub run {
my $status = 0; # OK
my $output = '';
if ($mem_consumed * 100 / ($memory_size / 1024) >= $self->{warn}) {
if (defined($self->{warn}) && $mem_consumed * 100 / ($memory_size / 1024) >= $self->{warn}) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
}
if ($mem_consumed * 100 / ($memory_size / 1024) >= $self->{crit}) {
if (defined($self->{crit}) && $mem_consumed * 100 / ($memory_size / 1024) >= $self->{crit}) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
}
$output = "Memory usage : " . centreon::esxd::common::simplify_number($mem_consumed / 1024 / 1024) . " Go - size : " . centreon::esxd::common::simplify_number($memory_size / 1024 / 1024 / 1024) . " Go - percent : " . centreon::esxd::common::simplify_number($mem_consumed * 100 / ($memory_size / 1024)) . " %";
$output .= "|usage=" . ($mem_consumed * 1024) . "o;" . centreon::esxd::common::simplify_number($memory_size * $self->{warn} / 100, 0) . ";" . centreon::esxd::common::simplify_number($memory_size * $self->{crit} / 100, 0) . ";0;" . ($memory_size) . " size=" . $memory_size . "o" . " overhead=" . ($mem_overhead * 1024) . "o" . " ballooning=" . ($mem_ballooning * 1024) . "o" . " shared=" . ($mem_shared * 1024) . "o" . " active=" . ($mem_active * 1024) . "o" ;
$output .= "|usage=" . ($mem_consumed * 1024) . "o;" . (defined($self->{warn}) ? centreon::esxd::common::simplify_number($memory_size * $self->{warn} / 100, 0) : '') . ";" . (defined($self->{crit}) ? centreon::esxd::common::simplify_number($memory_size * $self->{crit} / 100, 0) : '') . ";0;" . ($memory_size) . " size=" . $memory_size . "o" . " overhead=" . ($mem_overhead * 1024) . "o" . " ballooning=" . ($mem_ballooning * 1024) . "o" . " shared=" . ($mem_shared * 1024) . "o" . " active=" . ($mem_active * 1024) . "o" ;
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
}

View File

@ -37,6 +37,7 @@ sub initArgs {
$self->{lvm} = $_[0];
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
$self->{skip_errors} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
$self->{skip_not_running} = (defined($_[3]) && $_[3] == 1) ? 1 : 0;
}
sub run {
@ -77,6 +78,11 @@ sub run {
}
next;
}
if ($self->{skip_not_running} == 1 &&
!centreon::esxd::common::is_running($virtual->{'runtime.powerState'}->val)) {
next;
}
my $tools_status = lc($virtual->{'summary.guest.toolsStatus'}->val);
if ($tools_status eq 'toolsnotinstalled') {