WIP: need commands (memhost, swaphost, uptimehost)
This commit is contained in:
Quentin Garnier 2014-10-22 16:07:03 +02:00
parent bfb15e4d93
commit ab4985ed69
4 changed files with 281 additions and 138 deletions

View File

@ -113,7 +113,6 @@ sub print_usage () {
print " --vsphere vsphere name (default: none)\n"; print " --vsphere vsphere name (default: none)\n";
print " -u (--usage) What to check. The list and args (required)\n"; print " -u (--usage) What to check. The list and args (required)\n";
print "\n"; print "\n";
print "'datastore-usage':\n"; print "'datastore-usage':\n";
print " --datastore Datastore name to check (required)\n"; print " --datastore Datastore name to check (required)\n";
print " -w (--warning) Warning Threshold (default 80)\n"; print " -w (--warning) Warning Threshold (default 80)\n";
@ -145,12 +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 "'cpuhost':\n";
print " -e (--esx-host) Esx Host 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 " --light-perfdata Display only total average cpu perfdata\n";
print "\n";
print "'nethost':\n"; print "'nethost':\n";
print " -e (--esx-host) Esx Host to check (required)\n"; print " -e (--esx-host) Esx Host to check (required)\n";
print " --nic Physical nic name to check (required)\n"; print " --nic Physical nic name to check (required)\n";
@ -159,16 +152,6 @@ sub print_usage () {
print " --filter Use regexp for --nic option (can check multiple nics at once)\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 " --skip-errors Status OK if some nic are down (when you checks multiples)\n";
print "\n"; print "\n";
print "'memhost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
print " -w (--warning) Warning Threshold in percent (default 80)\n";
print " -c (--critical) Critical Threshold in percent (default 90)\n";
print "\n";
print "'swaphost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
print " -w (--warning) Warning Threshold in MB/s (default 0.8)\n";
print " -c (--critical) Critical Threshold in MB/s (default 1)\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";
@ -183,9 +166,6 @@ sub print_usage () {
print " --warning2 Warning Threshold if more VMs not 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 " --critical2 Critical Threshold if more VMs not on (default none)\n";
print "\n"; print "\n";
print "'uptimehost':\n";
print " -e (--esx-host) Esx Host to check (required)\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";
@ -239,10 +219,6 @@ sub print_usage () {
print " --warn Warn\n"; print " --warn Warn\n";
print " --skip-errors Status OK if vms are disconnected (when you checks multiples)\n"; print " --skip-errors Status OK if vms are disconnected (when you checks multiples)\n";
print "\n"; print "\n";
print "'stats':\n";
print " -w (--warning) Warning Threshold in total client connections (default none)\n";
print " -c (--critical) Critical Threshold in total client connections (default none)\n";
} }
sub print_help () { sub print_help () {

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} = 'memhost'; $self->{commandName} = 'memhost';
bless $self, $class; bless $self, $class;
@ -22,79 +21,134 @@ sub getCommandName {
} }
sub checkArgs { sub checkArgs {
my $self = shift; my ($self, %options) = @_;
my ($host, $warn, $crit) = @_;
if (!defined($host) || $host eq "") { if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
$self->{logger}->writeLogError("ARGS error: need hostname"); $options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: esx hostname 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 (($options{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning})) == 0) {
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number"); $options{manager}->{output}->output_add(severity => 'UNKNOWN',
return 1; short_msg => "Argument error: wrong value for warning value '" . $options{arguments}->{warning} . "'.");
return 1;
} }
if (defined($warn) && defined($crit) && $warn > $crit) { if (($options{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical})) == 0) {
$self->{logger}->writeLogError("ARGS error: warn threshold must be lower than crit threshold"); $options{manager}->{output}->output_add(severity => 'UNKNOWN',
return 1; short_msg => "Argument error: wrong value for critical value '" . $options{arguments}->{critical} . "'.");
return 1;
} }
return 0; return 0;
} }
sub initArgs { sub initArgs {
my $self = shift; my ($self, %options) = @_;
$self->{lhost} = $_[0];
$self->{warn} = (defined($_[1]) ? $_[1] : 80); foreach (keys %{$options{arguments}}) {
$self->{crit} = (defined($_[2]) ? $_[2] : 90); $self->{$_} = $options{arguments}->{$_};
}
$self->{manager} = centreon::esxd::common::init_response();
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
$self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning});
$self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical});
}
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 = ('summary.hardware.memorySize', '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', 'summary.hardware.memorySize', '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 ;
}
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{lhost}, if (scalar(@$result) > 1) {
$$result[0]->{'runtime.connectionState'}->val) == 0); $multiple = 1;
}
my $memory_size = $$result[0]->{'summary.hardware.memorySize'};
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, $result,
[{'label' => 'mem.consumed.average', 'instances' => ['']}, [{'label' => 'mem.consumed.average', 'instances' => ['']},
{'label' => 'mem.overhead.average', 'instances' => ['']}], {'label' => 'mem.overhead.average', '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 $mem_used = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"}[0]));
my $mem_overhead = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"}[0]));
my $status = 0; # OK
my $output = '';
if ($mem_used * 100 / ($memory_size / 1024) >= $self->{warn}) { if ($multiple == 1) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING'); $self->{manager}->{output}->output_add(severity => 'OK',
short_msg => sprintf("All memory usages are ok"));
} }
if ($mem_used * 100 / ($memory_size / 1024) >= $self->{crit}) { foreach my $entity_view (@$result) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL'); 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);
my $entity_value = $entity_view->{mo_ref}->{value};
my $memory_size = $entity_view->{'summary.hardware.memorySize'}; # in B
# in KB
my $mem_used = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"}[0])) * 1024;
my $mem_overhead = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"}[0])) * 1024;
my $mem_free = $memory_size - $mem_used;
my $prct_used = $mem_used * 100 / $memory_size;
my $prct_free = 100 - $prct_used;
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my ($total_value, $total_unit) = $self->{manager}->{perfdata}->change_bytes(value => $memory_size);
my ($used_value, $used_unit) = $self->{manager}->{perfdata}->change_bytes(value => $mem_used);
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},
$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},
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $prct_used,
$free_value . " " . $free_unit, $prct_free));
}
my $extra_label = '';
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
$self->{manager}->{output}->perfdata_add(label => 'used' . $extra_label, unit => 'B',
value => $mem_used,
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning', total => $memory_size, cast_int => 1),
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical', total => $memory_size, cast_int => 1),
min => 0, max => $memory_size);
$self->{manager}->{output}->perfdata_add(label => 'overhead' . $extra_label, unit => 'B',
value => $mem_overhead,
min => 0);
} }
$output = "Memory used : " . centreon::esxd::common::simplify_number($mem_used / 1024 / 1024) . " Go - size : " . centreon::esxd::common::simplify_number($memory_size / 1024 / 1024 / 1024) . " Go - percent : " . centreon::esxd::common::simplify_number($mem_used * 100 / ($memory_size / 1024)) . " %";
$output .= "|used=" . ($mem_used * 1024) . "o;" . centreon::esxd::common::simplify_number($memory_size * $self->{warn} / 100, 0) . ";" . centreon::esxd::common::simplify_number($memory_size * $self->{crit} / 100, 0) . ";0;" . ($memory_size) . " size=" . $memory_size . "o" . " overhead=" . ($mem_overhead * 1024) . "o";
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\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} = 'swaphost'; $self->{commandName} = 'swaphost';
bless $self, $class; bless $self, $class;
@ -22,77 +21,130 @@ sub getCommandName {
} }
sub checkArgs { sub checkArgs {
my $self = shift; my ($self, %options) = @_;
my ($host, $warn, $crit) = @_;
if (!defined($host) || $host eq "") { if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
$self->{logger}->writeLogError("ARGS error: need hostname"); $options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: esx hostname 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 (($options{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning})) == 0) {
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number"); $options{manager}->{output}->output_add(severity => 'UNKNOWN',
return 1; short_msg => "Argument error: wrong value for warning value '" . $options{arguments}->{warning} . "'.");
return 1;
} }
if (defined($warn) && defined($crit) && $warn > $crit) { if (($options{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical})) == 0) {
$self->{logger}->writeLogError("ARGS error: warn threshold must be lower than crit threshold"); $options{manager}->{output}->output_add(severity => 'UNKNOWN',
return 1; short_msg => "Argument error: wrong value for critical value '" . $options{arguments}->{critical} . "'.");
return 1;
} }
return 0; return 0;
} }
sub initArgs { sub initArgs {
my $self = shift; my ($self, %options) = @_;
$self->{lhost} = $_[0];
$self->{warn} = (defined($_[1]) ? $_[1] : 0.8); foreach (keys %{$options{arguments}}) {
$self->{crit} = (defined($_[2]) ? $_[2] : 1); $self->{$_} = $options{arguments}->{$_};
}
$self->{manager} = centreon::esxd::common::init_response();
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
$self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning});
$self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical});
}
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 $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', 'runtime.connectionState'); my @properties = ('name', '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 ;
}
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{lhost}, if (scalar(@$result) > 1) {
$$result[0]->{'runtime.connectionState'}->val) == 0); $multiple = 1;
}
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, $result,
[{'label' => 'mem.swapinRate.average', 'instances' => ['']}, [{'label' => 'mem.swapinRate.average', 'instances' => ['']},
{'label' => 'mem.swapoutRate.average', 'instances' => ['']}], {'label' => 'mem.swapoutRate.average', 'instances' => ['']}],
$self->{obj_esxd}->{perfcounter_speriod}); $self->{obj_esxd}->{perfcounter_speriod});
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 $swap_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"}[0])); if ($multiple == 1) {
my $swap_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"}[0])); $self->{manager}->{output}->output_add(severity => 'OK',
my $status = 0; # OK short_msg => sprintf("All swap rate usages are ok"));
my $output = '';
if (($swap_in / 1024) >= $self->{warn} || ($swap_out / 1024) >= $self->{warn}) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
} }
if (($swap_in / 1024) >= $self->{crit} || ($swap_out / 1024) >= $self->{crit}) { foreach my $entity_view (@$result) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL'); 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);
my $entity_value = $entity_view->{mo_ref}->{value};
# KBps
my $swap_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"}[0])) * 1024;
my $swap_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"}[0])) * 1024;
my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $swap_in, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $swap_out, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
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},
$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},
$swap_in_value . " " . $swap_in_unit . "/s",
$swap_out_value . " " . $swap_out_unit . "/s"));
}
my $extra_label = '';
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
$self->{manager}->{output}->perfdata_add(label => 'swap_in' . $extra_label, unit => 'B/s',
value => $swap_in,
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{manager}->{output}->perfdata_add(label => 'swap_out' . $extra_label, unit => 'B/s',
value => $swap_out,
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
} }
$output = "Swap In : " . centreon::esxd::common::simplify_number($swap_in / 1024 * 8) . " Mb/s , Swap Out : " . centreon::esxd::common::simplify_number($swap_out / 1024 * 8) . " Mb/s ";
$output .= "|swap_in=" . ($swap_in * 1024 * 8) . "b/s swap_out=" . (($swap_out * 1024 * 8)) . "b/s";
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\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} = 'uptimehost'; $self->{commandName} = 'uptimehost';
bless $self, $class; bless $self, $class;
@ -22,55 +21,117 @@ sub getCommandName {
} }
sub checkArgs { sub checkArgs {
my $self = shift; my ($self, %options) = @_;
my ($lhost) = @_;
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($options{arguments}->{disconnect_status}) &&
$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;
}
if (($options{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning})) == 0) {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: wrong value for warning value '" . $options{arguments}->{warning} . "'.");
return 1;
}
if (($options{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical})) == 0) {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: wrong value for critical value '" . $options{arguments}->{critical} . "'.");
return 1;
}
return 0; return 0;
} }
sub initArgs { sub initArgs {
my $self = shift; my ($self, %options) = @_;
$self->{lhost} = $_[0];
foreach (keys %{$options{arguments}}) {
$self->{$_} = $options{arguments}->{$_};
}
$self->{manager} = centreon::esxd::common::init_response();
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
$self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning});
$self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical});
}
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}->{module_date_parse_loaded} == 0) { if ($self->{obj_esxd}->{module_date_parse_loaded} == 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) . "|Need to install Date::Parse Perl Module.\n"); short_msg => "Need to install Date::Parse Perl Module.");
return ; return ;
} }
my %filters = ('name' => $self->{lhost}); my %filters = ();
my @properties = ('runtime.bootTime', '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', 'runtime.bootTime', '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;
}
if ($multiple == 1) {
$self->{manager}->{output}->output_add(severity => 'OK',
short_msg => sprintf("All uptimes are ok"));
} }
return if (centreon::esxd::common::host_state($self->{obj_esxd}, $self->{lhost}, foreach my $entity_view (@$result) {
$$result[0]->{'runtime.connectionState'}->val) == 0); 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);
my $create_time = Date::Parse::str2time($$result[0]->{'runtime.bootTime'}); my $create_time = Date::Parse::str2time($entity_view->{'runtime.bootTime'});
if (!defined($create_time)) { if (!defined($create_time)) {
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 Parse date '" . $$result[0]->{'runtime.bootTime'} . "'.\n"); short_msg => "Can't Parse date '" . $entity_view->{'runtime.bootTime'} . "'");
return ; return ;
}
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' } ]);
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Uptime: %s day(s)",
$entity_view->{name},
$days));
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' Uptime: %s day(s)",
$entity_view->{name},
$days));
}
my $extra_label = '';
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
$self->{manager}->{output}->perfdata_add(label => 'uptime' . $extra_label, unit => 's',
value => $diff_time,
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
} }
my $diff_time = time() - $create_time;
my $days = int($diff_time / 60 / 60 / 24);
my $output = '';
my $status = 0; # OK
$output = "Uptime (in day): $days|uptime=" . $days . "day(s)\n";
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
} }
1; 1;