diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm index c079a9aa4..e80c0211f 100644 --- a/centreon/plugins/script.pm +++ b/centreon/plugins/script.pm @@ -166,10 +166,76 @@ sub check_directory { closedir $dh; } +sub fatpacker_find_plugin { + my ($self) = @_; + + my $plugins = []; + foreach (@INC) { + next if (ref($_) !~ /FatPacked/); + foreach my $name (keys %$_) { + if ($name =~ /plugin.pm$/) { + push @$plugins, $name; + } + } + } + + return $plugins; +} + +sub check_plugin_option { + my ($self) = @_; + + if (defined($self->{version})) { + $self->{output}->add_option_msg(short_msg => "Global Version: " . $global_version); + $self->{output}->option_exit(nolabel => 1); + } + + my $no_plugin = 1; + if ($alternative_fatpacker == 1) { + my $integrated_plugins = $self->fatpacker_find_plugin(); + if (scalar(@$integrated_plugins) == 1) { + $self->{plugin} = $integrated_plugins->[0]; + $no_plugin = 0; + } + } + + if ($no_plugin == 1) { + $self->{output}->add_option_msg(short_msg => "Need to specify '--plugin' option."); + $self->{output}->option_exit(); + } +} + sub display_list_plugin { my ($self) = @_; $self->{plugins_result} = {}; + if ($alternative_fatpacker == 1) { + my $integrated_plugins = $self->fatpacker_find_plugin(); + + foreach my $key (@$integrated_plugins) { + # Need to load it to get the description + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{plugin}, + error_msg => "Cannot load module --plugin."); + + my $name = $key; + $name =~ s/\.pm//g; + $name =~ s/\//::/g; + $self->{output}->add_option_msg(long_msg => '-----------------'); + $self->{output}->add_option_msg(long_msg => 'PLUGIN: ' . $name); + { + my $stdout = ''; + local *STDOUT; + open STDOUT, '>', \$stdout; + my $content_class = $INC{$key}->{$key}; + open my $str_fh, '<', \$content_class; + pod2usage(-exitval => "NOEXIT", -input => $str_fh, -verbose => 99, -sections => "PLUGIN DESCRIPTION"); + close $str_fh; + $self->{output}->add_option_msg(long_msg => $stdout); + } + } + return ; + } + # Search file 'plugin.pm' $self->check_directory($FindBin::Bin); foreach my $key (keys %{$self->{plugins_result}}) { @@ -260,12 +326,7 @@ sub run { $self->{output}->option_exit(); } if (!defined($self->{plugin}) || $self->{plugin} eq '') { - if (defined($self->{version})) { - $self->{output}->add_option_msg(short_msg => "Global Version: " . $global_version); - $self->{output}->option_exit(nolabel => 1); - } - $self->{output}->add_option_msg(short_msg => "Need to specify '--plugin' option."); - $self->{output}->option_exit(); + $self->check_plugin_option(); } if (defined($self->{ignore_warn_msg})) { $SIG{__WARN__} = sub {};