This commit is contained in:
garnier-quentin 2016-05-02 21:06:27 +02:00
parent 9452678090
commit 2b9d0b7a47
7 changed files with 18 additions and 15 deletions

View File

@ -214,11 +214,13 @@ sub unix_execute {
sub mymodule_load {
my (%options) = @_;
my $file;
($file = $options{module} . ".pm") =~ s{::}{/}g;
($file = ($options{module} =~ /\.pm$/ ? $options{module} : $options{module} . ".pm")) =~ s{::}{/}g;
eval {
local $SIG{__DIE__} = 'IGNORE';
require $file;
$file =~ s{/}{::}g;
$file =~ s/\.pm$//;
};
if ($@) {
return 1 if (defined($options{no_quit}) && $options{no_quit} == 1);
@ -226,7 +228,7 @@ sub mymodule_load {
$options{output}->add_option_msg(short_msg => $options{error_msg});
$options{output}->option_exit();
}
return 0;
return wantarray ? (0, $file) : 0;
}
sub backtick {

View File

@ -273,6 +273,7 @@ sub run {
$self->check_relaunch();
(undef, $self->{plugin}) =
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{plugin},
error_msg => "Cannot load module --plugin.");
my $plugin = $self->{plugin}->new(options => $self->{options}, output => $self->{output});

View File

@ -115,7 +115,7 @@ sub init {
error_msg => "Cannot load module --mode.");
$self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name});
} elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
(undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
error_msg => "Cannot load module --dyn-mode.");
$self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name});
} else {

View File

@ -86,7 +86,7 @@ sub init {
error_msg => "Cannot load module --mode.");
$self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name});
} elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
(undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
error_msg => "Cannot load module --dyn-mode.");
$self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name});
} else {

View File

@ -91,7 +91,7 @@ sub init {
error_msg => "Cannot load module --mode.");
$self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name});
} elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
(undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
error_msg => "Cannot load module --dyn-mode.");
$self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name});
} else {

View File

@ -107,7 +107,7 @@ sub init {
error_msg => "Cannot load module --mode.");
$self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name});
} elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
(undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
error_msg => "Cannot load module --dyn-mode.");
$self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name});
} else {

View File

@ -91,7 +91,7 @@ sub init {
error_msg => "Cannot load module --mode.");
$self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name});
} elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
(undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name},
error_msg => "Cannot load module --dyn-mode.");
$self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name});
} else {