From 06442fa6e30cb00fe4d41245814ff53831722c96 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 10 Feb 2023 15:03:57 +0100 Subject: [PATCH 1/3] 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; From a9832e9886b9bbff50c51021b0fe1d44c721ae7e Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 13 Feb 2023 15:40:55 +0100 Subject: [PATCH 2/3] WIP: Added pandora notification if missing library on agent --- .../include/class/ConsoleSupervisor.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index b6a6d3df43..17d7b2213a 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -518,6 +518,14 @@ class ConsoleSupervisor $this->checkSyncQueueLength(); $this->checkSyncQueueStatus(); } + + /* + * Checkc agent missing libraries. + * NOTIF.AGENT.LIBRARY + */ + if ((bool) enterprise_installed() === true) { + $this->checkLibaryError(); + } } @@ -2806,4 +2814,29 @@ class ConsoleSupervisor } + /** + * Chechs if an agent has a dependency eror on omnishell + * + * @return void + */ + public function checkLibaryError() + { + $sql = 'SELECT COUNT(errorlevel) from tremote_command_target WHERE errorlevel = 2'; + + $error_dependecies = db_get_sql($sql); + if ($error_dependecies > 0) { + $this->notify( + [ + 'type' => 'NOTIF.AGENT.LIBRARY', + 'title' => __('Agent dependency error'), + 'message' => __( + 'There are omnishell agents with dependency errors', + ), + 'url' => $url, + ] + ); + } + } + + } From 9c4a0f8a2bcae7f3094f8d72a3ff2a5917767ff6 Mon Sep 17 00:00:00 2001 From: Calvo Date: Tue, 14 Feb 2023 09:03:51 +0100 Subject: [PATCH 3/3] Agent library error notification --- pandora_console/include/class/ConsoleSupervisor.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 17d7b2213a..1f82d1cea0 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -258,6 +258,14 @@ class ConsoleSupervisor $this->checkSyncQueueStatus(); } + /* + * Checkc agent missing libraries. + * NOTIF.AGENT.LIBRARY + */ + if ((bool) enterprise_installed() === true) { + $this->checkLibaryError(); + } + } @@ -2832,7 +2840,8 @@ class ConsoleSupervisor 'message' => __( 'There are omnishell agents with dependency errors', ), - 'url' => $url, + + 'url' => '__url__/index.php?sec=gextensions&sec2=enterprise/tools/omnishell', ] ); }