diff --git a/gorgone/gorgone/modules/centreon/autodiscovery/class.pm b/gorgone/gorgone/modules/centreon/autodiscovery/class.pm index 6d4e7bdad2d..14e860d41a6 100644 --- a/gorgone/gorgone/modules/centreon/autodiscovery/class.pm +++ b/gorgone/gorgone/modules/centreon/autodiscovery/class.pm @@ -478,6 +478,12 @@ sub launchhostdiscovery { ] }); + # plugins attribute format: + # "plugins": { + # "centreon-plugin-Cloud-Aws-Ec2-Api": 20220727, + # ... + # } + $self->send_internal_action({ action => 'COMMAND', target => $self->{hdisco_jobs_ids}->{$job_id}->{target}, @@ -490,7 +496,8 @@ sub launchhostdiscovery { timeout => $timeout, metadata => { job_id => $job_id, - source => 'autodiscovery-host-job-discovery' + source => 'autodiscovery-host-job-discovery', + pkg_install => $self->{hdisco_jobs_ids}->{$job_id}->{plugins} } } ] @@ -678,22 +685,6 @@ sub discovery_add_host_result { sub discovery_command_result { my ($self, %options) = @_; -=pod - use Devel::Size; - print "frame = " . (Devel::Size::total_size($options{frame}) / 1024 / 1024) . "==\n"; - - my $data = $options{frame}->getData(); - print "data = " . (Devel::Size::total_size($data) / 1024 / 1024) . "==\n"; - - my $frame = $options{frame}->getFrame(); - print "frame data = " . (Devel::Size::total_size($frame) / 1024 / 1024) . "==\n"; - - my $raw = $options{frame}->getRawData(); - print "raw data = " . (Devel::Size::total_size($raw) / 1024 / 1024) . "==\n"; - - return 1; -=cut - my $data = $options{frame}->getData(); return 1 if (!defined($data->{data}->{metadata}->{job_id})); diff --git a/gorgone/gorgone/modules/core/action/class.pm b/gorgone/gorgone/modules/core/action/class.pm index 3c386d16cdf..dc7f30d27f3 100644 --- a/gorgone/gorgone/modules/core/action/class.pm +++ b/gorgone/gorgone/modules/core/action/class.pm @@ -314,15 +314,18 @@ sub validate_plugins_deb { sub validate_plugins { my ($self, %options) = @_; - my ($rv, $message, $content) = gorgone::standard::misc::slurp(file => $options{file}); - return (1, $message) if (!$rv); + my ($rv, $message, $content); + my $plugins = $options{plugins}; + if (!defined($plugins)) { + ($rv, $message, $content) = gorgone::standard::misc::slurp(file => $options{file}); + return (1, $message) if (!$rv); - my $plugins; - try { - $plugins = JSON::XS->new->decode($content); - } catch { - return (1, 'cannot decode json'); - }; + try { + $plugins = JSON::XS->new->decode($content); + } catch { + return (1, 'cannot decode json'); + }; + } # nothing to validate. so it's ok, show must go on!! :) if (ref($plugins) ne 'HASH' || scalar(keys %$plugins) <= 0) { @@ -412,7 +415,6 @@ sub action_command { ); my $errors = 0; - foreach my $command (@{$options{data}->{content}}) { $self->send_log( socket => $options{socket_log}, @@ -425,7 +427,31 @@ sub action_command { metadata => $command->{metadata} } ); - + + # check install pkg + if (defined($command->{metadata}) && defined($command->{metadata}->{pkg_install})) { + my ($rv, $message) = $self->validate_plugins(plugins => $command->{metadata}->{pkg_install}); + if ($rv && $self->{paranoid_plugins} == 1) { + $self->{logger}->writeLogError("[action] $message"); + $self->send_log( + socket => $options{socket_log}, + code => GORGONE_ACTION_FINISH_KO, + token => $options{token}, + logging => $options{data}->{logging}, + data => { + message => "command execution issue", + command => $command->{command}, + metadata => $command->{metadata}, + result => { + exit_code => $rv, + stdout => $message + } + } + ); + next; + } + } + my $start = time(); my ($error, $stdout, $return_code) = gorgone::standard::misc::backtick( command => $command->{command}, @@ -495,7 +521,7 @@ sub action_command { ); } } - + if ($errors) { $self->send_log( socket => $options{socket_log},