From 5e33df93ac72cee946416520a342b93c0f72f7af Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Thu, 9 Jun 2022 13:29:43 +0200 Subject: [PATCH] Auto-assign Satellite Servers to agents when possible. --- pandora_server/lib/PandoraFMS/Core.pm | 5 +++-- pandora_server/lib/PandoraFMS/DataServer.pm | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index acc4d83546..189be884c9 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -3002,10 +3002,10 @@ defined also the parent is updated. =cut ########################################################################## -sub pandora_update_agent ($$$$$$$;$$) { +sub pandora_update_agent ($$$$$$$;$$$) { my ($pa_config, $agent_timestamp, $agent_id, $os_version, $agent_version, $agent_interval, $dbh, $timezone_offset, - $parent_agent_id) = @_; + $parent_agent_id, $satellite_server_id) = @_; # No access update for data without interval. # Single modules from network server, for example. This could be very Heavy for Pandora FMS @@ -3026,6 +3026,7 @@ sub pandora_update_agent ($$$$$$$;$$) { 'os_version' => $os_version, 'timezone_offset' => $timezone_offset, 'id_parent' => $parent_agent_id, + 'satellite_server' => $satellite_server_id }); db_do ($dbh, "UPDATE tagente SET $set WHERE id_agente = ?", @{$values}, $agent_id); diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 232361a50f..87909350cc 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -452,6 +452,16 @@ sub process_xml_data ($$$$$) { logger($pa_config, "Error retrieving information for agent ID $agent_id",10); return; } + + # Get the ID of the Satellite Server if available. + my $satellite_server_id = 0; + if (defined($data->{'satellite_server'})) { + $satellite_server_id = get_server_id($dbh, $data->{'satellite_server'}, SATELLITESERVER); + if ($satellite_server_id < 0) { + logger($pa_config, "Satellite Server '" . $data->{'satellite_server'} . "' does not exist.", 10); + $satellite_server_id = 0; + } + } # Check if agent is disabled and return if it's disabled. Disabled agents doesnt process data # in order to avoid not only events, also possible invalid data coming from agents. @@ -536,7 +546,7 @@ sub process_xml_data ($$$$$) { } # Update agent information - pandora_update_agent($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh, $timezone_offset, $parent_id); + pandora_update_agent($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh, $timezone_offset, $parent_id, $satellite_server_id); # Update GIS data if ($pa_config->{'activate_gis'} != 0 && $agent->{'update_gis_data'} == 1) {