This commit is contained in:
Quentin Garnier 2015-01-09 11:47:57 +01:00
parent e88ce52fc2
commit 57f361c88c
9 changed files with 123 additions and 48 deletions

View File

@ -88,6 +88,9 @@ sub run {
$filters{name} = qr/$self->{vm_hostname}/;
}
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState');
if (defined($self->{display_description})) {
push @properties, 'config.annotation';
}
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
return if (!defined($result));
@ -150,16 +153,21 @@ sub run {
}
$long_msg .= ' on last ' . int($self->{obj_esxd}->{perfcounter_speriod} / 60) . ' min';
my $prefix_msg = "'$entity_view->{name}'";
if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) &&
$entity_view->{'config.annotation'} ne '') {
$prefix_msg .= ' [' . centreon::esxd::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']';
}
$self->{manager}->{output}->output_add(long_msg => "'$entity_view->{name}' $long_msg");
$self->{manager}->{output}->output_add(long_msg => "$prefix_msg $long_msg");
my $exit = $self->{manager}->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{manager}->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{manager}->{output}->output_add(severity => $exit,
short_msg => "'$entity_view->{name}' $short_msg"
short_msg => "$prefix_msg $short_msg"
);
}
if ($multiple == 0) {
$self->{manager}->{output}->output_add(short_msg => "'$entity_view->{name}' $long_msg");
$self->{manager}->{output}->output_add(short_msg => "$prefix_msg $long_msg");
}
foreach my $id (sort { my ($cida, $cia) = split /:/, $a;
@ -168,7 +176,7 @@ sub run {
$cib = -1 if (!defined($cib) || $cib eq "");
$cia <=> $cib} keys %{$values->{$entity_value}}) {
my ($counter_id, $instance) = split /:/, $id;
next if ($self->{obj_esxd}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} != $counter_id);
next if ($self->{obj_esxd}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{key} != $counter_id);
if ($instance ne "") {
$self->{manager}->{output}->perfdata_add(label => 'cpu_' . $instance . '_MHz' . $extra_label, unit => 'MHz',
value => centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$id}[0])),

View File

@ -94,6 +94,9 @@ sub run {
$filters{name} = qr/$self->{vm_hostname}/;
}
my @properties = ('name', 'datastore', 'runtime.connectionState', 'runtime.powerState');
if (defined($self->{display_description})) {
push @properties, 'config.annotation';
}
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
return if (!defined($result));
@ -166,6 +169,11 @@ sub run {
next if (centreon::esxd::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0 &&
centreon::esxd::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
my $entity_value = $entity_view->{mo_ref}->{value};
my $prefix_msg = "'$entity_view->{name}'";
if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) &&
$entity_view->{'config.annotation'} ne '') {
$prefix_msg .= ' [' . centreon::esxd::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']';
}
$finded |= 1;
my %datastore_lun = ();
@ -187,20 +195,20 @@ sub run {
my $write_counter = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($datastore_lun{$_}{'disk.numberWrite.summation'} / $self->{obj_esxd}->{perfcounter_speriod}));
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $read_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' read iops on '%s' is %s",
$entity_view->{name}, $_, $read_counter));
$self->{manager}->{output}->output_add(long_msg => sprintf("%s read iops on '%s' is %s",
$prefix_msg, $_, $read_counter));
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{manager}->{output}->output_add(severity => $exit,
short_msg => sprintf("'%s' read iops on '%s' is %s",
$entity_view->{name}, $_, $read_counter));
short_msg => sprintf("%s read iops on '%s' is %s",
$prefix_msg, $_, $read_counter));
}
$exit = $self->{manager}->{perfdata}->threshold_check(value => $write_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' write iops on '%s' is %s",
$entity_view->{name}, $_, $write_counter));
$self->{manager}->{output}->output_add(long_msg => sprintf("%s write iops on '%s' is %s",
$prefix_msg, $_, $write_counter));
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{manager}->{output}->output_add(severity => $exit,
short_msg => sprintf("'%s' write iops on '%s' is %s",
$entity_view->{name}, $_, $write_counter));
short_msg => sprintf("%s write iops on '%s' is %s",
$prefix_msg, $_, $write_counter));
}
my $extra_label = '';

View File

@ -76,7 +76,11 @@ sub display_verbose {
$self->{manager}->{output}->output_add(long_msg => $options{label});
foreach my $vm (sort keys %{$options{vms}}) {
$self->{manager}->{output}->output_add(long_msg => ' ' . $vm);
my $prefix = $vm;
if ($options{vms}->{$vm} ne '') {
$prefix .= ' [' . centreon::esxd::common::strip_cr(value => $options{vms}->{$vm}) . ']';
}
$self->{manager}->{output}->output_add(long_msg => ' ' . $prefix);
}
}
@ -92,11 +96,13 @@ sub run {
} else {
$filters{name} = qr/$self->{vm_hostname}/;
}
my @properties;
push @properties, 'name', 'runtime.connectionState', 'runtime.powerState', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit';
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit');
if (defined($self->{check_disk_limit})) {
push @properties, 'config.hardware.device';
}
if (defined($self->{display_description})) {
push @properties, 'config.annotation';
}
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
return if (!defined($result));
@ -128,12 +134,12 @@ sub run {
# CPU Limit
if (defined($entity_view->{'config.cpuAllocation.limit'}) && $entity_view->{'config.cpuAllocation.limit'} != -1) {
$cpu_limit{$entity_view->{name}} = 1;
$cpu_limit{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : '';
}
# Memory Limit
if (defined($entity_view->{'config.memoryAllocation.limit'}) && $entity_view->{'config.memoryAllocation.limit'} != -1) {
$memory_limit{$entity_view->{name}} = 1;
$memory_limit{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : '';
}
# Disk
@ -141,7 +147,7 @@ sub run {
foreach my $device (@{$entity_view->{'config.hardware.device'}}) {
if ($device->isa('VirtualDisk')) {
if (defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
$disk_limit{$entity_view->{name}} = 1;
$disk_limit{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : '';
last;
}
}

View File

@ -90,16 +90,19 @@ sub run {
$filters{name} = qr/$self->{vm_hostname}/;
}
my @properties = ('name', 'summary.config.memorySizeMB', 'runtime.connectionState', 'runtime.powerState');
if (defined($self->{display_description})) {
push @properties, 'config.annotation';
}
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
return if (!defined($result));
my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd},
$result,
[{'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' => ['']}],
[{label => 'mem.active.average', instancess => ['']},
{label => 'mem.overhead.average', instances => ['']},
{label => 'mem.vmmemctl.average', instances => ['']},
{label => 'mem.consumed.average', instances => ['']},
{label => 'mem.shared.average', instances => ['']}],
$self->{obj_esxd}->{perfcounter_speriod},
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
@ -137,16 +140,22 @@ sub run {
my ($used_value, $used_unit) = $self->{manager}->{perfdata}->change_bytes(value => $mem_consumed);
my ($free_value, $free_unit) = $self->{manager}->{perfdata}->change_bytes(value => $mem_free);
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$entity_view->{name},
my $prefix_msg = "'$entity_view->{name}'";
if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) &&
$entity_view->{'config.annotation'} ne '') {
$prefix_msg .= ' [' . centreon::esxd::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']';
}
$self->{manager}->{output}->output_add(long_msg => sprintf("%s Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$prefix_msg,
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $prct_used,
$free_value . " " . $free_unit, $prct_free));
if ($multiple == 0 ||
!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{manager}->{output}->output_add(severity => $exit,
short_msg => sprintf("'%s' Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$entity_view->{name},
short_msg => sprintf("%s Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$prefix_msg,
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $prct_used,
$free_value . " " . $free_unit, $prct_free));

View File

@ -81,11 +81,13 @@ sub run {
} else {
$filters{name} = qr/$self->{vm_hostname}/;
}
my @properties;
push @properties, 'snapshot.rootSnapshotList', 'name', 'runtime.connectionState', 'runtime.powerState';
my @properties = ('snapshot.rootSnapshotList', 'name', 'runtime.connectionState', 'runtime.powerState');
if (defined($self->{check_consolidation}) == 1) {
push @properties, 'runtime.consolidationNeeded';
}
if (defined($self->{display_description})) {
push @properties, 'config.annotation';
}
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
return if (!defined($result));
@ -130,11 +132,16 @@ sub run {
my $diff_time = time() - $create_time;
my $days = int($diff_time / 60 / 60 / 24);
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $diff_time, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $diff_time, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $prefix_msg = "'$entity_view->{name}'";
if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) &&
$entity_view->{'config.annotation'} ne '') {
$prefix_msg .= ' [' . centreon::esxd::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']';
}
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$vm_errors{$exit}->{$entity_view->{name}} = 1;
$self->{manager}->{output}->output_add(long_msg => "'$entity_view->{name}' snapshot create time: " . $snapshot->createTime);
$self->{manager}->{output}->output_add(long_msg => "$prefix_msg snapshot create time: " . $snapshot->createTime);
}
}
}
@ -157,8 +164,8 @@ sub run {
}
if (scalar(keys %vm_consolidate) > 0) {
$self->{manager}->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf('VMs need consolidation: [%s]',
join('] [', sort keys %vm_consolidate)));
short_msg => sprintf('VMs need consolidation: [%s]',
join('] [', sort keys %vm_consolidate)));
}
}

View File

@ -90,13 +90,17 @@ sub run {
$filters{name} = qr/$self->{vm_hostname}/;
}
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState');
if (defined($self->{display_description})) {
push @properties, 'config.annotation';
}
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
return if (!defined($result));
my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd},
$result,
[{'label' => 'mem.swapinRate.average', 'instances' => ['']},
{'label' => 'mem.swapoutRate.average', 'instances' => ['']}],
[{label => 'mem.swapinRate.average', instances => ['']},
{label => 'mem.swapoutRate.average', instances => ['']}],
$self->{obj_esxd}->{perfcounter_speriod},
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
@ -129,15 +133,21 @@ sub run {
my ($swap_in_value, $swap_in_unit) = $self->{manager}->{perfdata}->change_bytes(value => $swap_in);
my ($swap_out_value, $swap_out_unit) = $self->{manager}->{perfdata}->change_bytes(value => $swap_out);
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Swap In: %s Swap Out: %s",
$entity_view->{name},
my $prefix_msg = "'$entity_view->{name}'";
if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) &&
$entity_view->{'config.annotation'} ne '') {
$prefix_msg .= ' [' . centreon::esxd::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']';
}
$self->{manager}->{output}->output_add(long_msg => sprintf("%s Swap In: %s Swap Out: %s",
$prefix_msg,
$swap_in_value . " " . $swap_in_unit . "/s",
$swap_out_value . " " . $swap_out_unit . "/s"));
if ($multiple == 0 ||
!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{manager}->{output}->output_add(severity => $exit,
short_msg => sprintf("'%s' Swap In: %s Swap Out: %s",
$entity_view->{name},
short_msg => sprintf("%s Swap In: %s Swap Out: %s",
$prefix_msg,
$swap_in_value . " " . $swap_in_unit . "/s",
$swap_out_value . " " . $swap_out_unit . "/s"));
}

View File

@ -64,8 +64,12 @@ sub display_verbose {
my ($self, %options) = @_;
foreach my $vm (sort keys %{$options{vms}}) {
$self->{manager}->{output}->output_add(long_msg => $vm);
foreach my $disk (sort keys %{$options{vms}->{$vm}}) {
my $prefix = $vm;
if ($options{vms}->{$vm}->{description} ne '') {
$prefix .= ' [' . centreon::esxd::common::strip_cr(value => $options{vms}->{$vm}->{description}) . ']';
}
$self->{manager}->{output}->output_add(long_msg => $prefix);
foreach my $disk (sort keys %{$options{vms}->{$vm}->{disks}}) {
$self->{manager}->{output}->output_add(long_msg => ' ' . $disk);
}
}
@ -84,6 +88,10 @@ sub run {
$filters{name} = qr/$self->{vm_hostname}/;
}
my @properties = ('name', 'config.hardware.device', 'runtime.connectionState', 'runtime.powerState');
if (defined($self->{display_description})) {
push @properties, 'config.annotation';
}
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
return if (!defined($result));
@ -122,8 +130,10 @@ sub run {
if ($_->isa('VirtualDisk')) {
if (defined($entry) && $_->backing->thinProvisioned =~ /$maps_match{$entry}->{regexp}/) {
$num++;
$disks_vm->{$entity_view->{name}} = {} if (!defined($disks_vm->{$entity_view->{name}}));
$disks_vm->{$entity_view->{name}}->{$_->backing->fileName} = 1;
if (!defined($disks_vm->{$entity_view->{name}})) {
$disks_vm->{$entity_view->{name}} = { disks => {}, description => (defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : '') };
}
$disks_vm->{$entity_view->{name}}->{disks}->{$_->backing->fileName} = 1;
}
}
}

View File

@ -76,7 +76,11 @@ sub display_verbose {
$self->{manager}->{output}->output_add(long_msg => $options{label});
foreach my $vm (sort keys %{$options{vms}}) {
$self->{manager}->{output}->output_add(long_msg => ' ' . $vm);
my $prefix = $vm;
if ($options{vms}->{$vm} ne '') {
$prefix .= ' [' . centreon::esxd::common::strip_cr(value => $options{vms}->{$vm}) . ']';
}
$self->{manager}->{output}->output_add(long_msg => ' ' . $prefix);
}
}
@ -93,6 +97,10 @@ sub run {
$filters{name} = qr/$self->{vm_hostname}/;
}
my @properties = ('name', 'summary.guest.toolsStatus', 'runtime.connectionState', 'runtime.powerState');
if (defined($self->{display_description})) {
push @properties, 'config.annotation';
}
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
return if (!defined($result));
@ -122,11 +130,11 @@ sub run {
my $tools_status = lc($entity_view->{'summary.guest.toolsStatus'}->val);
if ($tools_status eq 'toolsnotinstalled') {
$not_installed{$entity_view->{name}} = 1;
$not_installed{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : '';
} elsif ($tools_status eq 'toolsnotrunning') {
$not_running{$entity_view->{name}} = 1;
$not_running{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : '';
} elsif ($tools_status eq 'toolsold') {
$not_up2date{$entity_view->{name}} = 1;
$not_up2date{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : '';
}
}

View File

@ -304,7 +304,7 @@ sub generic_performance_values_historic {
if (!$$perfdata[0] || !defined($$perfdata[0]->value)) {
$manager_display->{output}->output_add(severity => 'UNKNOWN',
short_msg => 'Cannot get value for counters. Maybe you have call a wrong instance');
short_msg => 'Cannot get value for counters (Maybe, object(s) cannot be reached: disconnected, not running,...)');
return undef;
}
foreach my $val (@$perfdata) {
@ -502,6 +502,15 @@ sub host_state {
return 1;
}
sub strip_cr {
my (%options) = @_;
$options{value} =~ s/^\s+.*\s+$//mg;
$options{value} =~ s/\r//mg;
$options{value} =~ s/\n/ -- /mg;
return $options{value};
}
sub stats_info {
my (%options) = @_;