add code lost inventory server pandora_enterprise#12188

This commit is contained in:
daniel 2023-11-15 08:30:24 +01:00
parent c7a746ea41
commit b45c967919
1 changed files with 28 additions and 10 deletions

View File

@ -184,14 +184,21 @@ sub data_consumer ($$) {
# No code to run
return if ($module->{'interpreter'} eq '');
# Save script in a temporary file
my $command;
my ($fh, $temp_file) = tempfile();
if ($module->{'script_mode'} == '1') {
my $script_file = $module->{'script_path'};
$command = $module->{'interpreter'} . ' ' . $script_file;
} else {
# Save script in a temporary file
$fh->print (decode_base64($module->{'code'}));
close ($fh);
set_file_permissions($pa_config, $temp_file, "0777");
# Run the script
my $command = $module->{'interpreter'} . ' ' . $temp_file . ' "' . $module->{'target'} . '"';
$command = $module->{'interpreter'} . ' ' . $temp_file . ' "' . $module->{'target'} . '"';
}
# Try to read the custom fields to use them as arguments into the command
if (defined($module->{'custom_fields'}) && $module->{'custom_fields'} ne '') {
@ -206,7 +213,11 @@ sub data_consumer ($$) {
if (!defined ($decoded_cfields)) {
logger ($pa_config, "Remote inventory module ".$module->{'name'}." has failed because the custom fields can't be read", 6);
if ($module->{'script_mode'} == '2') {
unlink ($temp_file);
}
return;
}
@ -237,11 +248,18 @@ sub data_consumer ($$) {
# Check for errors
if ($? != 0) {
logger ($pa_config, "Remote inventory module ".$module->{'name'}." has failed with error level $?", 6);
if ($module->{'script_mode'} == '2') {
unlink ($temp_file);
}
return;
}
if ($module->{'script_mode'} == '2') {
unlink ($temp_file);
}
my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
eval {