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) {
return 1; $options{manager}->{output}->output_add(severity => 'UNKNOWN',
} short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
if (defined($warn) && defined($crit) && $warn ne "" && $crit ne "" && $warn > $crit) { return 1;
$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;
}
}
}
}
foreach my $labels ((['poweredon', 'warning_on', 'critical_on'],
['poweredoff', 'warning_off', 'critical_off'],
['suspended', 'warning_suspended', 'critical_suspended'])) {
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $vm_states{$labels->[0]},
threshold => [ { label => $labels->[2], exit_litteral => 'critical' },
{ label => $labels->[1], exit_litteral => 'warning' } ]);
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' %s VM(s) %s", $entity_view->{name},
$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->{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});
} }
} }
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})) {
$output .= " - CRITICAL: $num_powerother VM not running.";
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
} elsif (defined($self->{warn2}) && $self->{warn2} ne "" && ($num_powerother >= $self->{warn2})) {
$output .= " - WARNING: $num_powerother VM not running.";
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
} else {
$output .= " - OK: $num_powerother VM not running.";
}
$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");
} }
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,192 +20,239 @@ 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) {
return 1; $options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
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 = [];
my %nic_in_vswitch = (); foreach my $entity_view (@$result) {
my %pnic_def_up = (); next if (centreon::esxd::common::host_state(connector => $self->{obj_esxd},
my %pnic_def_down = (); hostname => $entity_view->{name},
my $instances = []; state => $entity_view->{'runtime.connectionState'}->val,
my $filter_ok = 0; status => $self->{disconnect_status},
multiple => $multiple) == 0);
# Get Name from vswitch $pnic_def_up->{$entity_view->{mo_ref}->{value}} = {};
if (defined($$result[0]->{'config.network.vswitch'})) { $pnic_def_down->{$entity_view->{mo_ref}->{value}} = {};
foreach (@{$$result[0]->{'config.network.vswitch'}}) { my %nic_in_vswitch = ();
next if (!defined($_->{pnic})); my $instances = [];
foreach my $keynic (@{$_->{pnic}}) { my $filter_ok = 0;
$nic_in_vswitch{$keynic} = 1;
# Get Name from vswitch
if (defined($entity_view->{'config.network.vswitch'})) {
foreach (@{$entity_view->{'config.network.vswitch'}}) {
next if (!defined($_->{pnic}));
foreach my $keynic (@{$_->{pnic}}) {
$nic_in_vswitch{$keynic} = 1;
}
} }
} }
} # Get Name from proxySwitch
# Get Name from proxySwitch if (defined($entity_view->{'config.network.proxySwitch'})) {
if (defined($$result[0]->{'config.network.proxySwitch'})) { foreach (@{$entity_view->{'config.network.proxySwitch'}}) {
foreach (@{$$result[0]->{'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; }
} }
} }
}
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}));
# Check filter
if (defined($self->{nic_name}) && !defined($self->{filter_nic}) && $_->device ne $self->{nic_name}) {
next;
} elsif (defined($self->{nic_name}) && defined($self->{filter_nic}) && $_->device !~ /$self->{nic_name}/) {
next;
}
$filter_ok = 1;
if (defined($_->linkSpeed)) {
$pnic_def_up->{$entity_view->{mo_ref}->{value}}->{$_->device} = $_->linkSpeed->speedMb;
push @$instances, $_->device;
} else {
$pnic_def_down->{$entity_view->{mo_ref}->{value}}->{$_->device} = 1;
}
}
if ($filter_ok == 0) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("%s can't get physical nic with filter '%s'. (or physical nic not in a 'vswitch' or 'dvswitch'",
$entity_view->{name}, $self->{nic_name}));
next;
}
if (scalar(@${instances}) == 0 &&
($multiple == 0 || ($multiple == 1 && !$self->{manager}->{output}->is_status(value => $self->{link_down_status}, compare => 'ok', litteral => 1)))) {
$self->{manager}->{output}->output_add(severity => $self->{link_down_status},
short_msg => sprintf("%s Link(s) '%s' is(are) down",
$entity_view->{name}, join("','", keys %{$pnic_def_down->{$entity_view->{mo_ref}->{value}}})));
next; next;
} }
# Check filter
next if ($self->{filter} == 0 && $_->device !~ /^\Q$self->{pnic}\E$/);
next if ($self->{filter} == 1 && $_->device !~ /$self->{pnic}/);
$filter_ok = 1; push @$query_perfs, {
if (defined($_->linkSpeed)) { entity => $entity_view,
$pnic_def_up{$_->device} = $_->linkSpeed->speedMb; metrics => [
push @$instances, $_->device; {label => 'net.received.average', instances => $instances},
} else { {label => 'net.transmitted.average', instances => $instances}
$pnic_def_down{$_->device} = 1; ]
} };
} }
if ($filter_ok == 0) { # Nothing to retrieve. problem before already.
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN'); return if (scalar(@$query_perfs) == 0);
$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");
return ;
}
if ($#${instances} == -1) {
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN');
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Link(s) '" . join("','", keys %pnic_def_down) . "' is(are) down.\n");
return ;
}
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
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 $output_ok_unit = '';
my $perfdata = '';
my @nic_downs = keys %pnic_def_down; foreach my $entity_view (@$result) {
if ($#nic_downs >= 0) { my $entity_value = $entity_view->{mo_ref}->{value};
if ($self->{skip_errors} == 0 || $self->{filter} == 0) { if (scalar(keys %{$pnic_def_down->{$entity_value}}) > 0 &&
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN'); ($multiple == 0 || !$self->{manager}->{output}->is_status(value => $self->{link_down_status}, compare => 'ok', litteral => 1))) {
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ", $self->{manager}->{output}->output_add(severity => $self->{link_down_status},
"Link(s) '" . join("','", @nic_downs) . "' is(are) down"); short_msg => sprintf("%s Link(s) '%s' is(are) down",
} $entity_view->{name}, join("','", keys %{$pnic_def_down->{$entity_value}})));
}
foreach (keys %pnic_def_up) {
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 $traffic_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'net.transmitted.average'}->{'key'} . ":" . $_}[0]));
$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{$_}) . " %)";
if (($traffic_in / 1024 * 100 / $pnic_def_up{$_}) >= $self->{crit} || ($traffic_out / 1024 * 100 / $pnic_def_up{$_}) >= $self->{crit}) {
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ". ",
"'$_' 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{$_}) . " %)");
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
} elsif (($traffic_in / 1024 * 100 / $pnic_def_up{$_}) >= $self->{warn} || ($traffic_out / 1024 * 100 / $pnic_def_up{$_}) >= $self->{warn}) {
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ". ",
"'$_' 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{$_}) . " %)");
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
} }
my $warn_perfdata = ($pnic_def_up{$_} * $self->{warn} / 100) * 1024 * 1024; my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my $crit_perfdata = ($pnic_def_up{$_} * $self->{crit} / 100) * 1024 * 1024; my @exits;
foreach (sort keys %{$pnic_def_up->{$entity_value}}) {
if ($self->{filter} == 1) { # KBps
$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;"; 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;
} else { 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;
$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;"; 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 $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical_in', exit_litteral => 'critical' }, { label => 'warning_in', exit_litteral => 'warning' } ]);
my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical_out', exit_litteral => 'critical' }, { label => 'warning_out', exit_litteral => 'warning' } ]);
if ($output_unknown ne "") { my ($in_value, $in_unit) = $self->{manager}->{perfdata}->change_bytes(value => $traffic_in, network => 1);
$output .= $output_append . "UNKNOWN - $output_unknown"; my ($out_value, $out_unit) = $self->{manager}->{perfdata}->change_bytes(value => $traffic_out, network => 1);
$output_append = ". "; my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
} push @exits, $exit;
if ($output_critical ne "") {
$output .= $output_append . "CRITICAL - $output_critical"; my $output = sprintf("Interface '%s' Traffic In : %s/s (%.2f %%), Out : %s/s (%.2f %%) ", $_,
$output_append = ". "; $in_value . $in_unit, $in_prct,
} $out_value . $out_unit, $out_prct);
if ($output_warning ne "") { $long_msg .= $long_msg_append . $output;
$output .= $output_append . "WARNING - $output_warning"; $long_msg_append = ', ';
} if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || $multiple == 0) {
if ($status == 0) { $short_msg .= $short_msg_append . $output;
if ($self->{filter} == 1) { $short_msg_append = ', ';
$output .= $output_append . "All traffics are ok"; }
} else {
$output .= $output_append . $output_ok_unit; my $extra_label = '';
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
$self->{manager}->{output}->perfdata_add(label => 'traffic_in' . $extra_label, unit => 'b/s',
value => sprintf("%.2f", $traffic_in),
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed),
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed),
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);
}
$self->{manager}->{output}->output_add(long_msg => "$entity_view->{name}' $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"
);
}
if ($multiple == 0) {
$self->{manager}->{output}->output_add(short_msg => "'$entity_view->{name}' $long_msg");
} }
} }
$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,45 +179,102 @@ sub get_perf_metric_ids {
return $filtered_list; return $filtered_list;
} }
sub performance_builder_specific {
my (%options) = @_;
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 (@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",
(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]);
foreach (@{$options{views}}) {
if ($options{interval} == 20) {
push @perf_query_spec, PerfQuerySpec->new(entity => $_,
metricId => $perf_metric_ids,
format => 'normal',
intervalId => 20,
startTime => $startTime,
endTime => $endTime,
maxSample => 1);
} else {
push @perf_query_spec, PerfQuerySpec->new(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 generic_performance_values_historic { sub generic_performance_values_historic {
my ($obj_esxd, $views, $perfs, $interval, %options) = @_; my ($obj_esxd, $views, $perfs, $interval, %options) = @_;
my $counter = 0; my $counter = 0;
my %results; my %results;
eval { eval {
my $perf_metric_ids = get_perf_metric_ids($obj_esxd, $perfs); my $perfdata;
return undef if (!defined($perf_metric_ids));
my @perf_query_spec;
my $tstamp = time();
my (@t) = gmtime($tstamp - $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]);
foreach (@$views) { if (defined($views)) {
if ($interval == 20) { $perfdata = performance_builder_global(connector => $obj_esxd,
push @perf_query_spec, PerfQuerySpec->new(entity => $_, views => $views,
metricId => $perf_metric_ids, metrics => $perfs,
format => 'normal', interval => $interval);
intervalId => 20, } else {
startTime => $startTime, $perfdata = performance_builder_specific(connector => $obj_esxd,
endTime => $endTime, metrics => $perfs,
maxSample => 1); interval => $interval);
} else {
push @perf_query_spec, PerfQuerySpec->new(entity => $_,
metricId => $perf_metric_ids,
format => 'normal',
intervalId => $interval,
startTime => $startTime,
endTime => $endTime
);
#maxSample => 1);
}
} }
my $perfdata = $obj_esxd->{perfmanager_view}->QueryPerf(querySpec => \@perf_query_spec); 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',