Fix #5812
Fix #5810 git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@78 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
0dff025c48
commit
002b8c1af0
|
@ -29,6 +29,7 @@ my %OPTION = (
|
|||
on => undef,
|
||||
units => undef,
|
||||
free => undef,
|
||||
skip_errors => undef,
|
||||
filter => undef,
|
||||
);
|
||||
|
||||
|
@ -47,6 +48,7 @@ GetOptions(
|
|||
|
||||
"filter" => \$OPTION{filter},
|
||||
"free" => \$OPTION{free},
|
||||
"skip-errors" => \$OPTION{skip_errors},
|
||||
"units=s" => \$OPTION{units},
|
||||
"light-perfdata" => \$OPTION{'light-perfdata'},
|
||||
"datastore=s" => \$OPTION{datastore},
|
||||
|
@ -106,6 +108,7 @@ sub print_usage () {
|
|||
print " --units Threshold units: %, MB (default is MB)\n";
|
||||
print " --free Threshold is for free size\n";
|
||||
print " --filter Use regexp for --datastore option (can check multiples datastores at once)\n";
|
||||
print " --skip-errors Status OK if a datastore is not accessible (when you checks multiples)\n";
|
||||
print "\n";
|
||||
print "'datastore-io':\n";
|
||||
print " --datastore Datastore name to check (required)\n";
|
||||
|
@ -131,6 +134,7 @@ sub print_usage () {
|
|||
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 "'memhost':\n";
|
||||
print " -e (--esx-host) Esx Host to check (required)\n";
|
||||
|
@ -297,6 +301,11 @@ sub datastoreusage_check_arg {
|
|||
} else {
|
||||
$OPTION{free} = 0;
|
||||
}
|
||||
if (defined($OPTION{skip_errors})) {
|
||||
$OPTION{skip_errors} = 1;
|
||||
} else {
|
||||
$OPTION{skip_errors} = 0;
|
||||
}
|
||||
if (!defined($OPTION{warning})) {
|
||||
$OPTION{warning} = ($OPTION{free} == 1) ? 20 : 80;
|
||||
}
|
||||
|
@ -310,14 +319,14 @@ sub datastoreusage_check_arg {
|
|||
exit $ERRORS{UNKNOWN};
|
||||
}
|
||||
} else {
|
||||
$OPTION{units} = '';
|
||||
$OPTION{units} = '%';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub datastoreusage_get_str {
|
||||
return join($separatorin,
|
||||
('datastore-usage', $OPTION{vsphere}, $OPTION{datastore}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical}, $OPTION{free}, $OPTION{units}));
|
||||
('datastore-usage', $OPTION{vsphere}, $OPTION{datastore}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical}, $OPTION{free}, $OPTION{units}, $OPTION{skip_errors}));
|
||||
}
|
||||
|
||||
sub datastoreio_check_arg {
|
||||
|
@ -479,12 +488,17 @@ sub nethost_check_arg {
|
|||
} else {
|
||||
$OPTION{filter} = 0;
|
||||
}
|
||||
if (defined($OPTION{skip_errors})) {
|
||||
$OPTION{skip_errors} = 1;
|
||||
} else {
|
||||
$OPTION{skip_errors} = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub nethost_get_str {
|
||||
return join($separatorin,
|
||||
('nethost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{nic}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical}));
|
||||
('nethost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{nic}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical}, $OPTION{skip_errors}));
|
||||
}
|
||||
|
||||
sub countvmhost_check_arg {
|
||||
|
|
|
@ -120,6 +120,7 @@ sub run {
|
|||
}
|
||||
|
||||
# Vsphere >= 4.1
|
||||
# You get counters even if datastore is disconnect...
|
||||
my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd},
|
||||
$$result[0],
|
||||
[{'label' => 'datastore.totalReadLatency.average', 'instances' => $instances},
|
||||
|
|
|
@ -60,6 +60,7 @@ sub initArgs {
|
|||
$self->{warn} = (defined($_[2]) ? $_[2] : (($self->{free} == 1) ? 20 : 80));
|
||||
$self->{crit} = (defined($_[3]) ? $_[3] : (($self->{free} == 1) ? 10 : 90));
|
||||
$self->{units} = (defined($_[5])) ? $_[5] : '%';
|
||||
$self->{skip_errors} = (defined($_[6]) && $_[6] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
@ -85,6 +86,8 @@ sub run {
|
|||
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 ($warn_threshold, $crit_threshold);
|
||||
|
@ -97,9 +100,11 @@ sub run {
|
|||
|
||||
foreach my $ds (@$result) {
|
||||
if (!centreon::esxd::common::is_accessible($ds->summary->accessible)) {
|
||||
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||
"'" . $ds->summary->name . "' not accessible. Can be disconnected.");
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
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, ", ",
|
||||
"'" . $ds->summary->name . "' not accessible. Can be disconnected");
|
||||
next;
|
||||
}
|
||||
|
||||
|
@ -150,6 +155,10 @@ sub run {
|
|||
}
|
||||
}
|
||||
|
||||
if ($output_unknown ne "") {
|
||||
$output .= $output_append . "UNKNOWN - $output_unknown";
|
||||
$output_append = ". ";
|
||||
}
|
||||
if ($output_critical ne "") {
|
||||
$output .= $output_append . "CRITICAL - Datastore(s): $output_critical";
|
||||
$output_append = ". ";
|
||||
|
@ -159,9 +168,9 @@ sub run {
|
|||
}
|
||||
if ($status == 0) {
|
||||
if ($self->{filter} == 1) {
|
||||
$output = "All Datastore usages are ok";
|
||||
$output .= $output_append . "All Datastore usages are ok";
|
||||
} else {
|
||||
$output = $output_ok_unit;
|
||||
$output .= $output_append . $output_ok_unit;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ sub getCommandName {
|
|||
|
||||
sub checkArgs {
|
||||
my $self = shift;
|
||||
my ($host, $pnic, $warn, $crit) = @_;
|
||||
my ($host, $pnic, $filter, $warn, $crit) = @_;
|
||||
|
||||
if (!defined($host) || $host eq "") {
|
||||
$self->{logger}->writeLogError("ARGS error: need hostname");
|
||||
|
@ -55,6 +55,7 @@ sub initArgs {
|
|||
$self->{filter} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||
$self->{warn} = (defined($_[3]) ? $_[3] : 80);
|
||||
$self->{crit} = (defined($_[4]) ? $_[4] : 90);
|
||||
$self->{skip_errors} = (defined($_[5]) && $_[5] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
@ -67,7 +68,7 @@ sub run {
|
|||
}
|
||||
|
||||
my %filters = ('name' => $self->{lhost});
|
||||
my @properties = ('config.network.pnic', 'runtime.connectionState');
|
||||
my @properties = ('config.network.pnic', 'runtime.connectionState', 'config.network.vswitch');
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
|
@ -76,43 +77,124 @@ sub run {
|
|||
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{lhost},
|
||||
$$result[0]->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my %pnic_def = ();
|
||||
foreach (@{$$result[0]->{'config.network.pnic'}}) {
|
||||
if (defined($_->linkSpeed)) {
|
||||
$pnic_def{$_->device} = $_->linkSpeed->speedMb;
|
||||
my %nic_in_vswitch = ();
|
||||
my %pnic_def_up = ();
|
||||
my %pnic_def_down = ();
|
||||
my $instances = [];
|
||||
my $filter_ok = 0;
|
||||
|
||||
# Get Name from vswitch
|
||||
foreach (@{$$result[0]->{'config.network.vswitch'}}) {
|
||||
foreach my $keynic (@{$_->pnic}) {
|
||||
$nic_in_vswitch{$keynic} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($pnic_def{$self->{pnic}})) {
|
||||
foreach (@{$$result[0]->{'config.network.pnic'}}) {
|
||||
# Not in vswitch. Skip
|
||||
if (!defined($nic_in_vswitch{$_->key})) {
|
||||
next;
|
||||
}
|
||||
|
||||
# Check filter
|
||||
next if ($self->{filter} == 0 && $_->device !~ /^\Q$self->{pnic}\E$/);
|
||||
next if ($self->{filter} == 1 && $_->device !~ /$self->{pnic}/);
|
||||
|
||||
$filter_ok = 1;
|
||||
if (defined($_->linkSpeed)) {
|
||||
$pnic_def_up{$_->device} = $_->linkSpeed->speedMb;
|
||||
push @$instances, $_->device;
|
||||
} else {
|
||||
$pnic_def_down{$_->device} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($filter_ok == 0) {
|
||||
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN');
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Link '" . $self->{pnic} . "' not exist or down.\n");
|
||||
$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)\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},
|
||||
$$result[0],
|
||||
[{'label' => 'net.received.average', 'instances' => [$self->{pnic}]},
|
||||
{'label' => 'net.transmitted.average', 'instances' => [$self->{pnic}]}],
|
||||
[{'label' => 'net.received.average', 'instances' => $instances},
|
||||
{'label' => 'net.transmitted.average', 'instances' => $instances}],
|
||||
$self->{obj_esxd}->{perfcounter_speriod});
|
||||
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
|
||||
|
||||
my $traffic_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'net.received.average'}->{'key'} . ":" . $self->{pnic}}[0]));
|
||||
my $traffic_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'net.transmitted.average'}->{'key'} . ":" . $self->{pnic}}[0]));
|
||||
my $status = 0; # OK
|
||||
my $output = '';
|
||||
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 = '';
|
||||
|
||||
if (($traffic_in / 1024 * 8 * 100 / $pnic_def{$self->{pnic}}) >= $self->{warn} || ($traffic_out / 1024 * 8 * 100 / $pnic_def{$self->{pnic}}) >= $self->{warn}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
}
|
||||
if (($traffic_in / 1024 * 8 * 100 / $pnic_def{$self->{pnic}}) >= $self->{crit} || ($traffic_out / 1024 * 8 * 100 / $pnic_def{$self->{pnic}}) >= $self->{crit}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
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");
|
||||
}
|
||||
|
||||
$output = "Traffic In : " . centreon::esxd::common::simplify_number($traffic_in / 1024 * 8) . " Mb/s (" . centreon::esxd::common::simplify_number($traffic_in / 1024 * 8 * 100 / $pnic_def{$self->{pnic}}) . " %), Out : " . centreon::esxd::common::simplify_number($traffic_out / 1024 * 8) . " Mb/s (" . centreon::esxd::common::simplify_number($traffic_out / 1024 * 8 * 100 / $pnic_def{$self->{pnic}}) . " %)";
|
||||
$output .= "|traffic_in=" . ($traffic_in * 1024 * 8) . "b/s traffic_out=" . (($traffic_out * 1024 * 8)) . "b/s";
|
||||
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 $crit_perfdata = ($pnic_def_up{$_} * $self->{crit} / 100) * 1024 * 1024;
|
||||
|
||||
if ($self->{filter} == 1) {
|
||||
$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;";
|
||||
} else {
|
||||
$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;";
|
||||
}
|
||||
}
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||
if ($output_unknown ne "") {
|
||||
$output .= $output_append . "UNKNOWN - $output_unknown";
|
||||
$output_append = ". ";
|
||||
}
|
||||
if ($output_critical ne "") {
|
||||
$output .= $output_append . "CRITICAL - $output_critical";
|
||||
$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;
|
||||
|
|
|
@ -164,10 +164,14 @@ sub get_perf_metric_ids {
|
|||
}
|
||||
|
||||
sub generic_performance_values_historic {
|
||||
my ($obj_esxd, $view, $perfs, $interval) = @_;
|
||||
my ($obj_esxd, $view, $perfs, $interval, $skip_undef_counter) = @_;
|
||||
my $counter = 0;
|
||||
my %results;
|
||||
|
||||
|
||||
if (!defined($skip_undef_counter)) {
|
||||
|
||||
}
|
||||
|
||||
eval {
|
||||
my $perf_metric_ids = get_perf_metric_ids($obj_esxd, $perfs);
|
||||
return undef if (!defined($perf_metric_ids));
|
||||
|
@ -205,11 +209,14 @@ sub generic_performance_values_historic {
|
|||
return undef;
|
||||
}
|
||||
foreach (@{$$perfdata[0]->value}) {
|
||||
$results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $_->value;
|
||||
if (!defined($_->value)) {
|
||||
if (defined($skip_undef_counter) && $skip_undef_counter == 1 && !defined($_->value)) {
|
||||
results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = undef;
|
||||
next;
|
||||
} elsif (!defined($_->value)) {
|
||||
$obj_esxd->print_response("-3|Error: Cannot get value for counters. Maybe there is time sync problem (check the esxd server and the target also).\n");
|
||||
return undef;
|
||||
}
|
||||
$results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $_->value;
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
|
@ -358,7 +365,7 @@ sub stats_info {
|
|||
$$args[1] = '' if (!defined($$args[1]));
|
||||
|
||||
my $num_connection = scalar(keys(%{$obj_esxd->{sockets}}));
|
||||
$output = "'$num_connection' total client connections | connection=$num_connection;$$args[0];$$args[1] requests=" . $obj_esxd->{counter};
|
||||
$output = "'$num_connection' total client connections | connection=$num_connection;$$args[0];$$args[1];0; requests=" . $obj_esxd->{counter};
|
||||
if ($$args[1] ne '' and $num_connection >= $$args[1]) {
|
||||
$status = errors_mask($status, 'CRITICAL');
|
||||
} elsif ($$args[0] ne '' and $num_connection >= $$args[0]) {
|
||||
|
|
Loading…
Reference in New Issue