From ca9d168e67b035611ecc4e4caf3594a2b615ec7f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 11 Nov 2019 18:12:43 +0100 Subject: [PATCH] wip omnishell --- pandora_agents/unix/pandora_agent | 25 +++++++++++++++++---- pandora_server/lib/PandoraFMS/DataServer.pm | 6 ++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index c9315a31c8..cd2c293aef 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -281,6 +281,20 @@ sub error ($) { exit 1; } +################################################################################ +# Try to load extra libraries.c +################################################################################ +sub load_libraries() { + # Dynamic load. Avoid unwanted behaviour. + eval {eval 'require YAML::Tiny;1' or die('YAML::Tiny lib not found, commands feature won\'t be available');}; + if ($@) { + $YAML = 0; + print STDERR $@; + } else { + $YAML = 1; + } +} + ################################################################################ # Check a regular expression. Returns 1 if its valid, 0 otherwise. ################################################################################ @@ -1199,14 +1213,14 @@ sub recv_file { }; if ($@) { - log_message ('error', "Error retrieving file: File transfer command is not responding."); + log_message ('error', "Error retrieving file: '.$file.' File transfer command is not responding."); exit 1; } # Get the errorlevel my $rc = $? >> 8; if ($rc != 0) { - log_message ('error', "Error retrieving file: $output"); + log_message ('error', "Error retrieving file: '$file' $output"); } exit $rc; } @@ -1469,7 +1483,7 @@ sub prepare_remote_commands { }; if ($@) { # Failed. - log_message('error', 'Failed to decode command. ' . $@); + log_message('error', 'Failed to decode command. ' . "\n".$@); delete $Conf{'commands'}->{$ref}; next; } @@ -3206,6 +3220,8 @@ my $iter_base_time = time(); $LogFileIdx = -1; # Loop while (1) { + load_libraries(); + if (-e $Conf{'logfile'} && (stat($Conf{'logfile'}))[7] > $Conf{'logsize'}) { rotate_log(); } @@ -3376,9 +3392,10 @@ while (1) { $Xml .= "\n"; $Xml .= " \n"; $Xml .= " {'name'}."]]>\n"; + $Xml .= " \n"; $Xml .= " {'error_level'}."]]>\n"; $Xml .= " {'stdout'}."]]>\n"; - $Xml .= " {'stderr'}."]]>\n"; + $Xml .= " {'stderr'}."]]>\n"; $Xml .= " \n"; $Xml .= "\n"; } diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index df1cbbecfb..38a33fc263 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -602,8 +602,12 @@ sub process_xml_data ($$$$$) { # Process events process_events_dataserver($pa_config, $data, $agent_id, $group_id, $dbh); - # Process disovery modules + # Process discovery modules enterprise_hook('process_discovery_data', [$pa_config, $data, $server_id, $dbh]); + + # Process command responses + enterprise_hook('process_rcmd_report', [$pa_config, $data, $server_id, $dbh, $agent_id, $timestamp]); + } ##########################################################################