mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-09-21 08:47:57 +02:00
fix(centreon_vmware): test if dependencies are installed (#5665)
Refs: CTOR-1780
This commit is contained in:
parent
d4f9625b19
commit
657c4d00af
@ -39,6 +39,13 @@ contents:
|
||||
dst: "/usr/share/perl5/centreon/script/centreon_vmware.pm"
|
||||
packager: deb
|
||||
|
||||
- src: "../src/centreon/script/centreon_vmware_requirements.pm"
|
||||
dst: "/usr/share/perl5/vendor_perl/centreon/script/centreon_vmware_requirements.pm"
|
||||
packager: rpm
|
||||
- src: "../src/centreon/script/centreon_vmware_requirements.pm"
|
||||
dst: "/usr/share/perl5/centreon/script/centreon_vmware_requirements.pm"
|
||||
packager: deb
|
||||
|
||||
- src: "../src/centreon/script/centreonvault.pm"
|
||||
dst: "/usr/share/perl5/vendor_perl/centreon/script/centreonvault.pm"
|
||||
packager: rpm
|
||||
@ -102,6 +109,9 @@ overrides:
|
||||
- perl(ZMQ::Constants)
|
||||
- perl(ZMQ::LibZMQ4)
|
||||
- perl-Net-Curl
|
||||
- perl(XML::LibXML)
|
||||
- perl(Sys::Syslog)
|
||||
- perl(JSON)
|
||||
deb:
|
||||
depends:
|
||||
- libclass-methodmaker-perl
|
||||
@ -116,6 +126,8 @@ overrides:
|
||||
- libuuid-perl
|
||||
- libzmq-constants-perl
|
||||
- libzmq-libzmq4-perl
|
||||
- libxml-libxml-perl
|
||||
- libjson-perl
|
||||
|
||||
rpm:
|
||||
signature:
|
||||
|
@ -0,0 +1,71 @@
|
||||
# Copyright 2025 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::script::centreon_vmware_requirements;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::script;
|
||||
use Getopt::Long;
|
||||
use base qw(centreon::vmware::script);
|
||||
|
||||
# This package is only used to check if the VMware Perl SDK is installed
|
||||
# If the SDK is not present a detailed error message is logged in the Centreon log file
|
||||
|
||||
sub new {
|
||||
my ($class) = @_;
|
||||
my $self = $class->SUPER::new('centreon_vmware_requirements');
|
||||
|
||||
# "required" contain modules to check VMware::VIRuntime and VMware::VILib
|
||||
$self->{required} = [ 'VMware::VIRuntime', 'VMware::VILib' ];
|
||||
|
||||
bless $self, $class;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub parse_options {
|
||||
my $self = shift;
|
||||
|
||||
# Here we only use --logfile parameter to log the error message if the VMware Perl SDK is not installed
|
||||
# We use pass_throuth because we dont want this module to raise an error if an unrecognized option is passed
|
||||
Getopt::Long::Configure('pass_through');
|
||||
GetOptions(%{$self->{options}});
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
foreach (@{$self->{required}}) {
|
||||
eval "use $_;";
|
||||
if ($@) {
|
||||
my $msg = "$@\n\n***************\n".
|
||||
"To make the Centreon VMware VM Monitoring Connector work, you will need the Perl VMware SDK.\n".
|
||||
"Please refer to the documentation at https://docs.centreon.com/pp/integrations/plugin-packs/procedures/virtualization-vmware2-vm/#vmware-perl-sdk for the procedure.\n".
|
||||
"***************\n";
|
||||
$self->SUPER::run();
|
||||
|
||||
$self->{logger}->writeLogFatal($msg);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
@ -20,6 +20,14 @@
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
|
||||
BEGIN {
|
||||
# This package centreon_vmware_requirements is used to check if the VMware Perl SDK is installed.
|
||||
# I use a script based module in order to log the error message in the Centreon configured log file.
|
||||
use centreon::script::centreon_vmware_requirements;
|
||||
centreon::script::centreon_vmware_requirements->new()->run();
|
||||
}
|
||||
|
||||
use centreon::script::centreon_vmware;
|
||||
|
||||
centreon::script::centreon_vmware->new()->run();
|
||||
|
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test2::V0;
|
||||
use Test2::Plugin::NoWarnings echo => 1;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::RealBin/../../../src";
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
# Test with modules that do not exist ExIsTe::PaS and ExIsTe::pAs
|
||||
# Program should not die and just log an error message
|
||||
eval q{
|
||||
local *STDOUT; # to catch error message
|
||||
open STDOUT, '>', '/dev/null';
|
||||
use lib "$FindBin::RealBin/../../../src";
|
||||
use centreon::script::centreon_vmware_requirements;
|
||||
my $module = centreon::script::centreon_vmware_requirements->new();
|
||||
$module->{required} = [ 'ExIsTe::PaS', 'ExIsTe::pAs' ];
|
||||
$module->run();
|
||||
};
|
||||
my $test = $@ // '';
|
||||
ok($test =~ /To make the Centreon VMware VM Monitoring Connector work, you will need the Perl VMware SDK/m, "Test for missing modules");
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
# Test with existing modules Data::Dumper and FindBin
|
||||
# Program should not die and produce no output
|
||||
eval q{
|
||||
use lib "$FindBin::RealBin/../../../src";
|
||||
use centreon::script::centreon_vmware_requirements;
|
||||
my $module = centreon::script::centreon_vmware_requirements->new();
|
||||
$module->{required} = [ 'Data::Dumper', 'FindBin' ];
|
||||
$module->run();
|
||||
};
|
||||
my $test = $@ // '';
|
||||
ok($test eq '', "Test for installed modules");
|
||||
}
|
||||
|
||||
done_testing();
|
Loading…
x
Reference in New Issue
Block a user