+ Refactoring vmware connector client code
This commit is contained in:
parent
6280f4b5e7
commit
10c88e2334
|
@ -0,0 +1,289 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# permission to link this program with independent modules to produce an executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS also meet, for each linked independent module, the terms and conditions
|
||||
# of the license of that module. An independent module is a module which is not
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
# exception to your version of the program, but you are not obliged to do so. If you
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
# For more information : contact@centreon.com
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::vmware::connector::custom::connector;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use JSON;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
# $options{options} = options object
|
||||
# $options{output} = output object
|
||||
# $options{exit_value} = integer
|
||||
# $options{noptions} = integer
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class Custom: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s@" => { name => 'connector_hostname' },
|
||||
"connector-port:s@" => { name => 'connector_port' },
|
||||
"container:s@" => { name => 'container' },
|
||||
"timeout:s@" => { name => 'timeout' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'CONNECTOR OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
# Method to manage multiples
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
# options{options_result}
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
# Method to manage multiples
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
# options{default}
|
||||
|
||||
# Manage default value
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
# return 1 = ok still hostname
|
||||
# return 0 = no hostname left
|
||||
|
||||
$self->{connector_hostname} = (defined($self->{option_results}->{connector_hostname})) ? shift(@{$self->{option_results}->{connector_hostname}}) : undef;
|
||||
$self->{connector_port} = (defined($self->{option_results}->{connector_port})) ? shift(@{$self->{option_results}->{connector_port}}) : 5700;
|
||||
$self->{container} = (defined($self->{option_results}->{container})) ? shift(@{$self->{option_results}->{container}}) : 'default';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : undef;
|
||||
|
||||
if (!defined($self->{connector_hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{timeout}) && $self->{timeout} =~ /^\d+$/ &&
|
||||
$self->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if (!defined($self->{connector_hostname}) ||
|
||||
scalar(@{$self->{option_results}->{connector_hostname}}) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub set_discovery {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{discovery} = 1;
|
||||
}
|
||||
|
||||
sub add_params {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{command} = $options{command} if (defined($options{command}));
|
||||
foreach (keys %{$options{params}}) {
|
||||
$self->{json_send}->{$_} = $options{params}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub connector_response {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($options{response})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot read response: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $data = zmq_msg_data($options{response});
|
||||
if ($data !~ /^RESPSERVER (.*)/msi) {
|
||||
$self->{output}->add_option_msg(short_msg => "Response not formatted: $data");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $json = $1;
|
||||
my $result;
|
||||
|
||||
eval {
|
||||
$result = JSON->new->utf8->decode($json);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json result: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
foreach my $output (@{$result->{plugin}->{outputs}}) {
|
||||
if ($output->{type} == 1) {
|
||||
$self->{output}->output_add(severity => $output->{exit},
|
||||
short_msg => $output->{msg});
|
||||
} elsif ($output->{type} == 2) {
|
||||
$self->{output}->output_add(long_msg => $output->{msg});
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $perf (@{$result->{plugin}->{perfdatas}}) {
|
||||
$self->{output}->perfdata_add(label => $perf->{label}, unit => $perf->{unit},
|
||||
value => $perf->{value},
|
||||
warning => $perf->{warning},
|
||||
critical => $perf->{critical},
|
||||
min => $perf->{min}, max => $perf->{max});
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
# Build request
|
||||
my $uuid;
|
||||
UUID::generate($uuid);
|
||||
$self->{uuid} = $uuid;
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $self->{uuid});
|
||||
$self->{json_send}->{connector_hostname} = $self->{connector_hostname};
|
||||
$self->{json_send}->{connector_port} = $self->{connector_port};
|
||||
$self->{json_send}->{container} = $self->{container};
|
||||
|
||||
# Init
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $self->{uuid});
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{connector_hostname} . ':' . $self->{connector_port});
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
$self->connector_response(response => $response);
|
||||
# We need to remove xml output
|
||||
if (defined($self->{output}->{option_results}->{output_xml})) {
|
||||
delete $self->{output}->{option_results}->{output_xml};
|
||||
}
|
||||
if (!defined($self->{discovery})) {
|
||||
$self->{output}->display();
|
||||
} else {
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
}
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
VMWare connector library
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
my vmware connector
|
||||
|
||||
=head1 CONNECTOR OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
|
@ -1,86 +0,0 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# permission to link this program with independent modules to produce an timeelapsedutable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS also meet, for each linked independent module, the terms and conditions
|
||||
# of the license of that module. An independent module is a module which is not
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
# exception to your version of the program, but you are not obliged to do so. If you
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
# For more information : contact@centreon.com
|
||||
# Author : Simon BOMM <sbomm@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::vmware::connector::lib::common;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use JSON;
|
||||
use ZMQ::LibZMQ3;
|
||||
|
||||
sub connector_response {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($options{response})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot read response: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $data = zmq_msg_data($options{response});
|
||||
if ($data !~ /^RESPSERVER (.*)/msi) {
|
||||
$self->{output}->add_option_msg(short_msg => "Response not formatted: $data");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $json = $1;
|
||||
my $result;
|
||||
|
||||
eval {
|
||||
$result = JSON->new->utf8->decode($json);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json result: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
foreach my $output (@{$result->{plugin}->{outputs}}) {
|
||||
if ($output->{type} == 1) {
|
||||
$self->{output}->output_add(severity => $output->{exit},
|
||||
short_msg => $output->{msg});
|
||||
} elsif ($output->{type} == 2) {
|
||||
$self->{output}->output_add(long_msg => $output->{msg});
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $perf (@{$result->{plugin}->{perfdatas}}) {
|
||||
$self->{output}->perfdata_add(label => $perf->{label}, unit => $perf->{unit},
|
||||
value => $perf->{value},
|
||||
warning => $perf->{warning},
|
||||
critical => $perf->{critical},
|
||||
min => $perf->{min}, max => $perf->{max});
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,10 +47,7 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
|
@ -64,27 +57,13 @@ sub new {
|
|||
"critical-off:s" => { name => 'critical_off' },
|
||||
"warning-suspended:s" => { name => 'warning_suspended' },
|
||||
"critical-suspended:s" => { name => 'critical_suspended' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) {
|
||||
|
@ -101,58 +80,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'countvmhost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'countvmhost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -165,18 +99,6 @@ Check number of vm running/off on ESX hosts.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -190,10 +112,6 @@ ESX hostname is a regexp.
|
|||
|
||||
Status if ESX host disconnected (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning-on>
|
||||
|
||||
Threshold warning for 'poweredOn' vms.
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,35 +48,18 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
|
@ -96,58 +75,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'cpuhost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'cpuhost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -160,18 +94,6 @@ Check ESX cpu usage.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -185,10 +107,6 @@ ESX hostname is a regexp.
|
|||
|
||||
Status if ESX host disconnected (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in percent.
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,10 +47,7 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"vm-hostname:s" => { name => 'vm_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
|
@ -65,27 +58,13 @@ sub new {
|
|||
"critical-usage:s" => { name => 'critical_usage' },
|
||||
"warning-ready:s" => { name => 'warning_ready' },
|
||||
"critical-ready:s" => { name => 'critical_ready' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
foreach my $label (('warning_usagemhz', 'critical_usagemhz', 'warning_usage', 'critical_usage', 'warning_ready', 'critical_ready')) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) {
|
||||
|
@ -106,58 +85,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'cpuvm';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'cpuvm');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -170,18 +104,6 @@ Check virtual machine cpu usage.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--vm-hostname>
|
||||
|
||||
VM hostname to check.
|
||||
|
@ -199,10 +121,6 @@ Status if VM disconnected (default: 'unknown').
|
|||
|
||||
Status if VM is not poweredOn (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning-usagemhz>
|
||||
|
||||
Threshold warning in mhz.
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,88 +47,27 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
"vm-no" => { name => 'vm_no' },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'getmap';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->set_discovery();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'getmap');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -145,18 +80,6 @@ List ESX hosts and Virtual machines.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to list.
|
||||
|
@ -170,10 +93,6 @@ ESX hostname is a regexp.
|
|||
|
||||
Don't list virtual machines.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,35 +47,18 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"storage-status" => { name => 'storage_status' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'.");
|
||||
|
@ -87,58 +66,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'healthhost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'healthhost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -151,18 +85,6 @@ Check health of ESX hosts.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -180,10 +102,6 @@ Check storage(s) status.
|
|||
|
||||
Status if ESX host disconnected (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,9 +48,6 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
"vm-hostname:s" => { name => 'vm_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
|
@ -63,9 +56,7 @@ sub new {
|
|||
"disk-limitset-status:s" => { name => 'disk_limitset_status', default => 'critical' },
|
||||
"nopoweredon-skip" => { name => 'nopoweredon_skip' },
|
||||
"check-disk-limit" => { name => 'check_disk_limit' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -73,18 +64,6 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong disconnect-status option '" . $self->{option_results}->{disconnect_status} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
|
@ -103,58 +82,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'limitvm';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'limitvm');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -163,22 +97,10 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check virtual machine tools.
|
||||
Check virtual machine limits.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--vm-hostname>
|
||||
|
||||
VM hostname to check.
|
||||
|
@ -196,10 +118,6 @@ Status if VM disconnected (default: 'unknown').
|
|||
|
||||
Skip check if VM is not poweredOn.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--cpu-limitset-status>
|
||||
|
||||
Status if cpu limit is set (default: critical).
|
||||
|
@ -214,7 +132,7 @@ Status if disk limit is set (default: critical).
|
|||
|
||||
=item B<--check-disk-limit>
|
||||
|
||||
Check disk limits (since vsphere 5.0)?
|
||||
Check disk limits (since vsphere 5.0).
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,90 +48,26 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
"datastore-name:s" => { name => 'datastore_name' },
|
||||
"filter" => { name => 'filter' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'listdatastores';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
# We need to remove xml output
|
||||
if (defined($self->{output}->{option_results}->{output_xml})) {
|
||||
delete $self->{output}->{option_results}->{output_xml};
|
||||
}
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->set_discovery();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'listdatastores');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
|
@ -146,10 +78,11 @@ sub disco_format {
|
|||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
# We ask to use XML output from the connector
|
||||
$self->{json_send}->{disco_show} = 1;
|
||||
$self->run();
|
||||
$self->{connector}->add_params(params => { disco_show => 1 });
|
||||
$self->run(custom => $self->{connector});
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -162,18 +95,6 @@ List datastores.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--datastore-name>
|
||||
|
||||
datastore name to list.
|
||||
|
@ -182,10 +103,6 @@ datastore name to list.
|
|||
|
||||
Datastore name is a regexp.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,15 +47,10 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -67,80 +58,21 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{esx_hostname}) ||
|
||||
$self->{option_results}->{esx_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --esx-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'listnichost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
# We need to remove xml output
|
||||
if (defined($self->{output}->{option_results}->{output_xml})) {
|
||||
delete $self->{output}->{option_results}->{output_xml};
|
||||
}
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->set_discovery();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'listnichost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
|
@ -151,10 +83,11 @@ sub disco_format {
|
|||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
# We ask to use XML output from the connector
|
||||
$self->{json_send}->{disco_show} = 1;
|
||||
$self->run();
|
||||
$self->{connector}->add_params(params => { disco_show => 1 });
|
||||
$self->run(custom => $self->{connector});
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -167,26 +100,10 @@ List ESX interfaces.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check (required).
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,36 +47,19 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"maintenance-alert:s" => { name => 'maintenance_alert', default => '^(?!(false))' },
|
||||
"maintenance-status:s" => { name => 'maintenance_status', default => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'.");
|
||||
|
@ -92,58 +71,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'maintenancehost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'maintenancehost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -156,18 +90,6 @@ Check maintenance mode of ESX hosts.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -181,10 +103,6 @@ ESX hostname is a regexp.
|
|||
|
||||
Status if ESX host disconnected (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--maintenance-alert>
|
||||
|
||||
Alert if maintenance mode value matches (default: '^(?!(false))').
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,36 +47,19 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
|
@ -96,58 +75,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'memhost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'memhost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -160,18 +94,6 @@ Check ESX memory usage.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -185,10 +107,6 @@ ESX hostname is a regexp.
|
|||
|
||||
Status if ESX host disconnected (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in percent.
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,37 +47,20 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"vm-hostname:s" => { name => 'vm_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"nopoweredon-status:s" => { name => 'nopoweredon_status', default => 'unknown' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
foreach my $label (('warning', 'critical')) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) {
|
||||
|
@ -102,58 +81,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'memvm';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'memvm');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -166,18 +100,6 @@ Check virtual machine memory.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--vm-hostname>
|
||||
|
||||
VM hostname to check.
|
||||
|
@ -195,10 +117,6 @@ Status if VM disconnected (default: 'unknown').
|
|||
|
||||
Status if VM is not poweredOn (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning for consumed memory (in percent).
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,10 +47,7 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"nic-name:s" => { name => 'nic_name' },
|
||||
"filter" => { name => 'filter' },
|
||||
|
@ -65,27 +58,13 @@ sub new {
|
|||
"warning-out:s" => { name => 'warning_out', },
|
||||
"critical-out:s" => { name => 'critical_out', },
|
||||
"link-down-status:s" => { name => 'link_down_status', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
foreach my $label (('warning_in', 'critical_in', 'warning_out', 'critical_out')) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) {
|
||||
|
@ -105,58 +84,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'nethost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'nethost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -169,18 +103,6 @@ Check ESX net usage.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -207,10 +129,6 @@ Status if ESX host disconnected (default: 'unknown').
|
|||
|
||||
Status if some links are down (default: 'critical').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning-in>
|
||||
|
||||
Threshold warning traffic in (percent).
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,10 +47,7 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"vm-hostname:s" => { name => 'vm_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
|
@ -62,27 +55,13 @@ sub new {
|
|||
"check-consolidation" => { name => 'check_consolidation' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
foreach my $label (('warning', 'critical')) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) {
|
||||
|
@ -99,58 +78,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'snapshotvm';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'snapshotvm');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -163,18 +97,6 @@ Check virtual machine snapshots.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--vm-hostname>
|
||||
|
||||
VM hostname to check.
|
||||
|
@ -192,10 +114,6 @@ Status if VM disconnected (default: 'unknown').
|
|||
|
||||
Skip check if VM is not poweredOn.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in seconds.
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,83 +48,22 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'stats';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'stats');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -141,18 +76,6 @@ Get number of requests for each connectors (information from daemon. Not VMWare)
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,16 +48,10 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"caca" => { name => 'caca' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -69,76 +59,19 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'statushost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'statushost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -151,18 +84,6 @@ Check ESX global status.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -176,10 +97,6 @@ ESX hostname is a regexp.
|
|||
|
||||
Status if ESX host disconnected (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,35 +48,18 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
|
@ -96,58 +75,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'swaphost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'swaphost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -160,18 +94,6 @@ Check ESX swap rate usage.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -185,10 +107,6 @@ ESX hostname is a regexp.
|
|||
|
||||
Status if ESX host disconnected (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in bytes per seconds.
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,37 +47,20 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"vm-hostname:s" => { name => 'vm_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"nopoweredon-status:s" => { name => 'nopoweredon_status', default => 'unknown' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
foreach my $label (('warning', 'critical')) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) {
|
||||
|
@ -102,58 +81,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'swapvm';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'swapvm');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -166,18 +100,6 @@ Check virtual machine swap rate usage.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--vm-hostname>
|
||||
|
||||
VM hostname to check.
|
||||
|
@ -195,10 +117,6 @@ Status if VM disconnected (default: 'unknown').
|
|||
|
||||
Status if VM is not poweredOn (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in bytes per seconds.
|
||||
|
|
|
@ -39,10 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,10 +47,7 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"vm-hostname:s" => { name => 'vm_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
|
@ -62,9 +55,7 @@ sub new {
|
|||
"tools-notrunning-status:s" => { name => 'tools_notrunning_status', default => 'critical' },
|
||||
"tools-notup2date-status:s" => { name => 'tools_notupd2date_status', default => 'warning' },
|
||||
"nopoweredon-skip" => { name => 'nopoweredon_skip' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -72,18 +63,6 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong disconnect-status option '" . $self->{option_results}->{disconnect_status} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
|
@ -102,58 +81,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'toolsvm';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'toolsvm');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -166,18 +100,6 @@ Check virtual machine tools.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--vm-hostname>
|
||||
|
||||
VM hostname to check.
|
||||
|
@ -195,10 +117,6 @@ Status if VM disconnected (default: 'unknown').
|
|||
|
||||
Skip check if VM is not poweredOn.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--tools-notinstalled-status>
|
||||
|
||||
Status if vmtools is not installed (default: critical).
|
||||
|
|
|
@ -39,11 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::vmware::connector::lib::common;
|
||||
use ZMQ::LibZMQ3;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use UUID;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
|
@ -51,36 +46,19 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"connector-hostname:s" => { name => 'connector_hostname' },
|
||||
"connector-port:s" => { name => 'connector_port', default => 5700 },
|
||||
"container:s" => { name => 'container', default => 'default' },
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
});
|
||||
$self->{json_send} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{connector_hostname}) ||
|
||||
$self->{option_results}->{connector_hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set option --connector-hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
|
||||
$self->{option_results}->{timeout} > 0) {
|
||||
$self->{timeout} = $self->{option_results}->{timeout};
|
||||
} else {
|
||||
$self->{timeout} = 50;
|
||||
}
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
|
@ -96,58 +74,13 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
sub build_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{json_send}->{identity} = 'client-' . unpack('H*', $options{uuid});
|
||||
$self->{json_send}->{command} = 'uptimehost';
|
||||
foreach (keys %{$self->{option_results}}) {
|
||||
$self->{json_send}->{$_} = $self->{option_results}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
my $uuid;
|
||||
my $context = zmq_init();
|
||||
$self->{requester} = zmq_socket($context, ZMQ_DEALER);
|
||||
if (!defined($self->{requester})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
UUID::generate($uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_IDENTITY, "client-" . $uuid);
|
||||
zmq_setsockopt($self->{requester}, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($self->{requester}, 'tcp://' . $self->{option_results}->{connector_hostname} . ':' . $self->{option_results}->{connector_port});
|
||||
|
||||
$self->build_request(uuid => $uuid);
|
||||
|
||||
zmq_sendmsg($self->{requester}, "REQCLIENT " . JSON->new->utf8->encode($self->{json_send}), ZMQ_NOBLOCK);
|
||||
|
||||
my @poll = (
|
||||
{
|
||||
socket => $self->{requester},
|
||||
events => ZMQ_POLLIN,
|
||||
callback => sub {
|
||||
my $response = zmq_recvmsg($self->{requester});
|
||||
zmq_close($self->{requester});
|
||||
apps::vmware::connector::lib::common::connector_response($self, response => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
zmq_poll(\@poll, $self->{timeout} * 1000);
|
||||
zmq_close($self->{requester});
|
||||
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => sprintf("Cannot get response (timeout received)"));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{connector}->add_params(params => $self->{option_results},
|
||||
command => 'uptimehost');
|
||||
$self->{connector}->run();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -160,18 +93,6 @@ Check ESX swap rate usage.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--connector-hostname>
|
||||
|
||||
Connector hostname (required).
|
||||
|
||||
=item B<--connector-port>
|
||||
|
||||
Connector port (default: 5700).
|
||||
|
||||
=item B<--container>
|
||||
|
||||
Container to use (it depends of the connector configuration).
|
||||
|
||||
=item B<--esx-hostname>
|
||||
|
||||
ESX hostname to check.
|
||||
|
@ -185,10 +106,6 @@ ESX hostname is a regexp.
|
|||
|
||||
Status if ESX host disconnected (default: 'unknown').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set global execution timeout (Default: 50)
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in seconds.
|
||||
|
|
|
@ -37,7 +37,7 @@ package apps::vmware::connector::plugin;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -68,6 +68,7 @@ sub new {
|
|||
'uptime-host' => 'apps::vmware::connector::mode::uptimehost',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{connector} = 'apps::vmware::connector::custom::connector';
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
@ -198,7 +198,6 @@ sub is_custommode {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
sub version {
|
||||
my $self = shift;
|
||||
$self->{output}->add_option_msg(short_msg => "Plugin Version: " . $self->{version});
|
||||
|
|
Loading…
Reference in New Issue