mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-29 00:24:46 +02:00
WIP: new version centreon-vmware 3.0.0
This commit is contained in:
parent
5160ff8705
commit
6c35fdb854
@ -331,8 +331,7 @@ sub waiting_ready {
|
||||
}
|
||||
|
||||
if ($self->{centreon_vmware_config}->{vsphere_server}->{$options{container}}->{ready} == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "connector still not ready.");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "connector still not ready.");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return 0;
|
||||
}
|
||||
@ -345,8 +344,7 @@ sub request_dynamic {
|
||||
|
||||
if (!defined($options{result}->{vsphere_username}) || $options{result}->{vsphere_username} eq '' ||
|
||||
!defined($options{result}->{vsphere_password}) || $options{result}->{vsphere_password} eq '') {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Please set vsphere username or password");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Please set vsphere username or password");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
@ -386,20 +384,17 @@ sub request {
|
||||
$result = JSON->new->utf8->decode($options{data});
|
||||
};
|
||||
if ($@) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Cannot decode json result: $@");
|
||||
centreon::vmware::common::set_response(code => 1, short_message => "Cannot decode json result: $@");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
if ($result->{command} eq 'stats') {
|
||||
centreon::vmware::common::stats_info(manager => $options{manager},
|
||||
counters => $self->{counter_stats});
|
||||
centreon::vmware::common::stats_info(counters => $self->{counter_stats});
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
if (!defined($self->{modules_registry}->{$result->{command}})) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Unknown method name '$result->{command}'");
|
||||
centreon::vmware::common::set_response(code => 1, short_message => "Unknown method name '$result->{command}'");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
@ -416,8 +411,7 @@ sub request {
|
||||
}
|
||||
|
||||
if (!defined($self->{centreon_vmware_config}->{vsphere_server}->{$result->{container}})) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Unknown container name '$result->{container}'");
|
||||
centreon::vmware::common::set_response(code => 1, short_message => "Unknown container name '$result->{container}'");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
@ -448,12 +442,12 @@ sub repserver {
|
||||
$self->{logger}->writeLogError("Cannot decode JSON: $@ (options{data}");
|
||||
return ;
|
||||
}
|
||||
|
||||
$result->{plugin}->{name} =~ /^client-(.*)$/;
|
||||
|
||||
$result->{identity} =~ /^client-(.*)$/;
|
||||
my $identity = 'client-' . pack('H*', $1);
|
||||
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend,
|
||||
identity => $identity, stdout => $options{data});
|
||||
identity => $identity, force_response => $options{data});
|
||||
}
|
||||
|
||||
sub router_event {
|
||||
@ -469,16 +463,15 @@ sub router_event {
|
||||
my $data = zmq_msg_data($msg);
|
||||
zmq_msg_close($msg);
|
||||
|
||||
my $manager = centreon::vmware::common::init_response();
|
||||
centreon::vmware::common::init_response();
|
||||
if ($centreon_vmware->{stop} != 0) {
|
||||
# We quit so we say we're leaving ;)
|
||||
$manager->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Daemon is restarting/stopping...');
|
||||
centreon::vmware::common::set_response(code => -1, short_message => 'Daemon is restarting/stopping...');
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $identity);
|
||||
} elsif ($data =~ /^REQCLIENT\s+(.*)$/msi) {
|
||||
$centreon_vmware->request(identity => $identity, data => $1, manager => $manager);
|
||||
$centreon_vmware->request(identity => $identity, data => $1);
|
||||
} elsif ($data =~ /^RESPSERVER2\s+(.*)$/msi) {
|
||||
$centreon_vmware->repserver(data => $1, manager => $manager);
|
||||
$centreon_vmware->repserver(data => $1);
|
||||
} elsif ($data =~ /^READY/msi) {
|
||||
$identity =~ /server-(.*)/;
|
||||
$centreon_vmware->{centreon_vmware_config}->{vsphere_server}->{$1}->{ready} = 1;
|
||||
|
@ -23,8 +23,6 @@ use base qw(centreon::vmware::cmdbase);
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
@ -40,123 +38,40 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datacenter}) && $options{arguments}->{datacenter} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: datacenter cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datacenter cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => 0);
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => 0);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (defined($self->{memory})) {
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(output => $self->{manager}->{output});
|
||||
$self->{statefile_cache}->read(statefile_dir => $self->{connector}->{retention_dir},
|
||||
statefile => "cache_vmware_connector_" . $self->{connector}->{whoaim} . "_" . $self->{commandName} . "_" . (defined($self->{datacenter}) ? md5_hex($self->{datacenter}) : md5_hex('.*')),
|
||||
statefile_suffix => '',
|
||||
no_quit => 1);
|
||||
return if ($self->{statefile_cache}->error() == 1);
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
if (defined($self->{filter_time}) && $self->{filter_time} ne '' && $self->{connector}->{module_date_parse_loaded} == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Need to install Date::Parse CPAN Module");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datacenter', is_regexp => 'filter');
|
||||
my @properties = ('name', 'triggeredAlarmState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datacenter', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("No current alarms on datacenter(s)"));
|
||||
|
||||
my $total_alarms = { red => 0, yellow => 0 };
|
||||
my $dc_alarms = {};
|
||||
my $new_datas = {};
|
||||
my $data = {};
|
||||
foreach my $datacenter_view (@$result) {
|
||||
$dc_alarms->{$datacenter_view->name} = { red => 0, yellow => 0, alarms => {} };
|
||||
$data->{$datacenter_view->{mo_ref}->{value}} = { name => $datacenter_view->name, red => 0, yellow => 0, alarms => {} };
|
||||
next if (!defined($datacenter_view->triggeredAlarmState));
|
||||
foreach (@{$datacenter_view->triggeredAlarmState}) {
|
||||
next if ($_->overallStatus->val !~ /(red|yellow)/i);
|
||||
if (defined($self->{filter_time}) && $self->{filter_time} ne '') {
|
||||
my $time_sec = Date::Parse::str2time($_->time);
|
||||
next if (time() - $time_sec > $self->{filter_time});
|
||||
}
|
||||
$new_datas->{$_->key} = 1;
|
||||
next if (defined($self->{memory}) && defined($self->{statefile_cache}->get(name => $_->key)));
|
||||
|
||||
|
||||
my $entity = centreon::vmware::common::get_view($self->{connector}, $_->entity, ['name']);
|
||||
my $alarm = centreon::vmware::common::get_view($self->{connector}, $_->alarm, ['info']);
|
||||
|
||||
$dc_alarms->{$datacenter_view->name}->{alarms}->{$_->key} = { type => $_->entity->type, entity_name => $entity->name,
|
||||
time => $_->time, name => $alarm->info->name,
|
||||
description => $alarm->info->description,
|
||||
status => $_->overallStatus->val};
|
||||
$dc_alarms->{$datacenter_view->name}->{$_->overallStatus->val}++;
|
||||
$total_alarms->{$_->overallStatus->val}++;
|
||||
$data->{$datacenter_view->{mo_ref}->{value}}->{alarms}->{$_->key} = { type => $_->entity->type, entity_name => $entity->name,
|
||||
time => $_->time, name => $alarm->info->name,
|
||||
description => $alarm->info->description,
|
||||
status => $_->overallStatus->val
|
||||
};
|
||||
$data->{$datacenter_view->{mo_ref}->{value}}->{$_->overallStatus->val}++;
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $total_alarms->{yellow},
|
||||
threshold => [ { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%s alarm(s) found(s)", $total_alarms->{yellow}));
|
||||
}
|
||||
$exit = $self->{manager}->{perfdata}->threshold_check(value => $total_alarms->{red}, threshold => [ { label => 'critical', exit_litteral => 'critical' } ]);
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%s alarm(s) found(s)", $total_alarms->{red}));
|
||||
}
|
||||
|
||||
foreach my $dc_name (keys %{$dc_alarms}) {
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("Checking datacenter %s", $dc_name));
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" %s warn alarm(s) found(s) - %s critical alarm(s) found(s)",
|
||||
$dc_alarms->{$dc_name}->{yellow}, $dc_alarms->{$dc_name}->{red}));
|
||||
foreach my $alert (keys %{$dc_alarms->{$dc_name}->{alarms}}) {
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" [%s] [%s] [%s] [%s] %s/%s",
|
||||
$dc_alarms->{$dc_name}->{alarms}->{$alert}->{status},
|
||||
$dc_alarms->{$dc_name}->{alarms}->{$alert}->{type},
|
||||
$dc_alarms->{$dc_name}->{alarms}->{$alert}->{entity_name},
|
||||
$dc_alarms->{$dc_name}->{alarms}->{$alert}->{time},
|
||||
$dc_alarms->{$dc_name}->{alarms}->{$alert}->{name},
|
||||
$dc_alarms->{$dc_name}->{alarms}->{$alert}->{description}
|
||||
));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $dc_name if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'alarm_warning' . $extra_label,
|
||||
value => $dc_alarms->{$dc_name}->{yellow},
|
||||
min => 0);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'alarm_critical' . $extra_label,
|
||||
value => $dc_alarms->{$dc_name}->{red},
|
||||
min => 0);
|
||||
}
|
||||
|
||||
if (defined($self->{memory})) {
|
||||
$self->{statefile_cache}->write(data => $new_datas);
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -23,8 +23,6 @@ use base qw(centreon::vmware::cmdbase);
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
@ -40,123 +38,41 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: esx hostname cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => 0);
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => 0);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (defined($self->{memory})) {
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(output => $self->{manager}->{output});
|
||||
$self->{statefile_cache}->read(statefile_dir => $self->{connector}->{retention_dir},
|
||||
statefile => "cache_vmware_connector_" . $self->{connector}->{whoaim} . "_" . (defined($self->{esx_hostname}) ? md5_hex($self->{esx_hostname}) : md5_hex('.*')),
|
||||
statefile_suffix => '',
|
||||
no_quit => 1);
|
||||
return if ($self->{statefile_cache}->error() == 1);
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
|
||||
if (defined($self->{filter_time}) && $self->{filter_time} ne '' && $self->{connector}->{module_date_parse_loaded} == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Need to install Date::Parse CPAN Module");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'triggeredAlarmState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("No current alarms on host(s)"));
|
||||
|
||||
my $total_alarms = { red => 0, yellow => 0 };
|
||||
my $host_alarms = {};
|
||||
my $new_datas = {};
|
||||
my $data = {};
|
||||
foreach my $host_view (@$result) {
|
||||
$host_alarms->{$host_view->name} = { red => 0, yellow => 0, alarms => {} };
|
||||
$data->{$host_view->{mo_ref}->{value}} = { name => $host_view->name, red => 0, yellow => 0, alarms => {} };
|
||||
next if (!defined($host_view->triggeredAlarmState));
|
||||
foreach(@{$host_view->triggeredAlarmState}) {
|
||||
next if ($_->overallStatus->val !~ /(red|yellow)/i);
|
||||
if (defined($self->{filter_time}) && $self->{filter_time} ne '') {
|
||||
my $time_sec = Date::Parse::str2time($_->time);
|
||||
next if (time() - $time_sec > $self->{filter_time});
|
||||
}
|
||||
$new_datas->{$_->key} = 1;
|
||||
next if (defined($self->{memory}) && defined($self->{statefile_cache}->get(name => $_->key)));
|
||||
|
||||
my $entity = centreon::vmware::common::get_view($self->{connector}, $_->entity, ['name']);
|
||||
my $alarm = centreon::vmware::common::get_view($self->{connector}, $_->alarm, ['info']);
|
||||
|
||||
$host_alarms->{$host_view->name}->{alarms}->{$_->key} = { type => $_->entity->type, entity_name => $entity->name,
|
||||
time => $_->time, name => $alarm->info->name,
|
||||
description => $alarm->info->description,
|
||||
status => $_->overallStatus->val};
|
||||
$host_alarms->{$host_view->name}->{$_->overallStatus->val}++;
|
||||
$total_alarms->{$_->overallStatus->val}++;
|
||||
$data->{$host_view->{mo_ref}->{value}}->{alarms}->{$_->key} = {
|
||||
type => $_->entity->type, entity_name => $entity->name,
|
||||
time => $_->time, name => $alarm->info->name,
|
||||
description => $alarm->info->description,
|
||||
status => $_->overallStatus->val
|
||||
};
|
||||
$data->{$host_view->{mo_ref}->{value}}->{$_->overallStatus->val}++;
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $total_alarms->{yellow},
|
||||
threshold => [ { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%s alarm(s) found(s)", $total_alarms->{yellow}));
|
||||
}
|
||||
$exit = $self->{manager}->{perfdata}->threshold_check(value => $total_alarms->{red}, threshold => [ { label => 'critical', exit_litteral => 'critical' } ]);
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%s alarm(s) found(s)", $total_alarms->{red}));
|
||||
}
|
||||
|
||||
foreach my $host_name (keys %{$host_alarms}) {
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("Checking host %s", $host_name));
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" %s warn alarm(s) found(s) - %s critical alarm(s) found(s)",
|
||||
$host_alarms->{$host_name}->{yellow}, $host_alarms->{$host_name}->{red}));
|
||||
foreach my $alert (keys %{$host_alarms->{$host_name}->{alarms}}) {
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" [%s] [%s] [%s] [%s] %s/%s",
|
||||
$host_alarms->{$host_name}->{alarms}->{$alert}->{status},
|
||||
$host_alarms->{$host_name}->{alarms}->{$alert}->{type},
|
||||
$host_alarms->{$host_name}->{alarms}->{$alert}->{entity_name},
|
||||
$host_alarms->{$host_name}->{alarms}->{$alert}->{time},
|
||||
$host_alarms->{$host_name}->{alarms}->{$alert}->{name},
|
||||
$host_alarms->{$host_name}->{alarms}->{$alert}->{description}
|
||||
));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $host_name if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'alarm_warning' . $extra_label,
|
||||
value => $host_alarms->{$host_name}->{yellow},
|
||||
min => 0);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'alarm_critical' . $extra_label,
|
||||
value => $host_alarms->{$host_name}->{red},
|
||||
min => 0);
|
||||
}
|
||||
|
||||
if (defined($self->{memory})) {
|
||||
$self->{statefile_cache}->write(data => $new_datas);
|
||||
}
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -20,6 +20,7 @@ package centreon::vmware::cmdbase;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
my %handlers = (ALRM => {});
|
||||
|
||||
@ -67,6 +68,15 @@ sub set_connector {
|
||||
alarm(300);
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
centreon::vmware::common::init_response(identity => $options{arguments}->{identity});
|
||||
}
|
||||
|
||||
sub build_filter {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -38,52 +38,21 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: esx hostname cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx 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;
|
||||
}
|
||||
foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) {
|
||||
if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'vm', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
|
||||
|
||||
#return if (centreon::vmware::common::host_state($self->{connector}, $self->{lhost},
|
||||
# $$result[0]->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
@ -97,19 +66,11 @@ sub run {
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@vm_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All ESX Hosts are ok"));
|
||||
}
|
||||
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::host_state(connector => $self->{connector},
|
||||
hostname => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
status => $self->{disconnect_status},
|
||||
multiple => $multiple) == 0);
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
$data->{$entity_view->{name}} = { state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my %vm_states = (poweredon => 0, poweredoff => 0, suspended => 0);
|
||||
if (defined($entity_view->vm)) {
|
||||
foreach my $vm_host (@{$entity_view->vm}) {
|
||||
@ -123,30 +84,10 @@ sub run {
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $labels ((['poweredon', 'warning_on', 'critical_on'],
|
||||
['poweredoff', 'warning_off', 'critical_off'],
|
||||
['suspended', 'warning_suspended', 'critical_suspended'])) {
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $vm_states{$labels->[0]},
|
||||
threshold => [ { label => $labels->[2], exit_litteral => 'critical' },
|
||||
{ label => $labels->[1], exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' %s VM(s) %s", $entity_view->{name},
|
||||
$vm_states{$labels->[0]},
|
||||
$labels->[0]));
|
||||
if ($multiple == 0 ||
|
||||
!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("'%s' %s VM(s) %s", $entity_view->{name},
|
||||
$vm_states{$labels->[0]},
|
||||
$labels->[0]));
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->perfdata_add(label => $labels->[0] . $extra_label,
|
||||
value => $vm_states{$labels->[0]},
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => $labels->[1]),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => $labels->[2]),
|
||||
min => 0, max => $vm_states{poweredoff} + $vm_states{suspended} + $vm_states{poweredon});
|
||||
}
|
||||
$data->{$entity_view->{name}} = { %{$data->{$entity_view->{name}}}, %vm_states };
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,59 +38,26 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: esx hostname cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx 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 (($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, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::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});
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'runtime.connectionState', 'summary.hardware.numCpuCores', 'summary.hardware.cpuMhz');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
my @instances = ('*');
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
$result,
|
||||
@ -103,42 +70,22 @@ sub run {
|
||||
|
||||
my $interval_min = centreon::vmware::common::get_interval_min(speriod => $self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift});
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All Total Average CPU usages are ok"));
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::host_state(connector => $self->{connector},
|
||||
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};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"} * 0.01));
|
||||
my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}));
|
||||
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $total_cpu_average,
|
||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Total Average CPU usage '%s%%' on last %s min",
|
||||
$entity_view->{name}, $total_cpu_average, $interval_min));
|
||||
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' Total Average CPU usage '%s%%' on last %s min",
|
||||
$entity_view->{name}, $total_cpu_average, $interval_min));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'cpu_total' . $extra_label, unit => '%',
|
||||
value => $total_cpu_average,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0, max => 100);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'cpu_total_MHz' . $extra_label, unit => 'MHz',
|
||||
value => $total_cpu_mhz_average,
|
||||
min => 0, max => $entity_view->{'summary.hardware.numCpuCores'} * $entity_view->{'summary.hardware.cpuMhz'});
|
||||
$data->{$entity_value}->{'interval_min'} = $interval_min;
|
||||
$data->{$entity_value}->{'cpu.usage.average'} = $total_cpu_average;
|
||||
$data->{$entity_value}->{'cpu.usagemhz.average'} = $total_cpu_mhz_average;
|
||||
$data->{$entity_value}->{'numCpuCores'} = $entity_view->{'summary.hardware.numCpuCores'};
|
||||
$data->{$entity_value}->{'cpuMhz'} = $entity_view->{'summary.hardware.cpuMhz'};
|
||||
$data->{$entity_value}->{'cpu'} = {};
|
||||
|
||||
foreach my $id (sort { my ($cida, $cia) = split /:/, $a;
|
||||
my ($cidb, $cib) = split /:/, $b;
|
||||
@ -147,12 +94,12 @@ sub run {
|
||||
$cia <=> $cib} keys %{$values->{$entity_value}}) {
|
||||
my ($counter_id, $instance) = split /:/, $id;
|
||||
if ($instance ne "") {
|
||||
$self->{manager}->{output}->perfdata_add(label => 'cpu' . $instance . $extra_label, unit => '%',
|
||||
value => centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id}) * 0.01),
|
||||
min => 0, max => 100);
|
||||
$data->{$entity_value}->{cpu}->{$instance} = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id}) * 0.01);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,55 +38,21 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
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");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "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}->{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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::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});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
if (defined($self->{filter_description}) && $self->{filter_description} ne '') {
|
||||
$filters->{'config.annotation'} = qr/$self->{filter_description}/;
|
||||
@ -110,78 +76,36 @@ sub run {
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All cpu usages are ok"));
|
||||
}
|
||||
|
||||
my $interval_sec = $self->{connector}->{perfcounter_speriod};
|
||||
if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') {
|
||||
$interval_sec = $self->{sampling_period};
|
||||
}
|
||||
my $interval_min = centreon::vmware::common::get_interval_min(speriod => $self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift});
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::vm_state(connector => $self->{connector},
|
||||
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};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"} * 0.01));
|
||||
my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}));
|
||||
my $total_cpu_ready = centreon::vmware::common::simplify_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.ready.summation'}->{'key'} . ":"} / ($interval_sec * 1000) * 100);
|
||||
|
||||
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_' . $entry->{label}),
|
||||
min => $entry->{perf_min}, max => $entry->{perf_max});
|
||||
}
|
||||
|
||||
$long_msg .= ' on last ' . $interval_min . ' min';
|
||||
my $prefix_msg = "'$entity_view->{name}'";
|
||||
if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) &&
|
||||
$entity_view->{'config.annotation'} ne '') {
|
||||
$prefix_msg .= ' [' . centreon::vmware::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']';
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => "$prefix_msg $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 => "$prefix_msg $short_msg"
|
||||
);
|
||||
}
|
||||
if ($multiple == 0) {
|
||||
$self->{manager}->{output}->output_add(short_msg => "$prefix_msg $long_msg");
|
||||
}
|
||||
$data->{$entity_value}->{'cpu.usage.average'} = $total_cpu_average;
|
||||
$data->{$entity_value}->{'cpu.usagemhz.average'} = $total_cpu_mhz_average;
|
||||
$data->{$entity_value}->{'cpu_ready'} = $total_cpu_ready;
|
||||
$data->{$entity_value}->{'interval_min'} = $interval_min;
|
||||
$data->{$entity_value}->{'config.annotation'} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef;
|
||||
$data->{$entity_value}->{'cpu'} = {};
|
||||
|
||||
foreach my $id (sort { my ($cida, $cia) = split /:/, $a;
|
||||
my ($cidb, $cib) = split /:/, $b;
|
||||
@ -191,12 +115,12 @@ sub run {
|
||||
my ($counter_id, $instance) = split /:/, $id;
|
||||
next if ($self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{key} != $counter_id);
|
||||
if ($instance ne "") {
|
||||
$self->{manager}->{output}->perfdata_add(label => 'cpu_' . $instance . '_MHz' . $extra_label, unit => 'MHz',
|
||||
value => centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id})),
|
||||
min => 0);
|
||||
$data->{$entity_value}->{cpu}->{$instance} = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,51 +38,20 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: datastore name cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name 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;
|
||||
}
|
||||
foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) {
|
||||
if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.name', 'vm', 'summary.accessible');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
|
||||
my @vm_array = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
@ -94,20 +63,12 @@ sub run {
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@vm_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All Datastores are ok"));
|
||||
}
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{'summary.name'}, state => $entity_view->{'summary.accessible'} };
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $entity_view->{'summary.accessible'}) == 0);
|
||||
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::datastore_state(connector => $self->{connector},
|
||||
name => $entity_view->{'summary.name'},
|
||||
state => $entity_view->{'summary.accessible'},
|
||||
status => $self->{disconnect_status},
|
||||
multiple => $multiple) == 0);
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $entity_view->{'summary.name'} if ($multiple == 1);
|
||||
my %vm_states = (poweredon => 0, poweredoff => 0, suspended => 0);
|
||||
if (defined($entity_view->vm)) {
|
||||
foreach my $vm_host (@{$entity_view->vm}) {
|
||||
@ -121,30 +82,10 @@ sub run {
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $labels ((['poweredon', 'warning_on', 'critical_on'],
|
||||
['poweredoff', 'warning_off', 'critical_off'],
|
||||
['suspended', 'warning_suspended', 'critical_suspended'])) {
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $vm_states{$labels->[0]},
|
||||
threshold => [ { label => $labels->[2], exit_litteral => 'critical' },
|
||||
{ label => $labels->[1], exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' %s VM(s) %s", $entity_view->{'summary.name'},
|
||||
$vm_states{$labels->[0]},
|
||||
$labels->[0]));
|
||||
if ($multiple == 0 ||
|
||||
!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("'%s' %s VM(s) %s", $entity_view->{'summary.name'},
|
||||
$vm_states{$labels->[0]},
|
||||
$labels->[0]));
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->perfdata_add(label => $labels->[0] . $extra_label,
|
||||
value => $vm_states{$labels->[0]},
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => $labels->[1]),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => $labels->[2]),
|
||||
min => 0, max => $vm_states{poweredoff} + $vm_states{suspended} + $vm_states{poweredon});
|
||||
}
|
||||
$data->{$entity_value} = { %{$data->{$entity_value}}, %vm_states };
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -39,63 +39,30 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: esx hostname cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: datastore name cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::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});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'config.fileSystemVolume.mountInfo', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
|
||||
my %uuid_list = ();
|
||||
#my %disk_name = ();
|
||||
my $query_perfs = [];
|
||||
@ -108,12 +75,11 @@ sub run {
|
||||
$ds_regexp = qr/$self->{datastore_name}/;
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::host_state(connector => $self->{connector},
|
||||
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};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val, datastore => {} };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my $instances = [];
|
||||
foreach (@{$entity_view->{'config.fileSystemVolume.mountInfo'}}) {
|
||||
@ -147,8 +113,7 @@ sub run {
|
||||
}
|
||||
|
||||
if (scalar(@$query_perfs) == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't get a single datastore.");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Can't get a single datastore.");
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -162,8 +127,6 @@ sub run {
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All Datastore latencies are ok"));
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
@ -177,37 +140,14 @@ sub run {
|
||||
my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.totalReadLatency.average'}->{'key'} . ":" . $uuid}));
|
||||
my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $uuid}));
|
||||
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $read_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' read on '%s' is %s ms",
|
||||
$entity_view->{name}, $uuid_list{$uuid}, $read_counter));
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("'%s' read on '%s' is %s ms",
|
||||
$entity_view->{name}, $uuid_list{$uuid}, $read_counter));
|
||||
}
|
||||
$exit = $self->{manager}->{perfdata}->threshold_check(value => $write_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' write on '%s' is %s ms",
|
||||
$entity_view->{name}, $uuid_list{$uuid}, $write_counter));
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("'%s' write on '%s' is %s ms",
|
||||
$entity_view->{name}, $uuid_list{$uuid}, $write_counter));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'trl' . $extra_label . '_' . $uuid_list{$uuid}, unit => 'ms',
|
||||
value => $read_counter,
|
||||
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 => 'twl' . $extra_label . '_' . $uuid_list{$uuid}, unit => 'ms',
|
||||
value => $write_counter,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$data->{$entity_value}->{datastore}->{$uuid_list{$uuid}} = {
|
||||
'datastore.totalReadLatency.average' => $read_counter,
|
||||
'datastore.totalWriteLatency.average' => $write_counter,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,49 +38,21 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: datastore name cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::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});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.name', 'summary.accessible');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
@ -95,58 +67,22 @@ sub run {
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All datastore rates are ok"));
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::datastore_state(connector => $self->{connector},
|
||||
name => $entity_view->{'summary.name'},
|
||||
state => $entity_view->{'summary.accessible'},
|
||||
status => $self->{disconnect_status},
|
||||
multiple => $multiple) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = { name => $entity_view->{'summary.name'}, state => $entity_view->{'summary.accessible'} };
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $entity_view->{'summary.accessible'}) == 0);
|
||||
|
||||
# in KBps
|
||||
my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.read.average'}->{'key'} . ":"})) * 1024;
|
||||
my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.write.average'}->{'key'} . ":"})) * 1024;
|
||||
|
||||
my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $read_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $write_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
my ($read_value, $read_unit) = $self->{manager}->{perfdata}->change_bytes(value => $read_counter);
|
||||
my ($write_value, $write_unit) = $self->{manager}->{perfdata}->change_bytes(value => $write_counter);
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Rate of reading data: %s Rate of writing data: %s",
|
||||
$entity_view->{'summary.name'},
|
||||
$read_value . " " . $read_unit . "/s",
|
||||
$write_value . " " . $write_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' Rate of reading data: %s Rate of writing data: %s",
|
||||
$entity_view->{'summary.name'},
|
||||
$read_value . " " . $read_unit . "/s",
|
||||
$write_value . " " . $write_unit . "/s"));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $entity_view->{'summary.name'} if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'read_rate' . $extra_label, unit => 'B/s',
|
||||
value => $read_counter,
|
||||
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 => 'write_rate' . $extra_label, unit => 'B/s',
|
||||
value => $write_counter,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$data->{$entity_value}->{'datastore.read.average'} = $read_counter;
|
||||
$data->{$entity_value}->{'datastore.write.average'} = $write_counter;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,72 +38,34 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: datastore name cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::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});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.accessible', 'summary.name', 'vm', 'info');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All Datastore IOPS counters are ok"));
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
#my %uuid_list = ();
|
||||
my %disk_name = ();
|
||||
my %datastore_lun = ();
|
||||
my $ds_checked = 0;
|
||||
foreach (@$result) {
|
||||
next if (centreon::vmware::common::datastore_state(connector => $self->{connector},
|
||||
name => $_->{'summary.name'},
|
||||
state => $_->{'summary.accessible'},
|
||||
status => $self->{disconnect_status},
|
||||
multiple => $multiple) == 0);
|
||||
$data->{$_->{'summary.name'}} = { name => $_->{'summary.name'}, state => $_->{'summary.accessible'} };
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $_->{'summary.accessible'}) == 0);
|
||||
|
||||
if ($_->info->isa('VmfsDatastoreInfo')) {
|
||||
#$uuid_list{$_->volume->uuid} = $_->volume->name;
|
||||
@ -122,8 +84,7 @@ sub run {
|
||||
}
|
||||
|
||||
if ($ds_checked == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "No Vmfs datastore(s) checked. Cannot get iops from Nas datastore(s)");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "No Vmfs datastore(s) checked. Cannot get iops from Nas datastore(s)");
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -140,8 +101,7 @@ sub run {
|
||||
}
|
||||
|
||||
if (scalar(@vm_array) == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => "No virtual machines on the datastore");
|
||||
centreon::vmware::common::set_response(code => 200, short_message => "No virtual machines on the datastore");
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -160,9 +120,8 @@ sub run {
|
||||
$ref_ids_vm{${$result2}[$i]->{mo_ref}->{value}} = ${$result2}[$i]->{name};
|
||||
}
|
||||
|
||||
if ($multiple == 0 && scalar(@{$result2}) == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => "No active virtual machines on the datastore");
|
||||
if (scalar(@{$result2}) == 0) {
|
||||
centreon::vmware::common::set_response(code => 200, short_message => "No active virtual machines on the datastore");
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -200,65 +159,36 @@ sub run {
|
||||
my $total_read_counter = $datastore_lun{$_}{'disk.numberRead.summation'};
|
||||
my $total_write_counter = $datastore_lun{$_}{'disk.numberWrite.summation'};
|
||||
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $total_read_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' read iops on '%s'",
|
||||
$total_read_counter, $_));
|
||||
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' read iops on '%s'",
|
||||
$total_read_counter, $_));
|
||||
$self->vm_iops_details(label => 'disk.numberRead.summation',
|
||||
type => 'read',
|
||||
detail => $datastore_lun{$_},
|
||||
ref_vm => \%ref_ids_vm);
|
||||
}
|
||||
$exit = $self->{manager}->{perfdata}->threshold_check(value => $total_write_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("'%s' write iops on '%s'",
|
||||
$total_write_counter, $_));
|
||||
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' write iops on '%s'",
|
||||
$total_write_counter, $_));
|
||||
$self->vm_iops_details(label => 'disk.numberWrite.summation',
|
||||
type => 'write',
|
||||
detail => $datastore_lun{$_},
|
||||
ref_vm => \%ref_ids_vm)
|
||||
}
|
||||
$data->{$_}->{'disk.numberRead.summation'} = $total_read_counter;
|
||||
$data->{$_}->{'disk.numberWrite.summation'} = $total_write_counter;
|
||||
$data->{$_}->{vm} = {};
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $_ if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'riops' . $extra_label, unit => 'iops',
|
||||
value => $total_read_counter,
|
||||
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 => 'wiops' . $extra_label, unit => 'iops',
|
||||
value => $total_write_counter,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$self->vm_iops_details(label => 'disk.numberRead.summation',
|
||||
type => 'read',
|
||||
detail => $datastore_lun{$_},
|
||||
ref_vm => \%ref_ids_vm,
|
||||
data => $data);
|
||||
$self->vm_iops_details(label => 'disk.numberWrite.summation',
|
||||
type => 'write',
|
||||
detail => $datastore_lun{$_},
|
||||
ref_vm => \%ref_ids_vm,
|
||||
data_vm => $data->{$_}->{vm});
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
sub vm_iops_details {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" VM IOPs details: "));
|
||||
my $num = 0;
|
||||
foreach my $value (keys %{$options{detail}}) {
|
||||
# display only for high iops
|
||||
if ($value =~ /^vm.*?$options{label}$/ && $options{detail}->{$value} >= $self->{detail_iops_min}) {
|
||||
my ($vm_id) = split(/_/, $value);
|
||||
$num++;
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" '%s' %s iops", $options{ref_vm}->{$vm_id}, $options{detail}->{$value}));
|
||||
$options{data_vm}->{$options{ref_vm}->{$vm_id}} = {} if (!defined($options{data_vm}->{$options{ref_vm}->{$vm_id}}));
|
||||
$options{data_vm}->{$options{ref_vm}->{$vm_id}}->{$options{label}} = $options{detail}->{$value};
|
||||
}
|
||||
}
|
||||
|
||||
if ($num == 0) {
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" no vm with iops >= %s", $self->{detail_iops_min}));
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,60 +38,32 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: datastore name cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name 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;
|
||||
}
|
||||
foreach my $label (('warning_total', 'critical_total', 'warning_snapshot', 'critical_snapshot')) {
|
||||
if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning_total', 'critical_total', 'warning_snapshot', 'critical_snapshot')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.accessible', 'summary.name', 'browser');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
|
||||
my @ds_array = ();
|
||||
my %ds_names = ();
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::datastore_state(connector => $self->{connector},
|
||||
name => $entity_view->{'summary.name'},
|
||||
state => $entity_view->{'summary.accessible'},
|
||||
status => $self->{disconnect_status},
|
||||
multiple => $multiple) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{'summary.name'},
|
||||
state => $entity_view->{'summary.accessible'},
|
||||
error_message => '',
|
||||
snapshost => [],
|
||||
};
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $entity_view->{'summary.accessible'}) == 0);
|
||||
if (defined($entity_view->browser)) {
|
||||
push @ds_array, $entity_view->browser;
|
||||
$ds_names{$entity_view->{mo_ref}->{value}} = $entity_view->{'summary.name'};
|
||||
@ -102,15 +74,12 @@ sub run {
|
||||
my $result2;
|
||||
return if (!($result2 = centreon::vmware::common::get_views($self->{connector}, \@ds_array, \@properties)));
|
||||
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All snapshot sizes are ok"));
|
||||
foreach my $browse_ds (@$result2) {
|
||||
my $dsName;
|
||||
my $tmp_name = $browse_ds->{mo_ref}->{value};
|
||||
$tmp_name =~ s/^datastoreBrowser-//i;
|
||||
$dsName = $ds_names{$tmp_name};
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => "Checking datastore '$dsName':");
|
||||
my ($snapshots, $msg) = centreon::vmware::common::search_in_datastore(
|
||||
connector => $self->{connector},
|
||||
browse_ds => $browse_ds,
|
||||
@ -125,48 +94,21 @@ sub run {
|
||||
if ($msg =~ /NoPermissionFault/i) {
|
||||
$msg = "Not enough permissions";
|
||||
}
|
||||
if ($multiple == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Datastore '%s' %s", $dsName, $msg));
|
||||
}
|
||||
|
||||
$data->{$tmp_name}->{error_message} = $msg;
|
||||
next;
|
||||
}
|
||||
|
||||
my $total_size = 0;
|
||||
my $lwarn = '';
|
||||
my $lcrit = '';
|
||||
foreach (@$snapshots) {
|
||||
if (defined($_->file)) {
|
||||
foreach my $x (@{$_->file}) {
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $x->fileSize, threshold => [ { label => 'critical_snapshot', exit_litteral => 'critical' }, { label => 'warning_snapshot', exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->set_status(exit_litteral => $exit);
|
||||
my ($size_value, $size_unit) = $self->{manager}->{perfdata}->change_bytes(value => $x->fileSize);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" %s: snapshot [%s]=>[%s] [size = %s]",
|
||||
$exit, $_->folderPath, $x->path, $size_value . ' ' . $size_unit));
|
||||
$total_size += $x->fileSize;
|
||||
push @{$data->{$tmp_name}->{snapshost}}, { folder_path => $_->folderPath, path => $x->path, size => $x->fileSize };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $total_size, threshold => [ { label => 'critical_total', exit_litteral => 'critical' }, { label => 'warning_total', exit_litteral => 'warning' } ]);
|
||||
my ($size_value, $size_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_size);
|
||||
$self->{manager}->{output}->set_status(exit_litteral => $exit);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf(" %s: total snapshots [size = %s]",
|
||||
$exit, $size_value . ' ' . $size_unit));
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $dsName if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'total_size' . $extra_label, unit => 'B',
|
||||
value => $total_size,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning_total'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical_total'),
|
||||
min => 0);
|
||||
}
|
||||
|
||||
if (!$self->{manager}->{output}->is_status(compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $self->{manager}->{output}->get_litteral_status(),
|
||||
short_msg => sprintf("Snapshot sizes exceed limits"));
|
||||
}
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,43 +38,13 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: datastore name cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name 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}->{units}) || $options{arguments}->{units} !~ /^(%|B)$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong units option '" . (defined($options{arguments}->{units}) ? $options{arguments}->{units} : 'null') . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
foreach my $label (('warning', 'critical', 'warning_provisioned', 'critical_provisioned')) {
|
||||
if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning', 'critical', 'warning_provisioned', 'critical_provisioned')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
@ -85,103 +55,31 @@ sub run {
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All Datastore usages are ok"));
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::datastore_state(connector => $self->{connector},
|
||||
name => $entity_view->summary->name,
|
||||
state => $entity_view->summary->accessible,
|
||||
status => $self->{disconnect_status},
|
||||
multiple => $multiple) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = { name => $entity_view->summary->name, state => $entity_view->summary->accessible };
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $entity_view->summary->accessible) == 0);
|
||||
|
||||
# capacity 0...
|
||||
if ($entity_view->summary->capacity <= 0) {
|
||||
if ($multiple == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("datastore size is 0"));
|
||||
}
|
||||
$data->{$entity_value}->{size} = 0;
|
||||
next;
|
||||
}
|
||||
|
||||
|
||||
# in Bytes
|
||||
my $exits = [];
|
||||
my $name_storage = $entity_view->summary->name;
|
||||
my $total_size = $entity_view->summary->capacity;
|
||||
my $total_free = $entity_view->summary->freeSpace;
|
||||
my $total_used = $total_size - $total_free;
|
||||
my $prct_used = $total_used * 100 / $total_size;
|
||||
my $prct_free = 100 - $prct_used;
|
||||
$data->{$entity_value}->{size} = $entity_view->summary->capacity;
|
||||
$data->{$entity_value}->{free} = $entity_view->summary->freeSpace;
|
||||
|
||||
my ($total_uncommited, $prct_uncommited);
|
||||
my $msg_uncommited = '';
|
||||
if (defined($entity_view->summary->uncommitted)) {
|
||||
$total_uncommited = $total_used + $entity_view->summary->uncommitted;
|
||||
$prct_uncommited = $total_uncommited * 100 / $total_size;
|
||||
my ($total_uncommited_value, $total_uncommited_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_uncommited);
|
||||
$msg_uncommited = sprintf(" Provisioned: %s (%.2f%%)", $total_uncommited_value . " " . $total_uncommited_unit, $prct_uncommited);
|
||||
push @{$exits}, $self->{manager}->{perfdata}->threshold_check(value => $prct_uncommited, threshold => [ { label => 'critical_provisioned', exit_litteral => 'critical' }, { label => 'warning_provisioned', exit_litteral => 'warning' } ]);
|
||||
}
|
||||
|
||||
my ($threshold_value);
|
||||
$threshold_value = $total_used;
|
||||
$threshold_value = $total_free if (defined($self->{free}));
|
||||
if ($self->{units} eq '%') {
|
||||
$threshold_value = $prct_used;
|
||||
$threshold_value = $prct_free if (defined($self->{free}));
|
||||
}
|
||||
push @{$exits}, $self->{manager}->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{manager}->{output}->get_most_critical(status => $exits);
|
||||
|
||||
my ($total_size_value, $total_size_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_size);
|
||||
my ($total_used_value, $total_used_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_used);
|
||||
my ($total_free_value, $total_free_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_free);
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("Datastore '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)%s", $name_storage,
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $prct_used,
|
||||
$total_free_value . " " . $total_free_unit, $prct_free,
|
||||
$msg_uncommited));
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || $multiple == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Datastore '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)%s", $name_storage,
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $prct_used,
|
||||
$total_free_value . " " . $total_free_unit, $prct_free,
|
||||
$msg_uncommited));
|
||||
}
|
||||
|
||||
my $label = 'used';
|
||||
my $value_perf = $total_used;
|
||||
if (defined($self->{free})) {
|
||||
$label = 'free';
|
||||
$value_perf = $total_free;
|
||||
}
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $name_storage if ($multiple == 1);
|
||||
my %total_options = ();
|
||||
if ($self->{units} eq '%') {
|
||||
$total_options{total} = $total_size;
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
$self->{manager}->{output}->perfdata_add(label => $label . $extra_label, unit => 'B',
|
||||
value => $value_perf,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options),
|
||||
min => 0, max => $total_size);
|
||||
if (defined($total_uncommited)) {
|
||||
$self->{manager}->{output}->perfdata_add(label => 'provisioned' . $extra_label, unit => 'B',
|
||||
value => $total_uncommited,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning_provisioned', total => $total_size, cast_int => 1),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical_provisioned', total => $total_size, cast_int => 1),
|
||||
min => 0, max => $total_size);
|
||||
$data->{$entity_value}->{uncommitted} = $entity_view->summary->uncommitted;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -39,56 +39,22 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
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");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: datastore name cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name 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}->{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;
|
||||
}
|
||||
foreach my $label (('warning', 'critical', 'warning_max_total_latency', 'critical_max_total_latency')) {
|
||||
if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning', 'critical', 'warning_max_total_latency', 'critical_max_total_latency')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -105,9 +71,6 @@ sub run {
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
my $ds_regexp;
|
||||
if (defined($self->{datastore_name}) && !defined($self->{filter_datastore})) {
|
||||
$ds_regexp = qr/^\Q$self->{datastore_name}\E$/;
|
||||
@ -117,16 +80,21 @@ sub run {
|
||||
$ds_regexp = qr/$self->{datastore_name}/;
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
my $mapped_datastore = {};
|
||||
my @ds_array = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::vm_state(connector => $self->{connector},
|
||||
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};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
datastore => {},
|
||||
};
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
if (defined($entity_view->datastore)) {
|
||||
foreach (@{$entity_view->datastore}) {
|
||||
if (!defined($mapped_datastore->{$_->value})) {
|
||||
@ -173,20 +141,15 @@ sub run {
|
||||
if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') {
|
||||
$interval_sec = $self->{sampling_period};
|
||||
}
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All Datastore IOPS counters are ok"));
|
||||
|
||||
my $finded = 0;
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0 &&
|
||||
centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
my $prefix_msg = "'$entity_view->{name}'";
|
||||
if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) &&
|
||||
$entity_view->{'config.annotation'} ne '') {
|
||||
$prefix_msg .= ' [' . centreon::vmware::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']';
|
||||
}
|
||||
$data->{$entity_value}->{'config.annotation'} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef;
|
||||
|
||||
$finded |= 1;
|
||||
my %datastore_lun = ();
|
||||
foreach (keys %{$values->{$entity_value}}) {
|
||||
my ($id, $disk_name) = split /:/;
|
||||
@ -200,62 +163,21 @@ sub run {
|
||||
$datastore_lun{$disk_name{$disk_name}}->{$self->{connector}->{perfcounter_cache_reverse}->{$id}} += $values->{$entity_value}->{$_};
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $entity_view->{name} if ($multiple == 1);
|
||||
foreach (sort keys %datastore_lun) {
|
||||
$finded |= 2;
|
||||
my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($datastore_lun{$_}{'disk.numberRead.summation'} / $interval_sec));
|
||||
my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($datastore_lun{$_}{'disk.numberWrite.summation'} / $interval_sec));
|
||||
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $read_counter, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("%s read iops on '%s' is %s",
|
||||
$prefix_msg, $_, $read_counter));
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%s read iops on '%s' is %s",
|
||||
$prefix_msg, $_, $read_counter));
|
||||
}
|
||||
$exit = $self->{manager}->{perfdata}->threshold_check(value => $write_counter, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("%s write iops on '%s' is %s",
|
||||
$prefix_msg, $_, $write_counter));
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%s write iops on '%s' is %s",
|
||||
$prefix_msg, $_, $write_counter));
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->perfdata_add(label => 'riops' . $extra_label . '_' . $_, unit => 'iops',
|
||||
value => $read_counter,
|
||||
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 => 'wiops' . $extra_label . '_' . $_, unit => 'iops',
|
||||
value => $write_counter,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$data->{$entity_value}->{datastore}->{$_} = {
|
||||
'disk.numberRead.summation' => $read_counter,
|
||||
'disk.numberWrite.summation' => $write_counter,
|
||||
};
|
||||
}
|
||||
|
||||
my $max_total_latency = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'disk.maxTotalLatency.latest'}->{key} . ":"}));
|
||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $max_total_latency, threshold => [ { label => 'critical_max_total_latency', exit_litteral => 'critical' }, { label => 'warning_max_total_latency', exit_litteral => 'warning' } ]);
|
||||
$self->{manager}->{output}->output_add(long_msg => sprintf("%s max total latency is %s ms",
|
||||
$prefix_msg, $max_total_latency));
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%s max total latency is %s ms",
|
||||
$prefix_msg, $max_total_latency));
|
||||
}
|
||||
$self->{manager}->{output}->perfdata_add(label => 'max_total_latency' . $extra_label, unit => 'ms',
|
||||
value => $max_total_latency,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning_max_total_latency'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical_max_total_latency'),
|
||||
min => 0);
|
||||
$data->{$entity_value}->{'disk.maxTotalLatency.latest'} = $max_total_latency;
|
||||
}
|
||||
|
||||
if (($finded & 2) == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't get a single datastore.");
|
||||
}
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,23 +38,10 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: esx hostname cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx 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;
|
||||
}
|
||||
foreach my $label (('warning', 'critical', 'warning_state', 'critical_state')) {
|
||||
if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -64,31 +51,22 @@ sub initArgs {
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning', 'critical', 'warning_state', 'critical_state')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
centreon::vmware::common::init_response(identity => $options{arguments}->{identity});
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'summary.hardware.memorySize', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
|
||||
my $performances = [{'label' => 'mem.consumed.average', 'instances' => ['']},
|
||||
{'label' => 'mem.overhead.average', 'instances' => ['']}];
|
||||
if (!defined($self->{no_memory_state})) {
|
||||
@ -108,17 +86,13 @@ sub run {
|
||||
# 3 (low) 1%
|
||||
my %mapping_state = (0 => 'high', 1 => 'soft', 2 => 'hard', 3 => 'low');
|
||||
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All memory usages are ok"));
|
||||
}
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::host_state(connector => $self->{connector},
|
||||
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};
|
||||
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my $memory_size = $entity_view->{'summary.hardware.memorySize'}; # in B
|
||||
|
||||
# in KB
|
||||
@ -128,70 +102,14 @@ sub run {
|
||||
if (!defined($self->{no_memory_state})) {
|
||||
$mem_state = centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.state.latest'}->{'key'} . ":"});
|
||||
}
|
||||
my $mem_free = $memory_size - $mem_used;
|
||||
my $prct_used = $mem_used * 100 / $memory_size;
|
||||
my $prct_free = 100 - $prct_used;
|
||||
|
||||
my $exit1 = $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);
|
||||
|
||||
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my $output = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_value . " " . $total_unit,
|
||||
$used_value . " " . $used_unit, $prct_used,
|
||||
$free_value . " " . $free_unit, $prct_free);
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit1, compare => 'ok', litteral => 1)) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
my $exit2 = 'OK';
|
||||
if (!defined($self->{no_memory_state})) {
|
||||
$output = sprintf("Memory state : %s", $mapping_state{$mem_state});
|
||||
$exit2 = $self->{manager}->{perfdata}->threshold_check(value => $mem_state, threshold => [ { label => 'critical_state', exit_litteral => 'critical' }, { label => 'warning_state', exit_litteral => 'warning' } ]);
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
}
|
||||
|
||||
my $prefix_msg = "'$entity_view->{name}'";
|
||||
$self->{manager}->{output}->output_add(long_msg => "$prefix_msg $long_msg");
|
||||
my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
if (!$self->{manager}->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{manager}->{output}->output_add(severity => $exit,
|
||||
short_msg => "$prefix_msg $short_msg"
|
||||
);
|
||||
}
|
||||
if ($multiple == 0) {
|
||||
$self->{manager}->{output}->output_add(short_msg => "$prefix_msg $long_msg");
|
||||
}
|
||||
|
||||
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);
|
||||
if (!defined($self->{no_memory_state})) {
|
||||
$self->{manager}->{output}->perfdata_add(label => 'state' . $extra_label,
|
||||
value => $mem_state,
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning_state'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical_state'),
|
||||
min => 0, max => 3);
|
||||
}
|
||||
$data->{$entity_value}->{mem_size} = $memory_size;
|
||||
$data->{$entity_value}->{'mem.consumed.average'} = $mem_used;
|
||||
$data->{$entity_value}->{'mem.overhead.average'} = $mem_overhead;
|
||||
$data->{$entity_value}->{mem_state} = defined($mem_state) ? $mapping_state{$mem_state} : undef;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -38,62 +38,22 @@ sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: esx hostname cannot be null");
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{nic_name}) && $options{arguments}->{nic_name} eq "") {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: nic name 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}->{link_down_status}) &&
|
||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{link_down_status}) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for link down status '" . $options{arguments}->{link_down_status} . "'");
|
||||
return 1;
|
||||
}
|
||||
foreach my $label (('warning_in', 'critical_in', 'warning_out', 'critical_out',
|
||||
'warning_dropped_in', 'critical_dropped_in', 'warning_dropped_out', 'critical_dropped_out')) {
|
||||
if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) {
|
||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
$self->{manager} = centreon::vmware::common::init_response();
|
||||
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
|
||||
foreach my $label (('warning_in', 'critical_in', 'warning_out', 'critical_out',
|
||||
'warning_dropped_in', 'critical_dropped_in', 'warning_dropped_out', 'critical_dropped_out')) {
|
||||
$self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Can't retrieve perf counters");
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my ($multiple, $number_nic) = (0, 0);
|
||||
my $number_nic = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'config.network.pnic', 'runtime.connectionState', 'config.network.vswitch');
|
||||
if (!defined($self->{no_proxyswitch})) {
|
||||
@ -101,83 +61,49 @@ sub run {
|
||||
}
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
if ($multiple == 1) {
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All traffics are ok"));
|
||||
}
|
||||
|
||||
|
||||
my $data = {};
|
||||
my $pnic_def_up = {};
|
||||
my $pnic_def_down = {};
|
||||
my $query_perfs = [];
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::host_state(connector => $self->{connector},
|
||||
hostname => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
status => $self->{disconnect_status},
|
||||
multiple => $multiple) == 0);
|
||||
$pnic_def_up->{$entity_view->{mo_ref}->{value}} = {};
|
||||
$pnic_def_down->{$entity_view->{mo_ref}->{value}} = {};
|
||||
my %nic_in_vswitch = ();
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val,
|
||||
pnic => { }, vswitch => { }, proxyswitch => {} };
|
||||
next if ($entity_view->{'runtime.connectionState'}->val !~ /^connected$/i);
|
||||
|
||||
$pnic_def_up->{$entity_value} = {};
|
||||
my $instances = [];
|
||||
my $filter_ok = 0;
|
||||
|
||||
# Get Name from vswitch
|
||||
if (defined($entity_view->{'config.network.vswitch'})) {
|
||||
foreach (@{$entity_view->{'config.network.vswitch'}}) {
|
||||
$data->{$entity_value}->{vswitch}->{$_->{name}} = { pnic => [] };
|
||||
next if (!defined($_->{pnic}));
|
||||
foreach my $keynic (@{$_->{pnic}}) {
|
||||
$nic_in_vswitch{$keynic} = 1;
|
||||
}
|
||||
push @{$data->{$entity_value}->{vswitch}->{$_->{name}}->{pnic}}, @{$_->{pnic}};
|
||||
}
|
||||
}
|
||||
# Get Name from proxySwitch
|
||||
if (defined($entity_view->{'config.network.proxySwitch'})) {
|
||||
foreach (@{$entity_view->{'config.network.proxySwitch'}}) {
|
||||
$data->{$entity_value}->{proxyswitch}->{$_->{name}} = { pnic => [] };
|
||||
next if (!defined($_->{pnic}));
|
||||
foreach my $keynic (@{$_->{pnic}}) {
|
||||
$nic_in_vswitch{$keynic} = 1;
|
||||
}
|
||||
push @{$data->{$entity_value}->{proxyswitch}->{$_->{name}}->{pnic}}, @{$_->{pnic}};
|
||||
}
|
||||
}
|
||||
|
||||
foreach (@{$entity_view->{'config.network.pnic'}}) {
|
||||
# Not in vswitch. Skip
|
||||
next if (!defined($nic_in_vswitch{$_->key}));
|
||||
|
||||
# Check filter
|
||||
if (defined($self->{nic_name}) && !defined($self->{filter_nic}) && $_->device ne $self->{nic_name}) {
|
||||
next;
|
||||
} elsif (defined($self->{nic_name}) && defined($self->{filter_nic}) && $_->device !~ /$self->{nic_name}/) {
|
||||
next;
|
||||
}
|
||||
$filter_ok = 1;
|
||||
$data->{$entity_value}->{pnic}->{$_->device} = { speed => undef, status => 'down', key => $_->{key} };
|
||||
|
||||
$number_nic++;
|
||||
if (defined($_->linkSpeed)) {
|
||||
$pnic_def_up->{$entity_view->{mo_ref}->{value}}->{$_->device} = $_->linkSpeed->speedMb;
|
||||
$data->{$entity_value}->{pnic}->{$_->device}->{speed} = $_->linkSpeed->speedMb;
|
||||
$data->{$entity_value}->{pnic}->{$_->device}->{status} = 'up';
|
||||
|
||||
$pnic_def_up->{$entity_value}->{$_->device} = $_->linkSpeed->speedMb;
|
||||
push @$instances, $_->device;
|
||||
} else {
|
||||
$pnic_def_down->{$entity_view->{mo_ref}->{value}}->{$_->device} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($filter_ok == 0) {
|
||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("%s can't get physical nic with filter '%s'. (or physical nic not in a 'vswitch' or 'dvswitch'",
|
||||
$entity_view->{name}, $self->{nic_name}));
|
||||
next;
|
||||
}
|
||||
if (scalar(@$instances) == 0 &&
|
||||
($multiple == 0 || ($multiple == 1 && !$self->{manager}->{output}->is_status(value => $self->{link_down_status}, compare => 'ok', litteral => 1)))) {
|
||||
$self->{manager}->{output}->output_add(severity => $self->{link_down_status},
|
||||
short_msg => sprintf("%s Link(s) '%s' is/are down",
|
||||
$entity_view->{name}, join("', '", keys %{$pnic_def_down->{$entity_view->{mo_ref}->{value}}})));
|
||||
next;
|
||||
}
|
||||
|
||||
|
||||
push @$query_perfs, {
|
||||
entity => $entity_view,
|
||||
metrics => [
|
||||
@ -204,106 +130,26 @@ sub run {
|
||||
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
if (scalar(keys %{$pnic_def_down->{$entity_value}}) > 0 &&
|
||||
(($multiple == 0 && $number_nic == 1) || !$self->{manager}->{output}->is_status(value => $self->{link_down_status}, compare => 'ok', litteral => 1))) {
|
||||
($number_nic == 1) ? my $be = "is" : my $be = "are";
|
||||
$self->{manager}->{output}->output_add(severity => $self->{link_down_status},
|
||||
short_msg => sprintf("%s Link(s) '%s' %s down",
|
||||
$entity_view->{name}, join("', '", keys %{$pnic_def_down->{$entity_value}}), $be));
|
||||
}
|
||||
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my @exits;
|
||||
foreach (sort keys %{$pnic_def_up->{$entity_value}}) {
|
||||
my $interface = sprintf("Interface '%s'", $_);
|
||||
my $output = '';
|
||||
|
||||
foreach (sort keys %{$pnic_def_up->{$entity_value}}) {
|
||||
# KBps
|
||||
my $traffic_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.received.average'}->{key} . ":" . $_})) * 1024 * 8;
|
||||
my $traffic_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.transmitted.average'}->{key} . ":" . $_})) * 1024 * 8;
|
||||
my $interface_speed = $pnic_def_up->{$entity_value}->{$_} * 1024 * 1024;
|
||||
my $in_prct = $traffic_in * 100 / $interface_speed;
|
||||
my $out_prct = $traffic_out * 100 / $interface_speed;
|
||||
|
||||
my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical_in', exit_litteral => 'critical' }, { label => 'warning_in', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical_out', exit_litteral => 'critical' }, { label => 'warning_out', exit_litteral => 'warning' } ]);
|
||||
|
||||
my ($in_value, $in_unit) = $self->{manager}->{perfdata}->change_bytes(value => $traffic_in, network => 1);
|
||||
my ($out_value, $out_unit) = $self->{manager}->{perfdata}->change_bytes(value => $traffic_out, network => 1);
|
||||
my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
push @exits, $exit;
|
||||
|
||||
$output = sprintf("Traffic In : %s/s (%.2f %%), Out : %s/s (%.2f %%)",
|
||||
$in_value . $in_unit, $in_prct,
|
||||
$out_value . $out_unit, $out_prct);
|
||||
$long_msg .= $long_msg_append . $interface . " " . $output;
|
||||
$long_msg_append = ', ';
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || ($multiple == 0 && $number_nic == 1)) {
|
||||
$short_msg .= $short_msg_append . $interface . " " . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label .= '_' . $_ if ($number_nic > 1);
|
||||
$extra_label .= '_' . $entity_view->{name} if ($multiple == 1);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'traffic_in' . $extra_label, unit => 'b/s',
|
||||
value => sprintf("%.2f", $traffic_in),
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed),
|
||||
min => 0, max => $interface_speed);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'traffic_out' . $extra_label, unit => 'b/s',
|
||||
value => sprintf("%.2f", $traffic_out),
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $interface_speed),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $interface_speed),
|
||||
min => 0, max => $interface_speed);
|
||||
|
||||
# Packets dropped
|
||||
my $packets_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.packetsRx.summation'}->{key} . ":" . $_}));
|
||||
my $packets_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.packetsTx.summation'}->{key} . ":" . $_}));
|
||||
my $dropped_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.droppedRx.summation'}->{key} . ":" . $_}));
|
||||
my $dropped_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.droppedTx.summation'}->{key} . ":" . $_}));
|
||||
my $dropped_in_prct = ($packets_in > 0) ? $dropped_in * 100 / $packets_in : 0;
|
||||
my $dropped_out_prct = ($packets_out > 0) ? $dropped_out * 100 / $packets_out : 0;
|
||||
|
||||
my $exit3 = $self->{manager}->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical_dropped_in', exit_litteral => 'critical' }, { label => 'warning_dropped_in', exit_litteral => 'warning' } ]);
|
||||
my $exit4 = $self->{manager}->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical_dropped_out', exit_litteral => 'critical' }, { label => 'warning_dropped_out', exit_litteral => 'warning' } ]);
|
||||
|
||||
my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit3, $exit4 ]);
|
||||
push @exits, $exit;
|
||||
|
||||
$output = sprintf("Packets In Dropped : %.2f %% (%d/%d packets), Packets Out Dropped : %.2f %% (%d/%d packets)",
|
||||
$dropped_in_prct, $dropped_in, $packets_in,
|
||||
$dropped_out_prct, $dropped_out, $packets_out);
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || ($multiple == 0 && $number_nic == 1)) {
|
||||
$short_msg .= $short_msg_append . $interface . " " . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->perfdata_add(label => 'packets_dropped_in' . $extra_label, unit => '%',
|
||||
value => sprintf("%.2f", $dropped_in_prct),
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning-dropped-in'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical-dropped-in'),
|
||||
min => 0, max => 100);
|
||||
$self->{manager}->{output}->perfdata_add(label => 'packets_dropped_out' . $extra_label, unit => '%',
|
||||
value => sprintf("%.2f", $dropped_out_prct),
|
||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning-dropped-out'),
|
||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical-dropped-out'),
|
||||
min => 0, max => 100);
|
||||
}
|
||||
|
||||
$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");
|
||||
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.received.average'} = $traffic_in;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.transmitted.average'} = $traffic_out;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.packetsRx.summation'} = $packets_in;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.packetsTx.summation'} = $packets_out;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.droppedRx.summation'} = $dropped_in;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.droppedTx.summation'} = $dropped_out;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -25,36 +25,49 @@ use VMware::VIRuntime;
|
||||
use VMware::VILib;
|
||||
use ZMQ::LibZMQ4;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use centreon::plugins::options;
|
||||
use centreon::plugins::output;
|
||||
use centreon::plugins::perfdata;
|
||||
use JSON;
|
||||
|
||||
my $manager_display = {};
|
||||
my $manager_response = {};
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
|
||||
sub init_response {
|
||||
$manager_display->{options} = centreon::plugins::options->new();
|
||||
$manager_display->{output} = centreon::plugins::output->new(options => $manager_display->{options});
|
||||
$manager_display->{perfdata} = centreon::plugins::perfdata->new(output => $manager_display->{output});
|
||||
sub set_response {
|
||||
my (%options) = @_;
|
||||
|
||||
return $manager_display;
|
||||
$manager_response->{code} = $options{code} if (defined($options{code}));
|
||||
$manager_response->{short_message} = $options{short_message} if (defined($options{short_message}));
|
||||
$manager_response->{extra_message} = $options{extra_message} if (defined($options{extra_message}));
|
||||
$manager_response->{identity} = $options{identity} if (defined($options{identity}));
|
||||
$manager_response->{data} = $options{data} if (defined($options{data}));
|
||||
}
|
||||
|
||||
sub init_response {
|
||||
my (%options) = @_;
|
||||
|
||||
$manager_response->{code} = 0;
|
||||
$manager_response->{short_message} = 'OK';
|
||||
$manager_response->{extra_message} = '';
|
||||
$manager_response->{identity} = $options{identity} if (defined($options{identity}));
|
||||
$manager_response->{data} = {};
|
||||
}
|
||||
|
||||
sub free_response {
|
||||
$manager_display = {};
|
||||
$manager_response = {};
|
||||
}
|
||||
|
||||
sub response {
|
||||
my (%options) = @_;
|
||||
|
||||
my $stdout = '';
|
||||
if (!defined($options{stdout})) {
|
||||
local *STDOUT;
|
||||
$manager_display->{output}->{option_results}->{output_json} = 1;
|
||||
open STDOUT, '>', \$stdout;
|
||||
$manager_display->{output}->display(force_long_output => 1, nolabel => 1);
|
||||
my $response_str = '';
|
||||
if (defined($options{force_response})) {
|
||||
$response_str = $options{force_response};
|
||||
} else {
|
||||
$stdout = $options{stdout};
|
||||
eval {
|
||||
$response_str = JSON->new->utf8->encode($manager_response);
|
||||
};
|
||||
if ($@) {
|
||||
$response_str = '{ "code": -1, "short_message": "Cannot encode result" }';
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($options{reinit})) {
|
||||
@ -70,7 +83,7 @@ sub response {
|
||||
zmq_msg_send($msg, $options{endpoint}, $flag);
|
||||
zmq_msg_close($msg);
|
||||
}
|
||||
my $msg = zmq_msg_init_data($options{token} . " " . $stdout);
|
||||
my $msg = zmq_msg_init_data($options{token} . " " . $response_str);
|
||||
zmq_msg_send($msg, $options{endpoint}, ZMQ_NOBLOCK);
|
||||
zmq_msg_close($msg);
|
||||
}
|
||||
@ -78,14 +91,12 @@ sub response {
|
||||
sub vmware_error {
|
||||
my ($obj_vmware, $lerror) = @_;
|
||||
|
||||
$manager_display->{output}->output_add(long_msg => $lerror);
|
||||
set_response(extra_message => $lerror);
|
||||
$obj_vmware->{logger}->writeLogError("'" . $obj_vmware->{whoaim} . "' $lerror");
|
||||
if ($lerror =~ /NoPermissionFault/i) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'VMWare error: not enought permissions');
|
||||
set_response(code => -1, short_message => 'VMWare error: not enought permissions');
|
||||
} else {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'VMWare error (verbose mode for more details)');
|
||||
set_response(code => -1, short_message => 'VMWare error (verbose mode for more details)');
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
@ -220,11 +231,11 @@ sub get_perf_metric_ids {
|
||||
foreach (@{$options{metrics}}) {
|
||||
if (defined($options{connector}->{perfcounter_cache}->{$_->{label}})) {
|
||||
if ($options{interval} != 20 && $options{connector}->{perfcounter_cache}->{$_->{label}}{level} > $options{connector}->{sampling_periods}->{$options{interval}}->{level}) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get counter '%s' for the sampling period '%s' (counter level: %s, sampling level: %s)",
|
||||
$_->{label}, $options{interval},
|
||||
$options{connector}->{perfcounter_cache}->{$_->{label}}{level},
|
||||
$options{connector}->{sampling_periods}->{$options{interval}}->{level}));
|
||||
set_response(code => -1,
|
||||
short_message => sprintf("Cannot get counter '%s' for the sampling period '%s' (counter level: %s, sampling level: %s)",
|
||||
$_->{label}, $options{interval},
|
||||
$options{connector}->{perfcounter_cache}->{$_->{label}}{level},
|
||||
$options{connector}->{sampling_periods}->{$options{interval}}->{level}));
|
||||
return undef;
|
||||
}
|
||||
foreach my $instance (@{$_->{instances}}) {
|
||||
@ -234,8 +245,7 @@ sub get_perf_metric_ids {
|
||||
}
|
||||
} else {
|
||||
$options{connector}->{logger}->writeLogError("Metric '" . $_->{label} . "' unavailable.");
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Counter doesn't exist. VMware version can be too old.");
|
||||
set_response(code => -1, short_message => "Counter doesn't exist. VMware version can be too old.");
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
@ -337,13 +347,11 @@ sub generic_performance_values_historic {
|
||||
}
|
||||
# check sampling period exist (period 20 is not listed)
|
||||
if ($interval != 20 && !defined($obj_vmware->{sampling_periods}->{$interval})) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Sampling period '%s' not managed.", $interval));
|
||||
set_response(code => -1, short_message => sprintf("Sampling period '%s' not managed.", $interval));
|
||||
return undef;
|
||||
}
|
||||
if ($interval != 20 && $obj_vmware->{sampling_periods}->{$interval}->{enabled} != 1) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Sampling period '%s' collection data no enabled.", $interval));
|
||||
set_response(code => -1, short_message => sprintf("Sampling period '%s' collection data no enabled.", $interval));
|
||||
return undef;
|
||||
}
|
||||
eval {
|
||||
@ -362,8 +370,7 @@ sub generic_performance_values_historic {
|
||||
return undef if (!defined($perfdata));
|
||||
|
||||
if (!$$perfdata[0] || !defined($$perfdata[0]->value)) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot get value for counters (Maybe, object(s) cannot be reached: disconnected, not running, time not synced (see time-host mode),...)');
|
||||
set_response(code => -1, short_message => 'Cannot get value for counters (Maybe, object(s) cannot be reached: disconnected, not running, time not synced (see time-host mode),...)');
|
||||
return undef;
|
||||
}
|
||||
foreach my $val (@$perfdata) {
|
||||
@ -372,8 +379,7 @@ sub generic_performance_values_historic {
|
||||
$results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = undef;
|
||||
next;
|
||||
} elsif (!defined($_->value)) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot get value for counters. Maybe there is time sync problem (check the esxd server and the target also)');
|
||||
set_response(code => -1, short_message => 'Cannot get value for counters. Maybe there is time sync problem (check the esxd server and the target also)');
|
||||
return undef;
|
||||
}
|
||||
|
||||
@ -400,9 +406,8 @@ sub generic_performance_values_historic {
|
||||
};
|
||||
if ($@) {
|
||||
if ($@ =~ /querySpec.interval.*InvalidArgumentFault/msi) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Interval '%s' is surely not supported for the managed entity (caller: %s)",
|
||||
$interval, join('--', caller)));
|
||||
set_response(code => -1, short_message => sprintf("Interval '%s' is surely not supported for the managed entity (caller: %s)",
|
||||
$interval, join('--', caller)));
|
||||
} else {
|
||||
$obj_vmware->{logger}->writeLogError("'" . $obj_vmware->{whoaim} . "' $@");
|
||||
}
|
||||
@ -463,8 +468,7 @@ sub search_entities {
|
||||
}
|
||||
|
||||
if (scalar(@$temp_views) == 0) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Cannot find '$$scope[1]' object");
|
||||
set_response(code => 1, short_message => "Cannot find '$$scope[1]' object");
|
||||
return undef;
|
||||
}
|
||||
push @$begin_views, @$temp_views;
|
||||
@ -487,8 +491,7 @@ sub search_entities {
|
||||
push @$results, @$views;
|
||||
}
|
||||
if (scalar(@$results) == 0) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Cannot find '$options{view_type}' object");
|
||||
set_response(code => 1, short_message => "Cannot find '$options{view_type}' object");
|
||||
return undef;
|
||||
}
|
||||
return $results;
|
||||
@ -526,8 +529,7 @@ sub find_entity_views {
|
||||
if (!defined($entity_views) || scalar(@$entity_views) == 0) {
|
||||
my $status = 0;
|
||||
if (!defined($options{output_message}) || $options{output_message} != 0) {
|
||||
$manager_display->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Cannot find '$options{view_type}' object");
|
||||
set_response(code => 1, short_message => "Cannot find '$options{view_type}' object");
|
||||
}
|
||||
return (0, undef);
|
||||
}
|
||||
@ -684,18 +686,11 @@ sub strip_cr {
|
||||
sub stats_info {
|
||||
my (%options) = @_;
|
||||
|
||||
my $total = 0;
|
||||
my $data = {};
|
||||
foreach my $container (keys %{$options{counters}}) {
|
||||
$total += $options{counters}->{$container};
|
||||
$options{manager}->{output}->perfdata_add(label => 'c[requests_' . $container . ']',
|
||||
value => $options{counters}->{$container},
|
||||
min => 0);
|
||||
$data->{$container} = { requests => $options{counters}->{$container} };
|
||||
}
|
||||
$options{manager}->{output}->perfdata_add(label => 'c[requests]',
|
||||
value => $total,
|
||||
min => 0);
|
||||
$options{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("'%s' total requests", $total));
|
||||
set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -125,10 +125,8 @@ sub handle_CHLD {
|
||||
sub response_router {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $manager = centreon::vmware::common::init_response();
|
||||
$manager->{output}->output_add(severity => $options{severity},
|
||||
short_msg => $options{msg});
|
||||
$manager->{output}->{plugin} = $options{identity};
|
||||
centreon::vmware::common::init_response(identity => $options{identity});
|
||||
centreon::vmware::common::set_response(code => $options{code}, short_message => $options{msg});
|
||||
centreon::vmware::common::response(token => 'RESPSERVER2', endpoint => $backend);
|
||||
centreon::vmware::common::free_response();
|
||||
}
|
||||
@ -144,7 +142,7 @@ sub verify_child {
|
||||
delete $self->{return_child}->{$self->{child_proc}->{$_}->{pid}};
|
||||
delete $self->{child_proc}->{$_};
|
||||
} elsif (time() - $self->{child_proc}->{$_}->{ctime} > $self->{config_child_timeout}) {
|
||||
$self->response_router(severity => 'UNKNOWN', msg => 'Timeout process',
|
||||
$self->response_router(code => -1, msg => 'Timeout process',
|
||||
identity => $_);
|
||||
kill('INT', $self->{child_proc}->{$_}->{pid});
|
||||
delete $self->{child_proc}->{$_};
|
||||
@ -191,7 +189,7 @@ sub reqclient {
|
||||
exit(0);
|
||||
}
|
||||
} else {
|
||||
$self->response_router(severity => 'UNKNOWN', msg => 'Container connection problem',
|
||||
$self->response_router(code => -1, msg => 'Container connection problem',
|
||||
identity => $result->{identity});
|
||||
}
|
||||
}
|
||||
@ -228,7 +226,7 @@ sub run {
|
||||
zmq_setsockopt($backend, ZMQ_IDENTITY, "server-" . $connector->{whoaim});
|
||||
zmq_setsockopt($backend, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($backend, 'ipc:///tmp/centreon_vmware/routing.ipc');
|
||||
centreon::vmware::common::response(token => 'READY', endpoint => $backend, stdout => '');
|
||||
centreon::vmware::common::response(token => 'READY', endpoint => $backend, force_response => '');
|
||||
|
||||
# Initialize poll set
|
||||
my @poll = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user