This commit is contained in:
Quentin Garnier 2014-10-27 14:02:42 +01:00
parent ab4985ed69
commit eaee5ccbd3
4 changed files with 378 additions and 268 deletions

View File

@ -144,14 +144,6 @@ sub print_usage () {
print " --filter Use regexp for --datastore option (can check multiples datastores at once)\n"; print " --filter Use regexp for --datastore option (can check multiples datastores at once)\n";
print " --skip-errors Status OK if not enough permissions or others errors (when you checks multiples)\n"; print " --skip-errors Status OK if not enough permissions or others errors (when you checks multiples)\n";
print "\n"; print "\n";
print "'nethost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
print " --nic Physical nic name 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 " --filter Use regexp for --nic option (can check multiple nics at once)\n";
print " --skip-errors Status OK if some nic are down (when you checks multiples)\n";
print "\n";
print "'datastoreshost':\n"; print "'datastoreshost':\n";
print " -e (--esx-host) Esx Host to check (required)\n"; print " -e (--esx-host) Esx Host to check (required)\n";
print " -w (--warning) Warning Threshold in ms (latency) (default none)\n"; print " -w (--warning) Warning Threshold in ms (latency) (default none)\n";
@ -159,13 +151,6 @@ sub print_usage () {
print " --datastore Datastores to check (can use a regexp with --filter)\n"; print " --datastore Datastores to check (can use a regexp with --filter)\n";
print " --filter Use regexp for --datastore option (can check multiples datastores at once)\n"; print " --filter Use regexp for --datastore option (can check multiples datastores at once)\n";
print "\n"; print "\n";
print "'countvmhost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
print " -w (--warning) Warning Threshold if more VMs on (default none)\n";
print " -c (--critical) Critical Threshold if more VMs on (default none)\n";
print " --warning2 Warning Threshold if more VMs not on (default none)\n";
print " --critical2 Critical Threshold if more VMs not on (default none)\n";
print "\n";
print "'cpuvm':\n"; print "'cpuvm':\n";
print " --vm VM to check (required)\n"; print " --vm VM to check (required)\n";
print " -w (--warning) Warning Threshold in percent for cpu average (default 80)\n"; print " -w (--warning) Warning Threshold in percent for cpu average (default 80)\n";

View File

@ -9,7 +9,6 @@ sub new {
my $class = shift; my $class = shift;
my $self = {}; my $self = {};
$self->{logger} = shift; $self->{logger} = shift;
$self->{obj_esxd} = shift;
$self->{commandName} = 'countvmhost'; $self->{commandName} = 'countvmhost';
bless $self, $class; bless $self, $class;
@ -22,108 +21,131 @@ sub getCommandName {
} }
sub checkArgs { sub checkArgs {
my $self = shift; my ($self, %options) = @_;
my ($lhost, $warn, $crit, $warn2, $crit2) = @_;
if (!defined($lhost) || $lhost eq "") { if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
$self->{logger}->writeLogError("ARGS error: need host name"); $options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: esx hostname cannot be null");
return 1; return 1;
} }
if (defined($warn) && $warn ne "" && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) { if (defined($options{arguments}->{disconnect_status}) &&
$self->{logger}->writeLogError("ARGS error: warn threshold must be a positive number"); $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{disconnect_status}) == 0) {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: wrong value for disconnect status '" . $options{arguments}->{disconnect_status} . "'");
return 1; return 1;
} }
if (defined($crit) && $crit ne "" && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) { foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) {
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number"); if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
return 1; return 1;
} }
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;
}
if (defined($warn2) && $warn2 ne "" && $warn2 !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
$self->{logger}->writeLogError("ARGS error: warn2 threshold must be a positive number");
return 1;
}
if (defined($crit2) && $crit2 ne "" && $crit2 !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
$self->{logger}->writeLogError("ARGS error: crit2 threshold must be a positive number");
return 1;
}
if (defined($warn2) && defined($crit2) && $warn2 ne "" && $crit2 ne "" && $warn2 > $crit2) {
$self->{logger}->writeLogError("ARGS error: warn2 threshold must be lower than crit2 threshold");
return 1;
} }
return 0; return 0;
} }
sub initArgs { sub initArgs {
my $self = shift; my ($self, %options) = @_;
$self->{lhost} = $_[0];
$self->{warn} = (defined($_[1]) ? $_[1] : ''); foreach (keys %{$options{arguments}}) {
$self->{crit} = (defined($_[2]) ? $_[2] : ''); $self->{$_} = $options{arguments}->{$_};
$self->{warn2} = (defined($_[3]) ? $_[3] : ''); }
$self->{crit2} = (defined($_[4]) ? $_[4] : ''); $self->{manager} = centreon::esxd::common::init_response();
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) {
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
}
}
sub set_connector {
my ($self, %options) = @_;
$self->{obj_esxd} = $options{connector};
} }
sub run { sub run {
my $self = shift; my $self = shift;
my %filters = ('name' => $self->{lhost}); my %filters = ();
my @properties = ('vm', 'runtime.connectionState'); my $multiple = 0;
if (defined($self->{esx_hostname}) && !defined($self->{filter})) {
$filters{name} = qr/^\Q$self->{esx_hostname}\E$/;
} elsif (!defined($self->{esx_hostname})) {
$filters{name} = qr/.*/;
} else {
$filters{name} = qr/$self->{esx_hostname}/;
}
my @properties = ('name', 'vm', 'runtime.connectionState');
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties);
if (!defined($result)) { return if (!defined($result));
return ;
if (scalar(@$result) > 1) {
$multiple = 1;
} }
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{lhost}, #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 @vm_array = (); my @vm_array = ();
foreach my $entity_view (@$result) { foreach my $entity_view (@$result) {
if (defined $entity_view->vm) { if (defined($entity_view->vm)) {
@vm_array = (@vm_array, @{$entity_view->vm}); @vm_array = (@vm_array, @{$entity_view->vm});
} }
} }
@properties = ('runtime.powerState'); @properties = ('runtime.powerState');
$result = centreon::esxd::common::get_views($self->{obj_esxd}, \@vm_array, \@properties); my $result2 = centreon::esxd::common::get_views($self->{obj_esxd}, \@vm_array, \@properties);
if (!defined($result)) { return if (!defined($result2));
return ;
if ($multiple == 1) {
$self->{manager}->{output}->output_add(severity => 'OK',
short_msg => sprintf("All ESX Hosts are ok"));
} }
my $output = ''; foreach my $entity_view (@$result) {
my $status = 0; # OK next if (centreon::esxd::common::host_state(connector => $self->{obj_esxd},
my $num_poweron = 0; hostname => $entity_view->{name},
my $num_powerother = 0; state => $entity_view->{'runtime.connectionState'}->val,
status => $self->{disconnect_status},
foreach (@$result) { multiple => $multiple) == 0);
my $power_value = lc($_->{'runtime.powerState'}->val); my $extra_label = '';
if ($power_value eq 'poweredon') { $extra_label = '_' . $entity_view->{name} if ($multiple == 1);
$num_poweron++; my %vm_states = (poweredon => 0, poweredoff => 0, suspended => 0);
} else { if (defined($entity_view->vm)) {
$num_powerother++; foreach my $vm_host (@{$entity_view->vm}) {
foreach my $vm (@{$result2}) {
if ($vm_host->{value} eq $vm->{mo_ref}->{value}) {
my $power_value = lc($vm->{'runtime.powerState'}->val);
$vm_states{$power_value}++;
last;
}
} }
} }
if (defined($self->{crit}) && $self->{crit} ne "" && ($num_poweron >= $self->{crit})) {
$output = "CRITICAL: $num_poweron VM running";
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
} elsif (defined($self->{warn}) && $self->{warn} ne "" && ($num_poweron >= $self->{warn})) {
$output = "WARNING: $num_poweron VM running";
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
} else {
$output .= "OK: $num_poweron VM running";
} }
if (defined($self->{crit2}) && $self->{crit2} ne "" && ($num_powerother >= $self->{crit2})) { foreach my $labels ((['poweredon', 'warning_on', 'critical_on'],
$output .= " - CRITICAL: $num_powerother VM not running."; ['poweredoff', 'warning_off', 'critical_off'],
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL'); ['suspended', 'warning_suspended', 'critical_suspended'])) {
} elsif (defined($self->{warn2}) && $self->{warn2} ne "" && ($num_powerother >= $self->{warn2})) { my $exit = $self->{manager}->{perfdata}->threshold_check(value => $vm_states{$labels->[0]},
$output .= " - WARNING: $num_powerother VM not running."; threshold => [ { label => $labels->[2], exit_litteral => 'critical' },
$status = centreon::esxd::common::errors_mask($status, 'WARNING'); { label => $labels->[1], exit_litteral => 'warning' } ]);
} else { $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' %s VM(s) %s", $entity_view->{name},
$output .= " - OK: $num_powerother VM not running."; $vm_states{$labels->[0]},
$labels->[0]));
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' %s VM(s) %s", $entity_view->{name},
$vm_states{$labels->[0]},
$labels->[0]));
} }
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output|count_on=$num_poweron;$self->{warn};$self->{crit};0; count_not_on=$num_powerother;$self->{warn2};$self->{crit2};0;\n"); $self->{manager}->{output}->perfdata_add(label => $labels->[0] . $extra_label,
value => $vm_states{$labels->[0]},
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => $labels->[1]),
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => $labels->[2]),
min => 0, max => $vm_states{poweredoff} + $vm_states{suspended} + $vm_states{poweredon});
}
}
} }
1; 1;

View File

@ -9,7 +9,6 @@ sub new {
my $class = shift; my $class = shift;
my $self = {}; my $self = {};
$self->{logger} = shift; $self->{logger} = shift;
$self->{obj_esxd} = shift;
$self->{commandName} = 'nethost'; $self->{commandName} = 'nethost';
bless $self, $class; bless $self, $class;
@ -21,71 +20,109 @@ sub getCommandName {
return $self->{commandName}; return $self->{commandName};
} }
sub checkArgs {
my $self = shift;
my ($host, $pnic, $filter, $warn, $crit) = @_;
if (!defined($host) || $host eq "") { sub checkArgs {
$self->{logger}->writeLogError("ARGS error: need hostname"); my ($self, %options) = @_;
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: esx hostname cannot be null");
return 1; return 1;
} }
if (!defined($pnic) || $pnic eq "") { if (defined($options{arguments}->{nic_name}) && $options{arguments}->{nic_name} eq "") {
$self->{logger}->writeLogError("ARGS error: need physical nic name"); $options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: nic name cannot be null");
return 1; return 1;
} }
if (defined($warn) && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) { if (defined($options{arguments}->{disconnect_status}) &&
$self->{logger}->writeLogError("ARGS error: warn threshold must be a positive number"); $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{disconnect_status}) == 0) {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: wrong value for disconnect status '" . $options{arguments}->{disconnect_status} . "'");
return 1; return 1;
} }
if (defined($crit) && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) { if (defined($options{arguments}->{link_down_status}) &&
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number"); $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{link_down_status}) == 0) {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: wrong value for link down status '" . $options{arguments}->{link_down_status} . "'");
return 1; return 1;
} }
if (defined($warn) && defined($crit) && $warn > $crit) { foreach my $label (('warning_in', 'critical_in', 'warning_out', 'critical_out')) {
$self->{logger}->writeLogError("ARGS error: warn threshold must be lower than crit threshold"); if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
return 1; return 1;
} }
}
return 0; return 0;
} }
sub initArgs { sub initArgs {
my $self = shift; my ($self, %options) = @_;
$self->{lhost} = $_[0];
$self->{pnic} = $_[1]; foreach (keys %{$options{arguments}}) {
$self->{filter} = (defined($_[2]) && $_[2] == 1) ? 1 : 0; $self->{$_} = $options{arguments}->{$_};
$self->{warn} = (defined($_[3]) ? $_[3] : 80); }
$self->{crit} = (defined($_[4]) ? $_[4] : 90); $self->{manager} = centreon::esxd::common::init_response();
$self->{skip_errors} = (defined($_[5]) && $_[5] == 1) ? 1 : 0; $self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
foreach my $label (('warning_in', 'critical_in', 'warning_out', 'critical_out')) {
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
}
}
sub set_connector {
my ($self, %options) = @_;
$self->{obj_esxd} = $options{connector};
} }
sub run { sub run {
my $self = shift; my $self = shift;
if (!($self->{obj_esxd}->{perfcounter_speriod} > 0)) { if (!($self->{obj_esxd}->{perfcounter_speriod} > 0)) {
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN'); $self->{manager}->{output}->output_add(severity => 'UNKNOWN',
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Can't retrieve perf counters.\n"); short_msg => "Can't retrieve perf counters");
return ; return ;
} }
my %filters = ('name' => $self->{lhost}); my %filters = ();
my @properties = ('config.network.pnic', 'runtime.connectionState', 'config.network.vswitch', 'config.network.proxySwitch'); my $multiple = 0;
if (defined($self->{esx_hostname}) && !defined($self->{filter})) {
$filters{name} = qr/^\Q$self->{esx_hostname}\E$/;
} elsif (!defined($self->{esx_hostname})) {
$filters{name} = qr/.*/;
} else {
$filters{name} = qr/$self->{esx_hostname}/;
}
my @properties = ('name', 'config.network.pnic', 'runtime.connectionState', 'config.network.vswitch', 'config.network.proxySwitch');
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties);
if (!defined($result)) { return if (!defined($result));
return ;
if (scalar(@$result) > 1) {
$multiple = 1;
}
if ($multiple == 1) {
$self->{manager}->{output}->output_add(severity => 'OK',
short_msg => sprintf("All traffics are ok"));
} }
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{lhost}, my $pnic_def_up = {};
$$result[0]->{'runtime.connectionState'}->val) == 0); my $pnic_def_down = {};
my $query_perfs = [];
foreach my $entity_view (@$result) {
next if (centreon::esxd::common::host_state(connector => $self->{obj_esxd},
hostname => $entity_view->{name},
state => $entity_view->{'runtime.connectionState'}->val,
status => $self->{disconnect_status},
multiple => $multiple) == 0);
$pnic_def_up->{$entity_view->{mo_ref}->{value}} = {};
$pnic_def_down->{$entity_view->{mo_ref}->{value}} = {};
my %nic_in_vswitch = (); my %nic_in_vswitch = ();
my %pnic_def_up = ();
my %pnic_def_down = ();
my $instances = []; my $instances = [];
my $filter_ok = 0; my $filter_ok = 0;
# Get Name from vswitch # Get Name from vswitch
if (defined($$result[0]->{'config.network.vswitch'})) { if (defined($entity_view->{'config.network.vswitch'})) {
foreach (@{$$result[0]->{'config.network.vswitch'}}) { foreach (@{$entity_view->{'config.network.vswitch'}}) {
next if (!defined($_->{pnic})); next if (!defined($_->{pnic}));
foreach my $keynic (@{$_->{pnic}}) { foreach my $keynic (@{$_->{pnic}}) {
$nic_in_vswitch{$keynic} = 1; $nic_in_vswitch{$keynic} = 1;
@ -93,8 +130,8 @@ sub run {
} }
} }
# Get Name from proxySwitch # Get Name from proxySwitch
if (defined($$result[0]->{'config.network.proxySwitch'})) { if (defined($entity_view->{'config.network.proxySwitch'})) {
foreach (@{$$result[0]->{'config.network.proxySwitch'}}) { foreach (@{$entity_view->{'config.network.proxySwitch'}}) {
next if (!defined($_->{pnic})); next if (!defined($_->{pnic}));
foreach my $keynic (@{$_->{pnic}}) { foreach my $keynic (@{$_->{pnic}}) {
$nic_in_vswitch{$keynic} = 1; $nic_in_vswitch{$keynic} = 1;
@ -102,111 +139,120 @@ sub run {
} }
} }
foreach (@{$$result[0]->{'config.network.pnic'}}) { foreach (@{$entity_view->{'config.network.pnic'}}) {
# Not in vswitch. Skip # Not in vswitch. Skip
if (!defined($nic_in_vswitch{$_->key})) { next if (!defined($nic_in_vswitch{$_->key}));
next;
}
# Check filter # Check filter
next if ($self->{filter} == 0 && $_->device !~ /^\Q$self->{pnic}\E$/); if (defined($self->{nic_name}) && !defined($self->{filter_nic}) && $_->device ne $self->{nic_name}) {
next if ($self->{filter} == 1 && $_->device !~ /$self->{pnic}/); next;
} elsif (defined($self->{nic_name}) && defined($self->{filter_nic}) && $_->device !~ /$self->{nic_name}/) {
next;
}
$filter_ok = 1; $filter_ok = 1;
if (defined($_->linkSpeed)) { if (defined($_->linkSpeed)) {
$pnic_def_up{$_->device} = $_->linkSpeed->speedMb; $pnic_def_up->{$entity_view->{mo_ref}->{value}}->{$_->device} = $_->linkSpeed->speedMb;
push @$instances, $_->device; push @$instances, $_->device;
} else { } else {
$pnic_def_down{$_->device} = 1; $pnic_def_down->{$entity_view->{mo_ref}->{value}}->{$_->device} = 1;
} }
} }
if ($filter_ok == 0) { if ($filter_ok == 0) {
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN'); $self->{manager}->{output}->output_add(severity => 'UNKNOWN',
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Can't get physical nic with filter '$self->{pnic}'. (or physical nic not in a 'vswitch' or 'dvswitch')\n"); short_msg => sprintf("%s can't get physical nic with filter '%s'. (or physical nic not in a 'vswitch' or 'dvswitch'",
return ; $entity_view->{name}, $self->{nic_name}));
next;
} }
if ($#${instances} == -1) { if (scalar(@${instances}) == 0 &&
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN'); ($multiple == 0 || ($multiple == 1 && !$self->{manager}->{output}->is_status(value => $self->{link_down_status}, compare => 'ok', litteral => 1)))) {
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Link(s) '" . join("','", keys %pnic_def_down) . "' is(are) down.\n"); $self->{manager}->{output}->output_add(severity => $self->{link_down_status},
return ; short_msg => sprintf("%s Link(s) '%s' is(are) down",
$entity_view->{name}, join("','", keys %{$pnic_def_down->{$entity_view->{mo_ref}->{value}}})));
next;
} }
push @$query_perfs, {
entity => $entity_view,
metrics => [
{label => 'net.received.average', instances => $instances},
{label => 'net.transmitted.average', instances => $instances}
]
};
}
# Nothing to retrieve. problem before already.
return if (scalar(@$query_perfs) == 0);
my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd}, my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd},
$result, undef,
[{'label' => 'net.received.average', 'instances' => $instances}, $query_perfs,
{'label' => 'net.transmitted.average', 'instances' => $instances}], $self->{obj_esxd}->{perfcounter_speriod},
$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); return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $status = 0; # OK foreach my $entity_view (@$result) {
my $output = ""; my $entity_value = $entity_view->{mo_ref}->{value};
my $output_append = ''; if (scalar(keys %{$pnic_def_down->{$entity_value}}) > 0 &&
my $output_warning = ''; ($multiple == 0 || !$self->{manager}->{output}->is_status(value => $self->{link_down_status}, compare => 'ok', litteral => 1))) {
my $output_warning_append = ''; $self->{manager}->{output}->output_add(severity => $self->{link_down_status},
my $output_critical = ''; short_msg => sprintf("%s Link(s) '%s' is(are) down",
my $output_critical_append = ''; $entity_view->{name}, join("','", keys %{$pnic_def_down->{$entity_value}})));
my $output_unknown = '';
my $output_unknown_append = '';
my $output_ok_unit = '';
my $perfdata = '';
my @nic_downs = keys %pnic_def_down;
if ($#nic_downs >= 0) {
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, ", ",
"Link(s) '" . join("','", @nic_downs) . "' is(are) down");
}
} }
foreach (keys %pnic_def_up) { my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$pnic_def_up->{$entity_value}}) {
# KBps
my $traffic_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'net.received.average'}->{key} . ":" . $_}[0])) * 1024 * 8;
my $traffic_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'net.transmitted.average'}->{key} . ":" . $_}[0])) * 1024 * 8;
my $interface_speed = $pnic_def_up->{$entity_value}->{$_} * 1024 * 1024;
my $in_prct = $traffic_in * 100 / $interface_speed;
my $out_prct = $traffic_out * 100 / $interface_speed;
my $traffic_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'net.received.average'}->{'key'} . ":" . $_}[0])); my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical_in', exit_litteral => 'critical' }, { label => 'warning_in', exit_litteral => 'warning' } ]);
my $traffic_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'net.transmitted.average'}->{'key'} . ":" . $_}[0])); my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical_out', exit_litteral => 'critical' }, { label => 'warning_out', exit_litteral => 'warning' } ]);
$output_ok_unit = "Traffic In : " . centreon::esxd::common::simplify_number($traffic_in / 1024) . " MB/s (" . centreon::esxd::common::simplify_number($traffic_in / 1024 * 100 / $pnic_def_up{$_}) . " %), Out : " . centreon::esxd::common::simplify_number($traffic_out / 1024) . " MB/s (" . centreon::esxd::common::simplify_number($traffic_out / 1024 * 100 / $pnic_def_up{$_}) . " %)"; my ($in_value, $in_unit) = $self->{manager}->{perfdata}->change_bytes(value => $traffic_in, network => 1);
my ($out_value, $out_unit) = $self->{manager}->{perfdata}->change_bytes(value => $traffic_out, network => 1);
my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
push @exits, $exit;
if (($traffic_in / 1024 * 100 / $pnic_def_up{$_}) >= $self->{crit} || ($traffic_out / 1024 * 100 / $pnic_def_up{$_}) >= $self->{crit}) { my $output = sprintf("Interface '%s' Traffic In : %s/s (%.2f %%), Out : %s/s (%.2f %%) ", $_,
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ". ", $in_value . $in_unit, $in_prct,
"'$_' Traffic In : " . centreon::esxd::common::simplify_number($traffic_in / 1024) . " MB/s (" . centreon::esxd::common::simplify_number($traffic_in / 1024 * 100 / $pnic_def_up{$_}) . " %), Out : " . centreon::esxd::common::simplify_number($traffic_out / 1024) . " MB/s (" . centreon::esxd::common::simplify_number($traffic_out / 1024 * 100 / $pnic_def_up{$_}) . " %)"); $out_value . $out_unit, $out_prct);
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL'); $long_msg .= $long_msg_append . $output;
} elsif (($traffic_in / 1024 * 100 / $pnic_def_up{$_}) >= $self->{warn} || ($traffic_out / 1024 * 100 / $pnic_def_up{$_}) >= $self->{warn}) { $long_msg_append = ', ';
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ". ", if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || $multiple == 0) {
"'$_' Traffic In : " . centreon::esxd::common::simplify_number($traffic_in / 1024) . " MB/s (" . centreon::esxd::common::simplify_number($traffic_in / 1024 * 100 / $pnic_def_up{$_}) . " %), Out : " . centreon::esxd::common::simplify_number($traffic_out / 1024) . " MB/s (" . centreon::esxd::common::simplify_number($traffic_out / 1024 * 100 / $pnic_def_up{$_}) . " %)"); $short_msg .= $short_msg_append . $output;
$status = centreon::esxd::common::errors_mask($status, 'WARNING'); $short_msg_append = ', ';
} }
my $warn_perfdata = ($pnic_def_up{$_} * $self->{warn} / 100) * 1024 * 1024; my $extra_label = '';
my $crit_perfdata = ($pnic_def_up{$_} * $self->{crit} / 100) * 1024 * 1024; $extra_label = '_' . $entity_view->{name} if ($multiple == 1);
$self->{manager}->{output}->perfdata_add(label => 'traffic_in' . $extra_label, unit => 'b/s',
if ($self->{filter} == 1) { value => sprintf("%.2f", $traffic_in),
$perfdata .= " 'traffic_in_" . $_ . "'=" . ($traffic_in * 1024) . "B/s;$warn_perfdata;$crit_perfdata;0; 'traffic_out_" . $_ . "'=" . (($traffic_out * 1024)) . "B/s;$warn_perfdata;$crit_perfdata;0;"; warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed),
} else { critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed),
$perfdata .= " traffic_in=" . ($traffic_in * 1024) . "B/s;$warn_perfdata;$crit_perfdata;0; traffic_out=" . (($traffic_out * 1024)) . "B/s;$warn_perfdata;$crit_perfdata;0;"; min => 0, max => $interface_speed);
} $self->{manager}->{output}->perfdata_add(label => 'traffic_out' . $extra_label, unit => 'b/s',
value => sprintf("%.2f", $traffic_out),
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $interface_speed),
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $interface_speed),
min => 0, max => $interface_speed);
} }
if ($output_unknown ne "") { $self->{manager}->{output}->output_add(long_msg => "$entity_view->{name}' $long_msg");
$output .= $output_append . "UNKNOWN - $output_unknown"; my $exit = $self->{manager}->{output}->get_most_critical(status => [ @exits ]);
$output_append = ". "; 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"
);
} }
if ($output_critical ne "") { if ($multiple == 0) {
$output .= $output_append . "CRITICAL - $output_critical"; $self->{manager}->{output}->output_add(short_msg => "'$entity_view->{name}' $long_msg");
$output_append = ". ";
}
if ($output_warning ne "") {
$output .= $output_append . "WARNING - $output_warning";
}
if ($status == 0) {
if ($self->{filter} == 1) {
$output .= $output_append . "All traffics are ok";
} else {
$output .= $output_append . $output_ok_unit;
} }
} }
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output|$perfdata\n");
} }
1; 1;

View File

@ -163,14 +163,14 @@ sub get_perf_metric_ids {
my $filtered_list = []; my $filtered_list = [];
foreach (@$perf_names) { foreach (@$perf_names) {
if (defined($obj_esxd->{perfcounter_cache}->{$_->{'label'}})) { if (defined($obj_esxd->{perfcounter_cache}->{$_->{label}})) {
foreach my $instance (@{$_->{'instances'}}) { foreach my $instance (@{$_->{instances}}) {
my $metric = PerfMetricId->new(counterId => $obj_esxd->{perfcounter_cache}->{$_->{'label'}}{'key'}, my $metric = PerfMetricId->new(counterId => $obj_esxd->{perfcounter_cache}->{$_->{label}}{key},
instance => $instance); instance => $instance);
push @$filtered_list, $metric; push @$filtered_list, $metric;
} }
} else { } else {
$obj_esxd->{logger}->writeLogError("Metric '" . $_->{'label'} . "' unavailable."); $obj_esxd->{logger}->writeLogError("Metric '" . $_->{label} . "' unavailable.");
$manager_display->{output}->output_add(severity => 'UNKNOWN', $manager_display->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Counter doesn't exist. VMware version can be too old."); short_msg => "Counter doesn't exist. VMware version can be too old.");
return undef; return undef;
@ -179,26 +179,61 @@ sub get_perf_metric_ids {
return $filtered_list; return $filtered_list;
} }
sub generic_performance_values_historic { sub performance_builder_specific {
my ($obj_esxd, $views, $perfs, $interval, %options) = @_; my (%options) = @_;
my $counter = 0;
my %results;
eval {
my $perf_metric_ids = get_perf_metric_ids($obj_esxd, $perfs);
return undef if (!defined($perf_metric_ids));
my @perf_query_spec; my @perf_query_spec;
foreach my $entry (@{$options{metrics}}) {
my $perf_metric_ids = get_perf_metric_ids($options{connector}, $entry->{metrics});
return undef if (!defined($perf_metric_ids));
my $tstamp = time(); my $tstamp = time();
my (@t) = gmtime($tstamp - $interval); my (@t) = gmtime($tstamp - $options{interval});
my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
(@t) = gmtime($tstamp);
my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
if ($options{interval} == 20) {
push @perf_query_spec, PerfQuerySpec->new(entity => $entry->{entity},
metricId => $perf_metric_ids,
format => 'normal',
intervalId => 20,
startTime => $startTime,
endTime => $endTime,
maxSample => 1);
} else {
push @perf_query_spec, PerfQuerySpec->new(entity => $entry->{entity},
metricId => $perf_metric_ids,
format => 'normal',
intervalId => $options{interval},
startTime => $startTime,
endTime => $endTime
);
#maxSample => 1);
}
}
return $options{connector}->{perfmanager_view}->QueryPerf(querySpec => \@perf_query_spec);
}
sub performance_builder_global {
my (%options) = @_;
my @perf_query_spec;
my $perf_metric_ids = get_perf_metric_ids($options{connector}, $options{metrics});
return undef if (!defined($perf_metric_ids));
my $tstamp = time();
my (@t) = gmtime($tstamp - $options{interval});
my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]); (1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
(@t) = gmtime($tstamp); (@t) = gmtime($tstamp);
my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]); (1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
foreach (@$views) { foreach (@{$options{views}}) {
if ($interval == 20) { if ($options{interval} == 20) {
push @perf_query_spec, PerfQuerySpec->new(entity => $_, push @perf_query_spec, PerfQuerySpec->new(entity => $_,
metricId => $perf_metric_ids, metricId => $perf_metric_ids,
format => 'normal', format => 'normal',
@ -210,14 +245,36 @@ sub generic_performance_values_historic {
push @perf_query_spec, PerfQuerySpec->new(entity => $_, push @perf_query_spec, PerfQuerySpec->new(entity => $_,
metricId => $perf_metric_ids, metricId => $perf_metric_ids,
format => 'normal', format => 'normal',
intervalId => $interval, intervalId => $options{interval},
startTime => $startTime, startTime => $startTime,
endTime => $endTime endTime => $endTime
); );
#maxSample => 1); #maxSample => 1);
} }
} }
my $perfdata = $obj_esxd->{perfmanager_view}->QueryPerf(querySpec => \@perf_query_spec);
return $options{connector}->{perfmanager_view}->QueryPerf(querySpec => \@perf_query_spec);
}
sub generic_performance_values_historic {
my ($obj_esxd, $views, $perfs, $interval, %options) = @_;
my $counter = 0;
my %results;
eval {
my $perfdata;
if (defined($views)) {
$perfdata = performance_builder_global(connector => $obj_esxd,
views => $views,
metrics => $perfs,
interval => $interval);
} else {
$perfdata = performance_builder_specific(connector => $obj_esxd,
metrics => $perfs,
interval => $interval);
}
return undef if (!defined($perfdata));
if (!$$perfdata[0] || !defined($$perfdata[0]->value)) { if (!$$perfdata[0] || !defined($$perfdata[0]->value)) {
$manager_display->{output}->output_add(severity => 'UNKNOWN', $manager_display->{output}->output_add(severity => 'UNKNOWN',