Last commit for 1.2

git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@22 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2012-09-25 07:31:58 +00:00
parent 9e63b4ca9c
commit a778707898
5 changed files with 267 additions and 50 deletions

View File

@ -115,6 +115,11 @@ sub print_usage () {
print " -w (--warning) Warning Threshold in ms (latency) (default none)\n";
print " -c (--critical) Critical Threshold in ms (latency) (default none)\n";
print "\n";
print "'countvmhost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
print " -w (--warning) Warning Threshold (default none)\n";
print " -c (--critical) Critical Threshold (default none)\n";
print "\n";
print "'cpuvm':\n";
print " --vm VM to check (required)\n";
print " -w (--warning) Warning Threshold in percent (default 80)\n";
@ -131,6 +136,13 @@ sub print_usage () {
print "\n";
print "'datastoresvm':\n";
print " --vm VM to check (required)\n";
print " -w (--warning) Warning Threshold in IOPS (default none)\n";
print " -c (--critical) Critical Threshold in IOPS (default none)\n";
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 "\n";
print "'listhost':\n";
print " None\n";
@ -352,6 +364,25 @@ sub nethost_get_str {
return "nethost|" . $OPTION{'esx-host'} . "|" . $OPTION{'nic'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
}
sub countvmhost_check_arg {
if (!defined($OPTION{'esx-host'})) {
print "Option --esx-host is required\n";
print_usage();
exit $ERRORS{'UNKNOWN'};
}
if (!defined($OPTION{'warning'})) {
$OPTION{'warning'} = '';
}
if (!defined($OPTION{'critical'})) {
$OPTION{'critical'} = '';
}
return 0;
}
sub countvmhost_get_str {
return "countvmhost|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
}
sub cpuvm_check_arg {
if (!defined($OPTION{'vm'})) {
print "Option --vm is required\n";
@ -416,13 +447,39 @@ sub datastoresvm_check_arg {
print_usage();
exit $ERRORS{'UNKNOWN'};
}
if (!defined($OPTION{'warning'})) {
$OPTION{'warning'} = '';
}
if (!defined($OPTION{'critical'})) {
$OPTION{'critical'} = '';
}
return 0;
}
sub datastoresvm_get_str {
return "datastoresvm|" . $OPTION{'vm'};
return "datastoresvm|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
}
sub memvm_check_arg {
if (!defined($OPTION{'vm'})) {
print "Option --vm is required\n";
print_usage();
exit $ERRORS{'UNKNOWN'};
}
if (!defined($OPTION{'warning'})) {
$OPTION{'warning'} = 80;
}
if (!defined($OPTION{'critical'})) {
$OPTION{'critical'} = 90;
}
return 0;
}
sub memvm_get_str {
return "memvm|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
}
sub listhost_check_arg {
return 0;
}
@ -477,7 +534,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|toolsvm|snapshotvm|datastoresvm|listhost|listdatastore|listnichost|getmap)$/) {
if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|listhost|listdatastore|listnichost|getmap)$/) {
print "Usage value is unknown\n";
print_usage();
exit $ERRORS{'UNKNOWN'};

View File

@ -42,6 +42,7 @@ require '/etc/centreon/centreon_esxd.pm';
require $libpath . '/esxd-common.pm';
require $libpath . '/command-cpuhost.pm';
require $libpath . '/command-cpuvm.pm';
require $libpath . '/command-countvmhost.pm';
require $libpath . '/command-datastoreio.pm';
require $libpath . '/command-datastoreshost.pm';
require $libpath . '/command-datastoresvm.pm';
@ -53,6 +54,7 @@ require $libpath . '/command-listhost.pm';
require $libpath . '/command-listnichost.pm';
require $libpath . '/command-maintenancehost.pm';
require $libpath . '/command-memhost.pm';
require $libpath . '/command-memvm.pm';
require $libpath . '/command-nethost.pm';
require $libpath . '/command-snapshotvm.pm';
require $libpath . '/command-statushost.pm';
@ -106,10 +108,12 @@ our %checks_descr = (
"datastoreshost" => {'arg' => \&datastoreshost_check_args, 'compute' => \&datastoreshost_compute_args, 'exec' => \&datastoreshost_do},
"memhost" => {'arg' => \&memhost_check_args, 'compute' => \&memhost_compute_args, 'exec' => \&memhost_do},
"swaphost" => {'arg' => \&swaphost_check_args, 'compute' => \&swaphost_compute_args, 'exec' => \&swaphost_do},
"countvmhost" => {'arg' => \&countvmhost_check_args, 'compute' => \&countvmhost_compute_args, 'exec' => \&countvmhost_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},
"snapshotvm" => {'arg' => \&snapshotvm_check_args, 'compute' => \&snapshotvm_compute_args, 'exec' => \&snapshotvm_do},
"datastoresvm" => {'arg' => \&datastoresvm_check_args, 'compute' => \&datastoresvm_compute_args, 'exec' => \&datastoresvm_do},
"memvm" => {'arg' => \&memvm_check_args, 'compute' => \&memvm_compute_args, 'exec' => \&memvm_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,74 @@
sub countvmhost_check_args {
my ($lhost, $warn, $crit) = @_;
if (!defined($lhost) || $lhost eq "") {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: need host name\n");
return 1;
}
if (defined($warn) && $warn ne "" && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be a positive number\n");
return 1;
}
if (defined($crit) && $crit ne "" && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: crit threshold must be a positive number\n");
return 1;
}
if (defined($warn) && defined($crit) && $warn ne "" && $crit ne "" && $warn > $crit) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be lower than crit threshold\n");
return 1;
}
return 0;
}
sub countvmhost_compute_args {
my $lhost = $_[0];
my $warn = (defined($_[1]) ? $_[1] : '');
my $crit = (defined($_[2]) ? $_[2] : '');
return ($lhost, $warn, $crit);
}
sub countvmhost_do {
my ($lhost, $warn, $crit) = @_;
my %filters = ('name' => $lhost);
my @properties = ('vm');
my $result = get_entities_host('HostSystem', \%filters, \@properties);
if (!defined($result)) {
return ;
}
my @vm_array = ();
foreach my $entity_view (@$result) {
if (defined $entity_view->vm) {
@vm_array = (@vm_array, @{$entity_view->vm});
}
}
@properties = ('runtime.powerState');
$result = get_views(\@vm_array, \@properties);
if (!defined($result)) {
return ;
}
my $output = '';
my $status = 0; # OK
my $num_poweron = 0;
foreach (@$result) {
my $power_value = lc($_->{'runtime.powerState'}->val);
if ($power_value eq 'poweredon') {
$num_poweron++;
}
}
if (defined($crit) && $crit ne "" && ($num_poweron >= $crit)) {
$output = "CRITICAL: $num_poweron VM running.";
$status |= $MYERRORS_MASK{'CRITICAL'};
} elsif (defined($warn) && $warn ne "" && ($num_poweron >= $warn)) {
$output = "WARNING: $num_poweron VM running.";
$status |= $MYERRORS_MASK{'WARNING'};
} else {
$output = "OK: $num_poweron VM running.";
}
print_response($ERRORS{$MYERRORS{$status}} . "|$output|count=$num_poweron\n");
}
1;

View File

@ -1,15 +1,29 @@
sub datastoresvm_check_args {
my ($lvm) = @_;
my ($lvm, $warn, $crit) = @_;
if (!defined($lvm) || $lvm eq "") {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: need vm name\n");
return 1;
}
if (defined($warn) && $warn ne "" && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be a positive number\n");
return 1;
}
if (defined($crit) && $crit ne "" && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: crit threshold must be a positive number\n");
return 1;
}
if (defined($warn) && defined($crit) && $warn ne "" && $crit ne "" && $warn > $crit) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be lower than crit threshold\n");
return 1;
}
return 0;
}
sub datastoresvm_compute_args {
my $lvm = $_[0];
return ($lvm);
my $warn = (defined($_[1]) ? $_[1] : '');
my $crit = (defined($_[2]) ? $_[2] : '');
return ($lvm, $warn, $crit);
}
sub datastoresvm_do {
@ -35,7 +49,7 @@ sub datastoresvm_do {
}
@properties = ('info');
my $result2 = get_views(\@ds_array, \@properties);
if (!defined($result)) {
if (!defined($result2)) {
return ;
}
@ -43,38 +57,31 @@ sub datastoresvm_do {
my %disk_name = ();
my %datastore_lun = ();
foreach (@$result2) {
writeLogFile(1, Data::Dumper::Dumper($_));
if ($_->info->vmfs->isa('HostVmfsVolume')) {
if ($_->info->isa('VmfsDatastoreInfo')) {
#$uuid_list{$_->volume->uuid} = $_->volume->name;
# Not need. We are on Datastore level (not LUN level)
foreach my $extent (@{$_->info->vmfs->extent}) {
$disk_name{$extent->diskName} = $_->info->vmfs->name;
if (!defined($datastore_lun{$_->info->vmfs->name})) {
%{$datastore_lun{$_->info->vmfs->name}} = ();
%{$datastore_lun{$_->info->vmfs->name}} = ('disk.numberRead.summation' => 0, 'disk.numberWrite.summation' => 0);
}
$datastore_lun{$_->info->vmfs->name}{$extent->diskName} = 0;
}
}
if ($_->info->vmfs->isa('HostNasVolume')) {
#$uuid_list{basename($_->mountInfo->path)} = $_->volume->name;
$disk_name{basename($_->info->mountInfo->path)} = $_->info->vmfs->name;
if (!defined($datastore_lun{$_->info->vmfs->name})) {
%{$datastore_lun{$_->info->vmfs->name}} = ();
}
$datastore_lun{$_->info->vmfs->name}{basename($_->info->mountInfo->path)} = 0;
}
#if ($_->info->isa('NasDatastoreInfo')) {
# Zero disk Info
#}
}
writeLogFile(1, Data::Dumper::Dumper(%datastore_lun));
# Vsphere >= 4.1
my $values = generic_performance_values_historic($$result[0],
[{'label' => 'datastore.totalReadLatency.average', 'instances' => ['*']},
{'label' => 'datastore.totalWriteLatency.average', 'instances' => ['*']},
[{'label' => 'disk.numberRead.summation', 'instances' => ['*']},
{'label' => 'disk.numberWrite.summation', 'instances' => ['*']}],
$perfcounter_speriod);
writeLogFile(1, Data::Dumper::Dumper($values) . "\n");
foreach (keys %$values) {
my ($id, $disk_name) = split(/:/);
$datastore_lun{$disk_name{$disk_name}}{$perfcounter_cache_reverse{$id}} += $values->{$_}[0];
}
my $status = 0; # OK
my $output = '';
@ -84,43 +91,41 @@ sub datastoresvm_do {
my $output_critical = '';
my $output_critical_append = '';
my $perfdata = '';
foreach (keys %uuid_list) {
if (defined($values->{$perfcounter_cache{'datastore.totalReadLatency.average'}->{'key'} . ":" . $_}) and
defined($values->{$perfcounter_cache{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $_})) {
my $read_counter = simplify_number(convert_number($values->{$perfcounter_cache{'datastore.totalReadLatency.average'}->{'key'} . ":" . $_}[0]));
my $write_counter = simplify_number(convert_number($values->{$perfcounter_cache{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $_}[0]));
if (defined($crit) && $crit ne "" && ($read_counter >= $crit)) {
output_add(\$output_critical, \$output_critical_append, ", ",
"read on '" . $uuid_list{$_} . "' is $read_counter ms");
$status |= $MYERRORS_MASK{'WARNING'};
} elsif (defined($warn) && $warn ne "" && ($read_counter >= $warn)) {
output_add(\$output_warning, \$output_warning_append, ", ",
"read on '" . $uuid_list{$_} . "' is $read_counter ms");
$status |= $MYERRORS_MASK{'WARNING'};
}
if (defined($crit) && $crit ne "" && ($write_counter >= $crit)) {
output_add(\$output_critical, \$output_critical_append, ", ",
"write on '" . $uuid_list{$_} . "' is $write_counter ms");
$status |= $MYERRORS_MASK{'WARNING'};
} elsif (defined($warn) && $warn ne "" && ($write_counter >= $warn)) {
output_add(\$output_warning, \$output_warning_append, ", ",
"write on '" . $uuid_list{$_} . "' is $write_counter ms");
$status |= $MYERRORS_MASK{'WARNING'};
}
$perfdata .= " 'trl_" . $uuid_list{$_} . "'=" . $read_counter . "ms 'twl_" . $uuid_list{$_} . "'=" . $write_counter . 'ms';
foreach (keys %datastore_lun) {
my $read_counter = simplify_number(convert_number($datastore_lun{$_}{'disk.numberRead.summation'} / $perfcounter_speriod));
my $write_counter = simplify_number(convert_number($datastore_lun{$_}{'disk.numberWrite.summation'} / $perfcounter_speriod));
if (defined($crit) && $crit ne "" && ($read_counter >= $crit)) {
output_add(\$output_critical, \$output_critical_append, ", ",
"read on '" . $_ . "' is $read_counter ms");
$status |= $MYERRORS_MASK{'WARNING'};
} elsif (defined($warn) && $warn ne "" && ($read_counter >= $warn)) {
output_add(\$output_warning, \$output_warning_append, ", ",
"read on '" . $_ . "' is $read_counter ms");
$status |= $MYERRORS_MASK{'WARNING'};
}
if (defined($crit) && $crit ne "" && ($write_counter >= $crit)) {
output_add(\$output_critical, \$output_critical_append, ", ",
"write on '" . $_ . "' is $write_counter ms");
$status |= $MYERRORS_MASK{'WARNING'};
} elsif (defined($warn) && $warn ne "" && ($write_counter >= $warn)) {
output_add(\$output_warning, \$output_warning_append, ", ",
"write on '" . $_ . "' is $write_counter ms");
$status |= $MYERRORS_MASK{'WARNING'};
}
$perfdata .= " 'riops_" . $_ . "'=" . $read_counter . "iops 'wiops_" . $_ . "'=" . $write_counter . 'iops';
}
if ($output_critical ne "") {
$output .= $output_append . "CRITICAL - Latency counter: $output_critical";
$output .= $output_append . "CRITICAL - Datastore IOPS counter: $output_critical";
$output_append = ". ";
}
if ($output_warning ne "") {
$output .= $output_append . "WARNING - Latency counter: $output_warning";
$output .= $output_append . "WARNING - Datastore IOPS counter: $output_warning";
}
if ($status == 0) {
$output = "All Datastore latency counters are ok";
$output = "All Datastore IOPS counters are ok";
}
print_response($ERRORS{$MYERRORS{$status}} . "|$output|$perfdata\n");
}

View File

@ -0,0 +1,77 @@
sub memvm_check_args {
my ($vm, $warn, $crit) = @_;
if (!defined($vm) || $vm eq "") {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: need vm name\n");
return 1;
}
if (defined($warn) && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be a positive number\n");
return 1;
}
if (defined($crit) && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: crit threshold must be a positive number\n");
return 1;
}
if (defined($warn) && defined($crit) && $warn > $crit) {
writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be lower than crit threshold\n");
return 1;
}
return 0;
}
sub memvm_compute_args {
my $lvm = $_[0];
my $warn = (defined($_[1]) ? $_[1] : 80);
my $crit = (defined($_[2]) ? $_[2] : 90);
return ($lvm, $warn, $crit);
}
sub memvm_do {
my ($lvm, $warn, $crit) = @_;
if (!($perfcounter_speriod > 0)) {
my $status |= $MYERRORS_MASK{'UNKNOWN'};
print_response($ERRORS{$MYERRORS{$status}} . "|Can't retrieve perf counters.\n");
return ;
}
my %filters = ('name' => $lvm);
my @properties = ('summary.config.memorySizeMB');
my $result = get_entities_host('VirtualMachine', \%filters, \@properties);
if (!defined($result)) {
return ;
}
$memory_size = $$result[0]->{'summary.config.memorySizeMB'} * 1024 * 1024;
my $values = generic_performance_values_historic($$result[0],
[{'label' => 'mem.active.average', 'instances' => ['']},
{'label' => 'mem.overhead.average', 'instances' => ['']},
{'label' => 'mem.vmmemctl.average', 'instances' => ['']},
{'label' => 'mem.consumed.average', 'instances' => ['']},
{'label' => 'mem.shared.average', 'instances' => ['']}],
$perfcounter_speriod);
writeLogFile(1, Data::Dumper::Dumper($values));
my $mem_consumed = simplify_number(convert_number($values->{$perfcounter_cache{'mem.consumed.average'}->{'key'} . ":"}[0]));
my $mem_active = simplify_number(convert_number($values->{$perfcounter_cache{'mem.active.average'}->{'key'} . ":"}[0]));
my $mem_overhead = simplify_number(convert_number($values->{$perfcounter_cache{'mem.overhead.average'}->{'key'} . ":"}[0]));
my $mem_ballooning = simplify_number(convert_number($values->{$perfcounter_cache{'mem.vmmemctl.average'}->{'key'} . ":"}[0]));
my $mem_shared = simplify_number(convert_number($values->{$perfcounter_cache{'mem.shared.average'}->{'key'} . ":"}[0]));
my $status = 0; # OK
my $output = '';
if ($mem_consumed * 100 / ($memory_size / 1024) >= $warn) {
$status |= $MYERRORS_MASK{'WARNING'};
}
if ($mem_consumed * 100 / ($memory_size / 1024) >= $crit) {
$status |= $MYERRORS_MASK{'CRITICAL'};
}
$output = "Memory usage : " . simplify_number($mem_consumed / 1024 / 1024) . " Go - size : " . simplify_number($memory_size / 1024 / 1024 / 1024) . " Go - percent : " . simplify_number($mem_consumed * 100 / ($memory_size / 1024)) . " %";
$output .= "|usage=" . ($mem_consumed * 1024) . "o;" . simplify_number($memory_size * $warn / 100, 0) . ";" . simplify_number($memory_size * $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" ;
print_response($ERRORS{$MYERRORS{$status}} . "|$output\n");
}
1;