update findbin from script.pm

This commit is contained in:
garnier-quentin 2019-12-17 11:35:12 +01:00
parent fb5edb6ea0
commit 5d13fb53eb
1 changed files with 41 additions and 27 deletions

View File

@ -24,7 +24,6 @@ use strict;
use warnings;
use centreon::plugins::output;
use centreon::plugins::misc;
use FindBin;
use Pod::Usage;
use Pod::Find qw(pod_where);
@ -191,11 +190,14 @@ sub check_directory {
{
local *STDOUT;
open STDOUT, '>', \$stdout;
pod2usage(-exitval => 'NOEXIT', -input => $directory . "/" . $filename,
-verbose => 99,
-sections => "PLUGIN DESCRIPTION");
pod2usage(
-exitval => 'NOEXIT',
-input => $directory . "/" . $filename,
-verbose => 99,
-sections => 'PLUGIN DESCRIPTION'
);
}
$self->{plugins_result}->{$directory . "/" . $filename} = $stdout;
$self->{plugins_result}->{$directory . '/' . $filename} = $stdout;
}
}
closedir $dh;
@ -273,6 +275,10 @@ sub display_list_plugin {
return ;
}
centreon::plugins::misc::mymodule_load(
output => $self->{output}, module => 'FindBin',
error_msg => "Cannot load module 'FindBin'."
);
# Search file 'plugin.pm'
$self->check_directory($FindBin::Bin);
foreach my $key (sort keys %{$self->{plugins_result}}) {
@ -289,8 +295,14 @@ sub display_list_plugin {
sub check_relaunch {
my $self = shift;
centreon::plugins::misc::mymodule_load(
output => $self->{output}, module => 'FindBin',
error_msg => "Cannot load module 'FindBin'."
);
my $need_restart = 0;
my $cmd = $FindBin::Bin . "/" . $FindBin::Script;
my $cmd = $FindBin::Bin . '/' . $FindBin::Script;
my @args = ();
if (defined($self->{environment})) {
@ -311,11 +323,11 @@ sub check_relaunch {
}
if ($uid != $>) {
if ($> == 0) {
unshift @args, "-s", "/bin/bash", "-l", $self->{runas}, "-c", join(" ", $cmd, "--plugin=" . $self->{plugin}, @ARGV);
$cmd = "su";
unshift @args, '-s', '/bin/bash', '-l', $self->{runas}, '-c', join(' ', $cmd, '--plugin=' . $self->{plugin}, @ARGV);
$cmd = 'su';
} else {
unshift @args, "-S", "-u", $self->{runas}, $cmd, "--plugin=" . $self->{plugin}, @ARGV;
$cmd = "sudo";
unshift @args, '-S', '-u', $self->{runas}, $cmd, '--plugin=' . $self->{plugin}, @ARGV;
$cmd = 'sudo';
}
$need_restart = 1;
}
@ -335,8 +347,10 @@ sub check_relaunch {
if ($exit_code <= -1000) {
if ($exit_code == -1000) {
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => $stdout);
$self->{output}->output_add(
severity => 'UNKNOWN',
short_msg => $stdout
);
}
$self->{output}->display();
$self->{output}->exit();