From 06442fa6e30cb00fe4d41245814ff53831722c96 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 10 Feb 2023 15:03:57 +0100 Subject: [PATCH] WIP: Omnishell error xml if YAML::Tiny not installed on agent --- pandora_agents/unix/pandora_agent | 46 ++++++++++++++++++------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index f01ddb5744..90b7d93c7c 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -556,30 +556,38 @@ BEGIN { sub runCommand { my ($self, $ref, $output_mode) = @_; + my $result; if($self->load_libraries()) { # Functionality possible. my $command = $self->{'commands'}->{$ref}; - my $result = $self->evaluate_command($ref); - if (ref($result) eq "HASH") { - # Process command result. - if (defined($output_mode) && $output_mode eq 'xml') { - my $output = ''; - $output .= "\n"; - $output .= " \n"; - $output .= " {'name'}."]]>\n"; - $output .= " \n"; - $output .= " {'error_level'}."]]>\n"; - $output .= " {'stdout'}."]]>\n"; - $output .= " {'stderr'}."]]>\n"; - $output .= " \n"; - $output .= "\n"; + $result = $self->evaluate_command($ref); + } else { + $result = { + 'stderr' => 'Cannot use commands without YAML dependency, please install it.', + 'name' => 'YAML::Tiny', + 'error_level' => 2, + }; + } - return $output; - } - return $result; - } else { - $self->set_last_error('Failed to process ['.$ref.']: '.$result); + if (ref($result) eq "HASH") { + # Process command result. + if (defined($output_mode) && $output_mode eq 'xml') { + my $output = ''; + $output .= "\n"; + $output .= " \n"; + $output .= " {'name'}."]]>\n"; + $output .= " \n"; + $output .= " {'error_level'}."]]>\n"; + $output .= " {'stdout'}."]]>\n"; + $output .= " {'stderr'}."]]>\n"; + $output .= " \n"; + $output .= "\n"; + + return $output; } + return $result; + } else { + $self->set_last_error('Failed to process ['.$ref.']: '.$result); } return undef;