parent
eaee5ccbd3
commit
a03d67da00
|
@ -151,51 +151,11 @@ sub print_usage () {
|
|||
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 "\n";
|
||||
print "'cpuvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " -w (--warning) Warning Threshold in percent for cpu average (default 80)\n";
|
||||
print " -c (--critical) Critical Threshold in percent for cpu average (default 90)\n";
|
||||
print " --warning2 Warning Threshold in percent for cpu ready (default 5)\n";
|
||||
print " --critical2 Critical Threshold in percent for cpu ready (default 10)\n";
|
||||
print "\n";
|
||||
print "'toolsvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
|
||||
print " --skip-errors Status OK if vms are disconnected (when you checks multiples)\n";
|
||||
print " --skip-not-running Skip vmtools for vms not running (also template)\n";
|
||||
print "\n";
|
||||
print "'snapshotvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
|
||||
print " --warning Warning threshold in seconds (default: 3 days)\n";
|
||||
print " --critical Critical threshold in seconds (default: 5 days)\n";
|
||||
print " --check-consolidation Check if VM needs consolidation (since vsphere 5.0)\n";
|
||||
print " --skip-errors Status OK if vms are disconnected (when you checks multiples)\n";
|
||||
print " --skip-not-running Skip snapshots for vms not running\n";
|
||||
print "\n";
|
||||
print "'limitvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
|
||||
print " --warn Warning threshold if set (default)\n";
|
||||
print " --crit Critical threshold if set\n";
|
||||
print " --check-disk Check Disk limits (since vsphere 5.0)\n";
|
||||
print " --skip-errors Status OK if vms are disconencted (when you checks multiples)\n";
|
||||
print "\n";
|
||||
print "'datastoresvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " -w (--warning) Warning Threshold in IOPS (default none)\n";
|
||||
print " -c (--critical) Critical Threshold in IOPS (default none)\n";
|
||||
print "\n";
|
||||
print "'memvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " -w (--warning) Warning Threshold in percent\n";
|
||||
print " -c (--critical) Critical Threshold in percent\n";
|
||||
print "\n";
|
||||
print "'swapvm':\n";
|
||||
print " --vm VM 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 "'thinprovisioningvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
|
||||
|
|
|
@ -20,7 +20,6 @@ sub getCommandName {
|
|||
return $self->{commandName};
|
||||
}
|
||||
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ sub new {
|
|||
my $class = shift;
|
||||
my $self = {};
|
||||
$self->{logger} = shift;
|
||||
$self->{obj_esxd} = shift;
|
||||
$self->{commandName} = 'cpuvm';
|
||||
|
||||
bless $self, $class;
|
||||
|
@ -22,113 +21,161 @@ sub getCommandName {
|
|||
}
|
||||
|
||||
sub checkArgs {
|
||||
my $self = shift;
|
||||
my ($vm, $warn, $crit, $warn2, $crit2) = @_;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($vm) || $vm eq "") {
|
||||
$self->{logger}->writeLogError("ARGS error: need vm hostname");
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($warn) && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: warn threshold must be a positive number");
|
||||
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 (defined($crit) && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number");
|
||||
if (defined($options{arguments}->{nopoweredon_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{nopoweredon_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for nopoweredon status '" . $options{arguments}->{nopoweredon_status} . "'");
|
||||
return 1;
|
||||
}
|
||||
if (defined($warn) && defined($crit) && $warn > $crit) {
|
||||
$self->{logger}->writeLogError("ARGS error: warn threshold must be lower than crit threshold");
|
||||
foreach my $label (('warning_usagemhz', 'critical_usagemhz', 'warning_usage', 'critical_usage', 'warning_ready', 'critical_ready')) {
|
||||
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;
|
||||
}
|
||||
if (defined($warn2) && $warn2 !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: warn2 threshold must be a positive number");
|
||||
return 1;
|
||||
}
|
||||
if (defined($crit2) && $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 > $crit2) {
|
||||
$self->{logger}->writeLogError("ARGS error: warn2 threshold must be lower than crit2 threshold");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my $self = shift;
|
||||
$self->{lvm} = $_[0];
|
||||
$self->{warn} = (defined($_[1]) ? $_[1] : 80);
|
||||
$self->{crit} = (defined($_[2]) ? $_[2] : 90);
|
||||
$self->{warn2} = (defined($_[3]) ? $_[3] : 5);
|
||||
$self->{crit2} = (defined($_[4]) ? $_[4] : 10);
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::esxd::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning_usagemhz', 'critical_usagemhz', 'warning_usage', 'critical_usage', 'warning_ready', 'critical_ready')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
}
|
||||
|
||||
sub set_connector {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{obj_esxd} = $options{connector};
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{obj_esxd}->{perfcounter_speriod} > 0)) {
|
||||
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN');
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Can't retrieve perf counters.\n");
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my %filters = ('name' => $self->{lvm});
|
||||
my %filters = ();
|
||||
my $multiple = 0;
|
||||
if (defined($self->{vm_hostname}) && !defined($self->{filter})) {
|
||||
$filters{name} = qr/^\Q$self->{vm_hostname}\E$/;
|
||||
} elsif (!defined($self->{vm_hostname})) {
|
||||
$filters{name} = qr/.*/;
|
||||
} else {
|
||||
$filters{name} = qr/$self->{vm_hostname}/;
|
||||
}
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState');
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm},
|
||||
$$result[0]->{'runtime.connectionState'}->val,
|
||||
$$result[0]->{'runtime.powerState'}->val) == 0);
|
||||
return if (!defined($result));
|
||||
|
||||
my @instances = ('*');
|
||||
|
||||
my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd},
|
||||
$result,
|
||||
[{'label' => 'cpu.usage.average', 'instances' => \@instances},
|
||||
{'label' => 'cpu.usagemhz.average', 'instances' => \@instances},
|
||||
{'label' => 'cpu.ready.summation', '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);
|
||||
|
||||
my $status = 0; # OK
|
||||
my $output = '';
|
||||
my $total_cpu_average = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"}[0] * 0.01));
|
||||
my $total_cpu_mhz_average = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}[0]));
|
||||
my $total_cpu_ready = centreon::esxd::common::simplify_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.ready.summation'}->{'key'} . ":"}[0] / ($self->{obj_esxd}->{perfcounter_speriod} * 1000) * 100);
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All cpu usages are ok"));
|
||||
}
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::esxd::common::vm_state(connector => $self->{obj_esxd},
|
||||
hostname => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power => $entity_view->{'runtime.powerState'}->val,
|
||||
status => $self->{disconnect_status},
|
||||
powerstatus => $self->{nopoweredon_status},
|
||||
multiple => $multiple) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
my $total_cpu_average = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"}[0] * 0.01));
|
||||
my $total_cpu_mhz_average = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}[0]));
|
||||
my $total_cpu_ready = centreon::esxd::common::simplify_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.ready.summation'}->{'key'} . ":"}[0] / ($self->{obj_esxd}->{perfcounter_speriod} * 1000) * 100);
|
||||
|
||||
if ($total_cpu_average >= $self->{warn}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
}
|
||||
if ($total_cpu_average >= $self->{crit}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
}
|
||||
if ($total_cpu_ready >= $self->{warn2}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
}
|
||||
if ($total_cpu_ready >= $self->{crit2}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my @exits;
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
|
||||
foreach my $entry (({ value => $total_cpu_average, label => 'usage', output => 'Total Average CPU usage %s %%',
|
||||
perf_label => 'cpu_total', perf_min => 0, perf_max => 100, perf_unit => '%' },
|
||||
{ value => $total_cpu_mhz_average, label => 'usagemhz', output => 'Total Average CPU %s Mhz',
|
||||
perf_label => 'cpu_total_MHz', perf_min => 0, perf_unit => 'MHz'},
|
||||
{ value => $total_cpu_ready, label => 'ready', output => 'CPU ready %s %%',
|
||||
perf_label => 'cpu_ready', perf_min => 0, perf_unit => '%' })) {
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $entry->{value}, threshold => [ { label => 'critical_' . $entry->{label}, exit_litteral => 'critical' }, { label => 'warning_' . $entry->{label}, exit_litteral => 'warning' } ]);
|
||||
push @exits, $exit;
|
||||
|
||||
my $output = sprintf($entry->{output}, $entry->{value});
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || $multiple == 0) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->perfdata_add(label => $entry->{perf_label} . $extra_label, unit => $entry->{perf_unit},
|
||||
value => $entry->{value},
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning_' . $entry->{label}),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical_in' . $entry->{label}),
|
||||
min => $entry->{perf_min}, max => $entry->{perf_max});
|
||||
}
|
||||
|
||||
$output = "CPU ready '$total_cpu_ready%', Total Average CPU usage '$total_cpu_average%', Total Average CPU '" . $total_cpu_mhz_average . "MHz' on last " . int($self->{obj_esxd}->{perfcounter_speriod} / 60) . "min | cpu_ready=$total_cpu_ready%;$self->{warn2};$self->{crit2};0; cpu_total=$total_cpu_average%;$self->{warn};$self->{crit};0;100 cpu_total_MHz=" . $total_cpu_mhz_average . "MHz";
|
||||
$long_msg .= ' on last ' . int($self->{obj_esxd}->{perfcounter_speriod} / 60) . ' min';
|
||||
|
||||
$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");
|
||||
}
|
||||
|
||||
foreach my $id (sort { my ($cida, $cia) = split /:/, $a;
|
||||
my ($cidb, $cib) = split /:/, $b;
|
||||
$cia = -1 if (!defined($cia) || $cia eq "");
|
||||
$cib = -1 if (!defined($cib) || $cib eq "");
|
||||
$cia <=> $cib} keys %$values) {
|
||||
$cia <=> $cib} keys %{$values->{$entity_value}}) {
|
||||
my ($counter_id, $instance) = split /:/, $id;
|
||||
next if ($self->{obj_esxd}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} != $counter_id);
|
||||
if ($instance ne "") {
|
||||
$output .= " cpu" . $instance . "_MHz=" . centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$id}[0])) . "MHz";
|
||||
$self->{manager}->{output}->perfdata_add(label => 'cpu_' . $instance . '_MHz' . $extra_label, unit => 'MHz',
|
||||
value => centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$id}[0])),
|
||||
min => 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -9,7 +9,6 @@ sub new {
|
|||
my $class = shift;
|
||||
my $self = {};
|
||||
$self->{logger} = shift;
|
||||
$self->{obj_esxd} = shift;
|
||||
$self->{commandName} = 'limitvm';
|
||||
|
||||
bless $self, $class;
|
||||
|
@ -22,26 +21,62 @@ sub getCommandName {
|
|||
}
|
||||
|
||||
sub checkArgs {
|
||||
my $self = shift;
|
||||
my ($vm) = @_;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($vm) || $vm eq "") {
|
||||
$self->{logger}->writeLogError("ARGS error: need vm hostname");
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: vm hostname cannot be null");
|
||||
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 (defined($options{arguments}->{cpu_limitset_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{cpu_limitset_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for cpu limitset status '" . $options{arguments}->{cpu_limitset_status} . "'");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{memory_limitset_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{memory_limitset_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for memory limitset status '" . $options{arguments}->{memory_limitset_status} . "'");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{disk_limitset_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{disk_limitset_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for disk limitset status '" . $options{arguments}->{disk_limitset_status} . "'");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my $self = shift;
|
||||
$self->{lvm} = $_[0];
|
||||
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||
$self->{warn} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||
$self->{crit} = (defined($_[3]) && $_[3] == 1) ? 1 : 0;
|
||||
$self->{disk} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
||||
$self->{skip_errors} = (defined($_[5]) && $_[5] == 1) ? 1 : 0;
|
||||
if ($self->{warn} == 0 && $self->{crit} == 0) {
|
||||
$self->{warn} = 1;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::esxd::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
}
|
||||
|
||||
sub set_connector {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{obj_esxd} = $options{connector};
|
||||
}
|
||||
|
||||
sub display_verbose {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => $options{label});
|
||||
foreach my $vm (sort keys %{$options{vms}}) {
|
||||
$self->{manager}->{output}->output_add(long_msg => ' ' . $vm);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,106 +84,89 @@ sub run {
|
|||
my $self = shift;
|
||||
|
||||
my %filters = ();
|
||||
|
||||
if ($self->{filter} == 0) {
|
||||
$filters{name} = qr/^\Q$self->{lvm}\E$/;
|
||||
my $multiple = 0;
|
||||
if (defined($self->{vm_hostname}) && !defined($self->{filter})) {
|
||||
$filters{name} = qr/^\Q$self->{vm_hostname}\E$/;
|
||||
} elsif (!defined($self->{vm_hostname})) {
|
||||
$filters{name} = qr/.*/;
|
||||
} else {
|
||||
$filters{name} = qr/$self->{lvm}/;
|
||||
$filters{name} = qr/$self->{vm_hostname}/;
|
||||
}
|
||||
my @properties;
|
||||
push @properties, 'name', 'runtime.connectionState', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit';
|
||||
if ($self->{disk} == 1) {
|
||||
push @properties, 'name', 'runtime.connectionState', 'runtime.powerState', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit';
|
||||
if (defined($self->{check_disk_limit})) {
|
||||
push @properties, 'config.hardware.device';
|
||||
}
|
||||
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All Limits are ok"));
|
||||
} else {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("Limits are ok"));
|
||||
}
|
||||
|
||||
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 %cpu_limit = ();
|
||||
my %memory_limit = ();
|
||||
my %disk_limit = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::esxd::common::vm_state(connector => $self->{obj_esxd},
|
||||
hostname => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
status => $self->{disconnect_status},
|
||||
nocheck_ps => 1,
|
||||
multiple => $multiple) == 0);
|
||||
|
||||
foreach my $virtual (@$result) {
|
||||
if (!centreon::esxd::common::is_connected($virtual->{'runtime.connectionState'}->val)) {
|
||||
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, ", ",
|
||||
"'" . $virtual->{name} . "' not connected");
|
||||
}
|
||||
next;
|
||||
}
|
||||
|
||||
my $limit_set_warn = '';
|
||||
my $limit_set_crit = '';
|
||||
next if (defined($self->{nopoweredon_skip}) &&
|
||||
!centreon::esxd::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
# CPU Limit
|
||||
if ($self->{crit} == 1 && defined($virtual->{'config.cpuAllocation.limit'}) && $virtual->{'config.cpuAllocation.limit'} != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$limit_set_crit = "/CPU"
|
||||
} elsif ($self->{warn} == 1 && defined($virtual->{'config.cpuAllocation.limit'}) && $virtual->{'config.cpuAllocation.limit'} != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$limit_set_warn = "/CPU"
|
||||
if (defined($entity_view->{'config.cpuAllocation.limit'}) && $entity_view->{'config.cpuAllocation.limit'} != -1) {
|
||||
$cpu_limit{$entity_view->{name}} = 1;
|
||||
}
|
||||
|
||||
# Memory Limit
|
||||
if ($self->{crit} == 1 && defined($virtual->{'config.memoryAllocation.limit'}) && $virtual->{'config.memoryAllocation.limit'} != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$limit_set_crit .= "/MEM"
|
||||
} elsif ($self->{warn} == 1 && defined($virtual->{'config.memoryAllocation.limit'}) && $virtual->{'config.memoryAllocation.limit'} != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$limit_set_warn .= "/MEM"
|
||||
if (defined($entity_view->{'config.memoryAllocation.limit'}) && $entity_view->{'config.memoryAllocation.limit'} != -1) {
|
||||
$memory_limit{$entity_view->{name}} = 1;
|
||||
}
|
||||
|
||||
# Disk
|
||||
if ($self->{disk} == 1) {
|
||||
foreach my $device (@{$virtual->{'config.hardware.device'}}) {
|
||||
if (defined($self->{check_disk_limit})) {
|
||||
foreach my $device (@{$entity_view->{'config.hardware.device'}}) {
|
||||
if ($device->isa('VirtualDisk')) {
|
||||
if ($self->{crit} == 1 && defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$limit_set_crit .= "/DISK"
|
||||
} elsif ($self->{warn} == 1 && defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$limit_set_warn .= "/DISK"
|
||||
if (defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
|
||||
$disk_limit{$entity_view->{name}} = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Set
|
||||
if ($limit_set_crit ne '') {
|
||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||
"[" . $virtual->{name}. "]$limit_set_crit");
|
||||
} elsif ($limit_set_warn ne '') {
|
||||
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||
"[" . $virtual->{name}. "]$limit_set_warn");
|
||||
if (scalar(keys %cpu_limit) > 0 &&
|
||||
!$self->{manager}->{output}->is_status(value => $self->{cpu_limitset_status}, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $self->{cpu_limitset_status},
|
||||
short_msg => sprintf('%d VM with CPU limits', scalar(keys %cpu_limit)));
|
||||
$self->display_verbose(label => 'CPU limits:', vms => \%cpu_limit);
|
||||
}
|
||||
|
||||
if (scalar(keys %memory_limit) > 0 &&
|
||||
!$self->{manager}->{output}->is_status(value => $self->{memory_limitset_status}, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $self->{memory_limitset_status},
|
||||
short_msg => sprintf('%d VM with memory limits', scalar(keys %memory_limit)));
|
||||
$self->display_verbose(label => 'Memory limits:', vms => \%memory_limit);
|
||||
}
|
||||
|
||||
if ($output_unknown ne "") {
|
||||
$output .= $output_append . "UNKNOWN - $output_unknown";
|
||||
$output_append = ". ";
|
||||
if (scalar(keys %disk_limit) > 0 &&
|
||||
!$self->{manager}->{output}->is_status(value => $self->{disk_limitset_status}, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $self->{disk_limitset_status},
|
||||
short_msg => sprintf('%d VM with disk limits', scalar(keys %disk_limit)));
|
||||
$self->display_verbose(label => 'Disk limits:', vms => \%disk_limit);
|
||||
}
|
||||
if ($output_critical ne "") {
|
||||
$output .= $output_append . "CRITICAL - Limits for VMs: $output_critical";
|
||||
$output_append = ". ";
|
||||
}
|
||||
if ($output_warning ne "") {
|
||||
$output .= $output_append . "WARNING - Limits for VMs: $output_warning";
|
||||
}
|
||||
if ($status == 0) {
|
||||
$output .= $output_append . "Limits are ok";
|
||||
}
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -9,7 +9,6 @@ sub new {
|
|||
my $class = shift;
|
||||
my $self = {};
|
||||
$self->{logger} = shift;
|
||||
$self->{obj_esxd} = shift;
|
||||
$self->{commandName} = 'memvm';
|
||||
|
||||
bless $self, $class;
|
||||
|
@ -22,56 +21,77 @@ sub getCommandName {
|
|||
}
|
||||
|
||||
sub checkArgs {
|
||||
my $self = shift;
|
||||
my ($vm, $warn, $crit) = @_;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($vm) || $vm eq "") {
|
||||
$self->{logger}->writeLogError("ARGS error: need vm name");
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($warn) && $warn ne '' && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: warn threshold must be a positive number");
|
||||
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 (defined($crit) && $crit ne '' && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number");
|
||||
if (defined($options{arguments}->{nopoweredon_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{nopoweredon_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for nopoweredon status '" . $options{arguments}->{nopoweredon_status} . "'");
|
||||
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");
|
||||
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;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my $self = shift;
|
||||
$self->{lvm} = $_[0];
|
||||
$self->{warn} = (defined($_[1]) ? $_[1] : undef);
|
||||
$self->{crit} = (defined($_[2]) ? $_[2] : undef);
|
||||
my ($self, %options) = @_;
|
||||
|
||||
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 {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{obj_esxd}->{perfcounter_speriod} > 0)) {
|
||||
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN');
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Can't retrieve perf counters.\n");
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my %filters = ('name' => $self->{lvm});
|
||||
my @properties = ('summary.config.memorySizeMB', 'runtime.connectionState', 'runtime.powerState');
|
||||
my %filters = ();
|
||||
my $multiple = 0;
|
||||
if (defined($self->{vm_hostname}) && !defined($self->{filter})) {
|
||||
$filters{name} = qr/^\Q$self->{vm_hostname}\E$/;
|
||||
} elsif (!defined($self->{vm_hostname})) {
|
||||
$filters{name} = qr/.*/;
|
||||
} else {
|
||||
$filters{name} = qr/$self->{vm_hostname}/;
|
||||
}
|
||||
my @properties = ('name', 'summary.config.memorySizeMB', 'runtime.connectionState', 'runtime.powerState');
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm},
|
||||
$$result[0]->{'runtime.connectionState'}->val,
|
||||
$$result[0]->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
my $memory_size = $$result[0]->{'summary.config.memorySizeMB'} * 1024 * 1024;
|
||||
return if (!defined($result));
|
||||
|
||||
my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd},
|
||||
$result,
|
||||
|
@ -80,28 +100,78 @@ sub run {
|
|||
{'label' => 'mem.vmmemctl.average', 'instances' => ['']},
|
||||
{'label' => 'mem.consumed.average', 'instances' => ['']},
|
||||
{'label' => 'mem.shared.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);
|
||||
|
||||
my $mem_consumed = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"}[0]));
|
||||
my $mem_active = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.active.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 $mem_ballooning = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.vmmemctl.average'}->{'key'} . ":"}[0]));
|
||||
my $mem_shared = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.shared.average'}->{'key'} . ":"}[0]));
|
||||
my $status = 0; # OK
|
||||
my $output = '';
|
||||
|
||||
if (defined($self->{warn}) && $mem_consumed * 100 / ($memory_size / 1024) >= $self->{warn}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if (defined($self->{crit}) && $mem_consumed * 100 / ($memory_size / 1024) >= $self->{crit}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All memory usages are ok"));
|
||||
}
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::esxd::common::vm_state(connector => $self->{obj_esxd},
|
||||
hostname => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power => $entity_view->{'runtime.powerState'}->val,
|
||||
status => $self->{disconnect_status},
|
||||
powerstatus => $self->{nopoweredon_status},
|
||||
multiple => $multiple) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
my $memory_size = $entity_view->{'summary.config.memorySizeMB'} * 1024 * 1024;
|
||||
# in KB
|
||||
my $mem_consumed = 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_active = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.active.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_ballooning = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.vmmemctl.average'}->{'key'} . ":"}[0])) * 1024;
|
||||
my $mem_shared = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.shared.average'}->{'key'} . ":"}[0])) * 1024;
|
||||
|
||||
my $mem_free = $memory_size - $mem_consumed;
|
||||
my $prct_used = $mem_consumed * 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_consumed);
|
||||
my ($free_value, $free_unit) = $self->{manager}->{perfdata}->change_bytes(value => $mem_free);
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$entity_view->{name},
|
||||
$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));
|
||||
}
|
||||
|
||||
$output = "Memory usage : " . centreon::esxd::common::simplify_number($mem_consumed / 1024 / 1024) . " Go - size : " . centreon::esxd::common::simplify_number($memory_size / 1024 / 1024 / 1024) . " Go - percent : " . centreon::esxd::common::simplify_number($mem_consumed * 100 / ($memory_size / 1024)) . " %";
|
||||
$output .= "|usage=" . ($mem_consumed * 1024) . "o;" . (defined($self->{warn}) ? centreon::esxd::common::simplify_number($memory_size * $self->{warn} / 100, 0) : '') . ";" . (defined($self->{crit}) ? centreon::esxd::common::simplify_number($memory_size * $self->{crit} / 100, 0) : '') . ";0;" . ($memory_size) . " size=" . $memory_size . "o" . " overhead=" . ($mem_overhead * 1024) . "o" . " ballooning=" . ($mem_ballooning * 1024) . "o" . " shared=" . ($mem_shared * 1024) . "o" . " active=" . ($mem_active * 1024) . "o" ;
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'used' . $extra_label, unit => 'B',
|
||||
value => $mem_consumed,
|
||||
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);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'ballooning' . $extra_label, unit => 'B',
|
||||
value => $mem_ballooning,
|
||||
min => 0);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'active' . $extra_label, unit => 'B',
|
||||
value => $mem_active,
|
||||
min => 0);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'shared' . $extra_label, unit => 'B',
|
||||
value => $mem_shared,
|
||||
min => 0);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -242,7 +242,7 @@ sub run {
|
|||
min => 0, max => $interface_speed);
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => "$entity_view->{name}' $long_msg");
|
||||
$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,
|
||||
|
|
|
@ -9,7 +9,6 @@ sub new {
|
|||
my $class = shift;
|
||||
my $self = {};
|
||||
$self->{logger} = shift;
|
||||
$self->{obj_esxd} = shift;
|
||||
$self->{commandName} = 'snapshotvm';
|
||||
|
||||
bless $self, $class;
|
||||
|
@ -22,155 +21,145 @@ sub getCommandName {
|
|||
}
|
||||
|
||||
sub checkArgs {
|
||||
my $self = shift;
|
||||
my ($vm, $filter, $warn, $crit) = @_;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($vm) || $vm eq "") {
|
||||
$self->{logger}->writeLogError("ARGS error: need vm hostname");
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($warn) && $warn ne "" && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: warn threshold must be a positive number");
|
||||
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 (defined($crit) && $crit ne "" && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number");
|
||||
foreach my $label (('warning', 'critical')) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my $self = shift;
|
||||
$self->{lvm} = $_[0];
|
||||
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||
$self->{warning} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 86400 * 3);
|
||||
$self->{critical} = ((defined($_[3]) and $_[3] ne '') ? $_[3] : 86400 * 5);
|
||||
$self->{consolidate} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
||||
$self->{skip_errors} = (defined($_[5]) && $_[5] == 1) ? 1 : 0;
|
||||
$self->{skip_not_running} = (defined($_[6]) && $_[6] == 1) ? 1 : 0;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::esxd::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning', 'critical')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
}
|
||||
|
||||
sub set_connector {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{obj_esxd} = $options{connector};
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if ($self->{obj_esxd}->{module_date_parse_loaded} == 0) {
|
||||
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN');
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Need to install Date::Parse CPAN Module.\n");
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Need to install Date::Parse CPAN Module");
|
||||
return ;
|
||||
}
|
||||
|
||||
my %filters = ();
|
||||
|
||||
if ($self->{filter} == 0) {
|
||||
$filters{name} = qr/^\Q$self->{lvm}\E$/;
|
||||
my $multiple = 0;
|
||||
if (defined($self->{vm_hostname}) && !defined($self->{filter})) {
|
||||
$filters{name} = qr/^\Q$self->{vm_hostname}\E$/;
|
||||
} elsif (!defined($self->{vm_hostname})) {
|
||||
$filters{name} = qr/.*/;
|
||||
} else {
|
||||
$filters{name} = qr/$self->{lvm}/;
|
||||
$filters{name} = qr/$self->{vm_hostname}/;
|
||||
}
|
||||
my @properties;
|
||||
push @properties, 'snapshot.rootSnapshotList', 'name', 'runtime.connectionState', 'runtime.powerState';
|
||||
if ($self->{consolidate} == 1) {
|
||||
if (defined($self->{check_consolidation}) == 1) {
|
||||
push @properties, 'runtime.consolidationNeeded';
|
||||
}
|
||||
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
return if (!defined($result));
|
||||
|
||||
my %vm_consolidate = ();
|
||||
my %vm_errors = (warning => {}, critical => {});
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All snapshots are ok"));
|
||||
} else {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("Snapshot(s) OK"));
|
||||
}
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::esxd::common::vm_state(connector => $self->{obj_esxd},
|
||||
hostname => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
status => $self->{disconnect_status},
|
||||
nocheck_ps => 1,
|
||||
multiple => $multiple) == 0);
|
||||
|
||||
next if (defined($self->{nopoweredon_skip}) &&
|
||||
!centreon::esxd::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
if (defined($self->{check_consolidation}) && defined($entity_view->{'runtime.consolidationNeeded'}) && $entity_view->{'runtime.consolidationNeeded'} =~ /^true|1$/i) {
|
||||
$vm_consolidate{$entity_view->{name}} = 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 = 'Snapshot(s) OK';
|
||||
my $consolidate_vms = '';
|
||||
my $consolidate_vms_append = '';
|
||||
my ($num_warning, $num_critical) = (0, 0);
|
||||
next if (!defined($entity_view->{'snapshot.rootSnapshotList'}));
|
||||
|
||||
foreach my $virtual (@$result) {
|
||||
if (!centreon::esxd::common::is_connected($virtual->{'runtime.connectionState'}->val)) {
|
||||
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, ", ",
|
||||
"'" . $virtual->{name} . "' not connected");
|
||||
}
|
||||
next;
|
||||
}
|
||||
|
||||
if ($self->{skip_not_running} == 1 &&
|
||||
!centreon::esxd::common::is_running($virtual->{'runtime.powerState'}->val)) {
|
||||
next;
|
||||
}
|
||||
|
||||
if ($self->{consolidate} == 1 && defined($virtual->{'runtime.consolidationNeeded'}) && $virtual->{'runtime.consolidationNeeded'} =~ /^true|1$/i) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$consolidate_vms .= $consolidate_vms_append . '[' . $virtual->{'name'} . ']';
|
||||
$consolidate_vms_append = ', ';
|
||||
}
|
||||
|
||||
if (!defined($virtual->{'snapshot.rootSnapshotList'})) {
|
||||
next;
|
||||
}
|
||||
|
||||
foreach my $snapshot (@{$virtual->{'snapshot.rootSnapshotList'}}) {
|
||||
foreach my $snapshot (@{$entity_view->{'snapshot.rootSnapshotList'}}) {
|
||||
# 2012-09-21T14:16:17.540469Z
|
||||
my $create_time = Date::Parse::str2time($snapshot->createTime);
|
||||
if (!defined($create_time)) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN');
|
||||
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||
"Can't Parse date '" . $snapshot->createTime . "' for vm [" . $virtual->{'name'} . "]");
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't Parse date '" . $snapshot->createTime . "' for vm '" . $entity_view->{name} . "'");
|
||||
next;
|
||||
}
|
||||
if (time() - $create_time >= $self->{critical}) {
|
||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||
"[" . $virtual->{'name'}. "]");
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$num_critical++;
|
||||
last;
|
||||
} elsif (time() - $create_time >= $self->{warning}) {
|
||||
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||
"[" . $virtual->{'name'}. "]");
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$num_warning++;
|
||||
last;
|
||||
|
||||
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' } ]);
|
||||
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$vm_errors{$exit}->{$entity_view->{name}} = 1;
|
||||
$self->{manager}->{output}->output_add(long_msg => "'$entity_view->{name}' snapshot create time: " . $snapshot->createTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $perfdata = 'num_warning=' . $num_warning . ' num_critical=' . $num_critical;
|
||||
if ($output_unknown ne "") {
|
||||
$output .= $output_append . "UNKNOWN - $output_unknown";
|
||||
$output_append = ". ";
|
||||
$self->{manager}->{output}->perfdata_add(label => 'num_warning',
|
||||
value => scalar(keys %{$vm_errors{warning}}),
|
||||
min => 0);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'num_critical',
|
||||
value => scalar(keys %{$vm_errors{critical}}),
|
||||
min => 0);
|
||||
if (scalar(keys %{$vm_errors{warning}}) > 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'WARNING',
|
||||
short_msg => sprintf('Snapshots for VM older than %d days: [%s]', ($self->{warning} / 86400),
|
||||
join('] [', sort keys %{$vm_errors{warning}})));
|
||||
}
|
||||
if ($consolidate_vms ne "") {
|
||||
$output .= $output_append . "CRITICAL - VMs need consolidation : " . $consolidate_vms;
|
||||
$output_append = ". ";
|
||||
if (scalar(keys %{$vm_errors{critical}}) > 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => sprintf('Snapshots for VM older than %d days: [%s]', ($self->{critical} / 86400),
|
||||
join('] [', sort keys %{$vm_errors{critical}})));
|
||||
}
|
||||
if ($output_critical ne "") {
|
||||
$output .= $output_append . "CRITICAL - Snapshots for VM older than " . ($self->{critical} / 86400) . " days: $output_critical";
|
||||
$output_append = ". ";
|
||||
if (scalar(keys %vm_consolidate) > 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => sprintf('VMs need consolidation: [%s]',
|
||||
join('] [', sort keys %vm_consolidate)));
|
||||
}
|
||||
if ($output_warning ne "") {
|
||||
$output .= $output_append . "WARNING - Snapshots for VM older than " . ($self->{warning} / 86400) . " days: $output_warning";
|
||||
}
|
||||
if ($status == 0) {
|
||||
if ($self->{filter} == 1) {
|
||||
$output .= $output_append . "All snapshots are ok";
|
||||
} else {
|
||||
$output .= $output_append . $output_ok_unit;
|
||||
}
|
||||
}
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output|$perfdata\n");
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -94,7 +94,8 @@ sub run {
|
|||
$result,
|
||||
[{'label' => 'mem.swapinRate.average', 'instances' => ['']},
|
||||
{'label' => 'mem.swapoutRate.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);
|
||||
|
||||
if ($multiple == 1) {
|
||||
|
@ -110,8 +111,8 @@ sub run {
|
|||
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 $swap_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$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->{$entity_value}->{$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' } ]);
|
||||
|
|
|
@ -9,7 +9,6 @@ sub new {
|
|||
my $class = shift;
|
||||
my $self = {};
|
||||
$self->{logger} = shift;
|
||||
$self->{obj_esxd} = shift;
|
||||
$self->{commandName} = 'swapvm';
|
||||
|
||||
bless $self, $class;
|
||||
|
@ -22,78 +21,140 @@ sub getCommandName {
|
|||
}
|
||||
|
||||
sub checkArgs {
|
||||
my $self = shift;
|
||||
my ($vm, $warn, $crit) = @_;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($vm) || $vm eq "") {
|
||||
$self->{logger}->writeLogError("ARGS error: need vm name");
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($warn) && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: warn threshold must be a positive number");
|
||||
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 (defined($crit) && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
$self->{logger}->writeLogError("ARGS error: crit threshold must be a positive number");
|
||||
if (defined($options{arguments}->{nopoweredon_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{nopoweredon_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for nopoweredon status '" . $options{arguments}->{nopoweredon_status} . "'");
|
||||
return 1;
|
||||
}
|
||||
if (defined($warn) && defined($crit) && $warn > $crit) {
|
||||
$self->{logger}->writeLogError("ARGS error: warn threshold must be lower than crit threshold");
|
||||
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;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my $self = shift;
|
||||
$self->{lvm} = $_[0];
|
||||
$self->{warn} = (defined($_[1]) ? $_[1] : 0.8);
|
||||
$self->{crit} = (defined($_[2]) ? $_[2] : 1);
|
||||
my ($self, %options) = @_;
|
||||
|
||||
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 {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{obj_esxd}->{perfcounter_speriod} > 0)) {
|
||||
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN');
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Can't retrieve perf counters.\n");
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my %filters = ('name' => $self->{lvm});
|
||||
my %filters = ();
|
||||
my $multiple = 0;
|
||||
if (defined($self->{vm_hostname}) && !defined($self->{filter})) {
|
||||
$filters{name} = qr/^\Q$self->{vm_hostname}\E$/;
|
||||
} elsif (!defined($self->{vm_hostname})) {
|
||||
$filters{name} = qr/.*/;
|
||||
} else {
|
||||
$filters{name} = qr/$self->{vm_hostname}/;
|
||||
}
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState');
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
return if (centreon::esxd::common::vm_state($self->{obj_esxd}, $self->{lvm},
|
||||
$$result[0]->{'runtime.connectionState'}->val,
|
||||
$$result[0]->{'runtime.powerState'}->val) == 0);
|
||||
return if (!defined($result));
|
||||
|
||||
my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd},
|
||||
$result,
|
||||
[{'label' => 'mem.swapinRate.average', 'instances' => ['']},
|
||||
{'label' => 'mem.swapoutRate.average', 'instances' => ['']}],
|
||||
$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);
|
||||
|
||||
my $swap_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"}[0]));
|
||||
my $swap_out = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"}[0]));
|
||||
my $status = 0; # OK
|
||||
my $output = '';
|
||||
|
||||
if (($swap_in / 1024) >= $self->{warn} || ($swap_out / 1024) >= $self->{warn}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if (($swap_in / 1024) >= $self->{crit} || ($swap_out / 1024) >= $self->{crit}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All swap rate usages are ok"));
|
||||
}
|
||||
|
||||
$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";
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::esxd::common::vm_state(connector => $self->{obj_esxd},
|
||||
hostname => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power => $entity_view->{'runtime.powerState'}->val,
|
||||
status => $self->{disconnect_status},
|
||||
powerstatus => $self->{nopoweredon_status},
|
||||
multiple => $multiple) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||
# KBps
|
||||
my $swap_in = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$entity_value}->{$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->{$entity_value}->{$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);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -9,7 +9,6 @@ sub new {
|
|||
my $class = shift;
|
||||
my $self = {};
|
||||
$self->{logger} = shift;
|
||||
$self->{obj_esxd} = shift;
|
||||
$self->{commandName} = 'toolsvm';
|
||||
|
||||
bless $self, $class;
|
||||
|
@ -22,110 +21,133 @@ sub getCommandName {
|
|||
}
|
||||
|
||||
sub checkArgs {
|
||||
my $self = shift;
|
||||
my ($vm) = @_;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($vm) || $vm eq "") {
|
||||
$self->{logger}->writeLogError("ARGS error: need vm hostname");
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{tools_notinstalled_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{tools_notinstalled_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for tools notinstalled status '" . $options{arguments}->{tools_notinstalled_status} . "'");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{tools_notrunning_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{tools_notrunning_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for tools notrunning status '" . $options{arguments}->{tools_notrunning_status} . "'");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{tools_notupd2date_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{tools_notupd2date_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for tools notupd2date status '" . $options{arguments}->{tools_notupd2date_status} . "'");
|
||||
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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my $self = shift;
|
||||
$self->{lvm} = $_[0];
|
||||
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||
$self->{skip_errors} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||
$self->{skip_not_running} = (defined($_[3]) && $_[3] == 1) ? 1 : 0;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::esxd::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
}
|
||||
|
||||
sub set_connector {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{obj_esxd} = $options{connector};
|
||||
}
|
||||
|
||||
sub display_verbose {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => $options{label});
|
||||
foreach my $vm (sort keys %{$options{vms}}) {
|
||||
$self->{manager}->{output}->output_add(long_msg => ' ' . $vm);
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my %filters = ();
|
||||
|
||||
if ($self->{filter} == 0) {
|
||||
$filters{name} = qr/^\Q$self->{lvm}\E$/;
|
||||
my $multiple = 0;
|
||||
if (defined($self->{vm_hostname}) && !defined($self->{filter})) {
|
||||
$filters{name} = qr/^\Q$self->{vm_hostname}\E$/;
|
||||
} elsif (!defined($self->{vm_hostname})) {
|
||||
$filters{name} = qr/.*/;
|
||||
} else {
|
||||
$filters{name} = qr/$self->{lvm}/;
|
||||
$filters{name} = qr/$self->{vm_hostname}/;
|
||||
}
|
||||
|
||||
my @properties = ('name', 'summary.guest.toolsStatus', 'runtime.connectionState', 'runtime.powerState');
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
}
|
||||
return if (!defined($result));
|
||||
|
||||
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 $not_installed = '';
|
||||
my $not_running = '';
|
||||
my $not_up2date = '';
|
||||
|
||||
foreach my $virtual (@$result) {
|
||||
if (!centreon::esxd::common::is_connected($virtual->{'runtime.connectionState'}->val)) {
|
||||
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, ", ",
|
||||
"'" . $virtual->{name} . "' not connected");
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
next;
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All VMTools are OK"));
|
||||
} else {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("VMTools are OK"));
|
||||
}
|
||||
my %not_installed = ();
|
||||
my %not_running = ();
|
||||
my %not_up2date = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::esxd::common::vm_state(connector => $self->{obj_esxd},
|
||||
hostname => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
status => $self->{disconnect_status},
|
||||
nocheck_ps => 1,
|
||||
multiple => $multiple) == 0);
|
||||
|
||||
if ($self->{skip_not_running} == 1 &&
|
||||
!centreon::esxd::common::is_running($virtual->{'runtime.powerState'}->val)) {
|
||||
next;
|
||||
}
|
||||
next if (defined($self->{nopoweredon_skip}) &&
|
||||
!centreon::esxd::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
my $tools_status = lc($virtual->{'summary.guest.toolsStatus'}->val);
|
||||
my $tools_status = lc($entity_view->{'summary.guest.toolsStatus'}->val);
|
||||
if ($tools_status eq 'toolsnotinstalled') {
|
||||
$not_installed .= ' [' . $virtual->{name} . ']';
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$not_installed{$entity_view->{name}} = 1;
|
||||
} elsif ($tools_status eq 'toolsnotrunning') {
|
||||
$not_running .= ' [' . $virtual->{name} . ']';
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$not_running{$entity_view->{name}} = 1;
|
||||
} elsif ($tools_status eq 'toolsold') {
|
||||
$not_up2date .= ' [' . $virtual->{name} . ']';
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$not_up2date{$entity_view->{name}} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($not_installed ne '') {
|
||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||
"VMTools not installed on VM:" . $not_installed);
|
||||
if (scalar(keys %not_up2date) > 0 &&
|
||||
!$self->{manager}->{output}->is_status(value => $self->{tools_notupd2date_status}, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $self->{tools_notupd2date_status},
|
||||
short_msg => sprintf('%d VM with VMTools not up-to-date', scalar(keys %not_up2date)));
|
||||
$self->display_verbose(label => 'vmtools not up-to-date:', vms => \%not_up2date);
|
||||
}
|
||||
if ($not_running ne '') {
|
||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||
"VMTools not running on VM:" . $not_running);
|
||||
if (scalar(keys %not_running) > 0 &&
|
||||
!$self->{manager}->{output}->is_status(value => $self->{tools_notrunning_status}, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $self->{tools_notrunning_status},
|
||||
short_msg => sprintf('%d VM with VMTools not running', scalar(keys %not_running)));
|
||||
$self->display_verbose(label => 'vmtools not running:', vms => \%not_running);
|
||||
}
|
||||
if ($not_up2date ne '') {
|
||||
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||
"VMTools not up-to-date on VM:" . $not_up2date);
|
||||
if (scalar(keys %not_installed) > 0 &&
|
||||
!$self->{manager}->{output}->is_status(value => $self->{tools_notupd2date_status}, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $self->{tools_notupd2date_status},
|
||||
short_msg => sprintf('%d VM with VMTools not installed', scalar(keys %not_installed)));
|
||||
$self->display_verbose(label => 'vmtools not installed:', vms => \%not_installed);
|
||||
}
|
||||
|
||||
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) {
|
||||
$output .= $output_append . "VMTools are OK.";
|
||||
}
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -406,9 +406,9 @@ sub is_connected {
|
|||
}
|
||||
|
||||
sub is_running {
|
||||
my ($power_state) = @_;
|
||||
my (%options) = @_;
|
||||
|
||||
if ($power_state !~ /^poweredOn$/i) {
|
||||
if ($options{power} !~ /^poweredOn$/i) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
@ -428,19 +428,27 @@ sub datastore_state {
|
|||
}
|
||||
|
||||
sub vm_state {
|
||||
my ($obj_esxd, $vm, $connection_state, $power_state, $nocheck_ps) = @_;
|
||||
my (%options) = @_;
|
||||
my $status = defined($options{status}) ? $options{status} : $options{connector}->{centreonesxd_config}->{host_state_error};
|
||||
my $power_status = defined($options{powerstatus}) ? $options{powerstatus} : $options{connector}->{centreonesxd_config}->{vm_state_error};
|
||||
|
||||
if ($connection_state !~ /^connected$/i) {
|
||||
my $output = "VM '" . $vm . "' not connected. Current Connection State: '$connection_state'.";
|
||||
$manager_display->{output}->output_add(severity => $obj_esxd->{centreonesxd_config}->{vm_state_error},
|
||||
if ($options{state} !~ /^connected$/i) {
|
||||
my $output = "VM '" . $options{hostname} . "' not connected. Current Connection State: '$options{state}'.";
|
||||
if ($options{multiple} == 0 ||
|
||||
!$manager_display->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$manager_display->{output}->output_add(severity => $status,
|
||||
short_msg => $output);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!defined($nocheck_ps) && $power_state !~ /^poweredOn$/i) {
|
||||
my $output = "VM '" . $vm . "' not running. Current Power State: '$power_state'.";
|
||||
$manager_display->{output}->output_add(severity => $obj_esxd->{centreonesxd_config}->{vm_state_error},
|
||||
if (!defined($options{nocheck_ps}) && $options{power} !~ /^poweredOn$/i) {
|
||||
my $output = "VM '" . $options{hostname} . "' not running. Current Power State: '$options{power}'.";
|
||||
if ($options{multiple} == 0 ||
|
||||
!$manager_display->{output}->is_status(value => $power_status, compare => 'ok', litteral => 1)) {
|
||||
$manager_display->{output}->output_add(severity => $power_status,
|
||||
short_msg => $output);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue