mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-29 16:45:04 +02:00
WIP: new version centreon-vmware 3.0.0
This commit is contained in:
parent
6c35fdb854
commit
fbe1d897e9
@ -54,7 +54,7 @@ BEGIN {
|
|||||||
use base qw(centreon::script);
|
use base qw(centreon::script);
|
||||||
use vars qw(%centreon_vmware_config);
|
use vars qw(%centreon_vmware_config);
|
||||||
|
|
||||||
my $VERSION = "2.4.0";
|
my $VERSION = "3.0.0";
|
||||||
my %handlers = (TERM => {}, HUP => {}, CHLD => {});
|
my %handlers = (TERM => {}, HUP => {}, CHLD => {});
|
||||||
|
|
||||||
my @load_modules = (
|
my @load_modules = (
|
||||||
|
@ -91,6 +91,7 @@ sub run {
|
|||||||
name => $entity_view->{name},
|
name => $entity_view->{name},
|
||||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||||
|
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||||
};
|
};
|
||||||
|
|
||||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||||
@ -104,7 +105,6 @@ sub run {
|
|||||||
$data->{$entity_value}->{'cpu.usagemhz.average'} = $total_cpu_mhz_average;
|
$data->{$entity_value}->{'cpu.usagemhz.average'} = $total_cpu_mhz_average;
|
||||||
$data->{$entity_value}->{'cpu_ready'} = $total_cpu_ready;
|
$data->{$entity_value}->{'cpu_ready'} = $total_cpu_ready;
|
||||||
$data->{$entity_value}->{'interval_min'} = $interval_min;
|
$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'} = {};
|
$data->{$entity_value}->{'cpu'} = {};
|
||||||
|
|
||||||
foreach my $id (sort { my ($cida, $cia) = split /:/, $a;
|
foreach my $id (sort { my ($cida, $cia) = split /:/, $a;
|
||||||
|
@ -90,6 +90,7 @@ sub run {
|
|||||||
name => $entity_view->{name},
|
name => $entity_view->{name},
|
||||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||||
|
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||||
datastore => {},
|
datastore => {},
|
||||||
};
|
};
|
||||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||||
@ -148,7 +149,6 @@ sub run {
|
|||||||
|
|
||||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0 &&
|
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);
|
centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||||
$data->{$entity_value}->{'config.annotation'} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef;
|
|
||||||
|
|
||||||
my %datastore_lun = ();
|
my %datastore_lun = ();
|
||||||
foreach (keys %{$values->{$entity_value}}) {
|
foreach (keys %{$values->{$entity_value}}) {
|
||||||
|
@ -30,7 +30,6 @@ sub new {
|
|||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{commandName} = 'devicevm';
|
$self->{commandName} = 'devicevm';
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,57 +37,21 @@ sub checkArgs {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||||
short_msg => "Argument error: vm hostname cannot be null");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (defined($options{arguments}->{disconnect_status}) &&
|
|
||||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{disconnect_status}) == 0) {
|
|
||||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
|
||||||
short_msg => "Argument error: wrong value for disconnect status '" . $options{arguments}->{disconnect_status} . "'");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (defined($options{arguments}->{nopoweredon_status}) &&
|
|
||||||
$options{manager}->{output}->is_litteral_status(status => $options{arguments}->{nopoweredon_status}) == 0) {
|
|
||||||
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
|
|
||||||
short_msg => "Argument error: wrong value for nopoweredon status '" . $options{arguments}->{nopoweredon_status} . "'");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (($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 {
|
return 0;
|
||||||
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});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||||
short_msg => "Can't retrieve perf counters");
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $multiple = 0;
|
|
||||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||||
if (defined($self->{filter_description}) && $self->{filter_description} ne '') {
|
if (defined($self->{filter_description}) && $self->{filter_description} ne '') {
|
||||||
$filters->{'config.annotation'} = qr/$self->{filter_description}/;
|
$filters->{'config.annotation'} = qr/$self->{filter_description}/;
|
||||||
@ -102,44 +65,32 @@ sub run {
|
|||||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||||
return if (!defined($result));
|
return if (!defined($result));
|
||||||
|
|
||||||
if (scalar(@$result) > 1) {
|
my $data = {};
|
||||||
$multiple = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $total_device_connected = 0;
|
my $total_device_connected = 0;
|
||||||
foreach my $entity_view (@$result) {
|
foreach my $entity_view (@$result) {
|
||||||
next if (centreon::vmware::common::vm_state(connector => $self->{connector},
|
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||||
hostname => $entity_view->{name},
|
|
||||||
state => $entity_view->{'runtime.connectionState'}->val,
|
$data->{$entity_value} = {
|
||||||
power => $entity_view->{'runtime.powerState'}->val,
|
name => $entity_view->{name},
|
||||||
status => $self->{disconnect_status},
|
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||||
powerstatus => $self->{nopoweredon_status},
|
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||||
multiple => $multiple) == 0);
|
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||||
|
total_device_connected => 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
foreach my $dev (@{$entity_view->{'config.hardware.device'}}) {
|
foreach my $dev (@{$entity_view->{'config.hardware.device'}}) {
|
||||||
if (ref($dev) =~ /$self->{device}/) {
|
if (ref($dev) =~ /$self->{device}/) {
|
||||||
if ($dev->connectable->connected == 1) {
|
if ($dev->connectable->connected == 1) {
|
||||||
my $prefix_msg = "'$entity_view->{name}'";
|
$data->{$entity_value}->{total_device_connected}++;
|
||||||
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 => sprintf("%s device connected",
|
|
||||||
$prefix_msg));
|
|
||||||
$total_device_connected++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $exit = $self->{manager}->{perfdata}->threshold_check(value => $total_device_connected, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
centreon::vmware::common::set_response(data => $data);
|
||||||
$self->{manager}->{output}->output_add(severity => $exit,
|
|
||||||
short_msg => sprintf("%s %s device connected", $total_device_connected, $self->{device}));
|
|
||||||
$self->{manager}->{output}->perfdata_add(label => 'connected',
|
|
||||||
value => $total_device_connected,
|
|
||||||
warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
|
||||||
critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
|
||||||
min => 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -23,7 +23,6 @@ use base qw(centreon::vmware::cmdbase);
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use centreon::vmware::common;
|
use centreon::vmware::common;
|
||||||
use JSON::XS;
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -41,16 +40,6 @@ sub checkArgs {
|
|||||||
return 0;
|
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};
|
|
||||||
}
|
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
@ -147,17 +136,8 @@ sub run {
|
|||||||
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
|
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
|
||||||
$disco_stats->{discovered_items} = @disco_data;
|
$disco_stats->{discovered_items} = @disco_data;
|
||||||
$disco_stats->{results} = \@disco_data;
|
$disco_stats->{results} = \@disco_data;
|
||||||
|
|
||||||
my $encoded_data;
|
|
||||||
eval {
|
|
||||||
$encoded_data = encode_json($disco_stats);
|
|
||||||
};
|
|
||||||
if ($@) {
|
|
||||||
$encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}';
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{manager}->{output}->output_add(short_msg => $encoded_data);
|
centreon::vmware::common::set_response(data => $disco_stats);
|
||||||
$self->{manager}->{output}->display(nolabel => 1, force_ignore_perfdata => 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -25,7 +25,7 @@ use VMware::VIRuntime;
|
|||||||
use VMware::VILib;
|
use VMware::VILib;
|
||||||
use ZMQ::LibZMQ4;
|
use ZMQ::LibZMQ4;
|
||||||
use ZMQ::Constants qw(:all);
|
use ZMQ::Constants qw(:all);
|
||||||
use JSON;
|
use JSON::XS;;
|
||||||
|
|
||||||
my $manager_display = {};
|
my $manager_display = {};
|
||||||
my $manager_response = {};
|
my $manager_response = {};
|
||||||
@ -63,7 +63,7 @@ sub response {
|
|||||||
$response_str = $options{force_response};
|
$response_str = $options{force_response};
|
||||||
} else {
|
} else {
|
||||||
eval {
|
eval {
|
||||||
$response_str = JSON->new->utf8->encode($manager_response);
|
$response_str = JSON::XS->new->utf8->encode($manager_response);
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$response_str = '{ "code": -1, "short_message": "Cannot encode result" }';
|
$response_str = '{ "code": -1, "short_message": "Cannot encode result" }';
|
||||||
|
@ -21,7 +21,7 @@ package centreon::vmware::connector;
|
|||||||
use strict;
|
use strict;
|
||||||
use VMware::VIRuntime;
|
use VMware::VIRuntime;
|
||||||
use VMware::VILib;
|
use VMware::VILib;
|
||||||
use JSON;
|
use JSON::XS;
|
||||||
use ZMQ::LibZMQ4;
|
use ZMQ::LibZMQ4;
|
||||||
use ZMQ::Constants qw(:all);
|
use ZMQ::Constants qw(:all);
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
@ -167,7 +167,7 @@ sub reqclient {
|
|||||||
|
|
||||||
my $result;
|
my $result;
|
||||||
eval {
|
eval {
|
||||||
$result = JSON->new->utf8->decode($options{data});
|
$result = JSON::XS->new->utf8->decode($options{data});
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->{logger}->writeLogError("Cannot decode JSON: $@ (options{data}");
|
$self->{logger}->writeLogError("Cannot decode JSON: $@ (options{data}");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user