Auto-assign Satellite Servers to agents when possible.

This commit is contained in:
Ramon Novoa 2022-06-09 13:29:43 +02:00
parent 48b20b255b
commit 5e33df93ac
2 changed files with 14 additions and 3 deletions

View File

@ -3002,10 +3002,10 @@ defined also the parent is updated.
=cut =cut
########################################################################## ##########################################################################
sub pandora_update_agent ($$$$$$$;$$) { sub pandora_update_agent ($$$$$$$;$$$) {
my ($pa_config, $agent_timestamp, $agent_id, $os_version, my ($pa_config, $agent_timestamp, $agent_id, $os_version,
$agent_version, $agent_interval, $dbh, $timezone_offset, $agent_version, $agent_interval, $dbh, $timezone_offset,
$parent_agent_id) = @_; $parent_agent_id, $satellite_server_id) = @_;
# No access update for data without interval. # No access update for data without interval.
# Single modules from network server, for example. This could be very Heavy for Pandora FMS # 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, 'os_version' => $os_version,
'timezone_offset' => $timezone_offset, 'timezone_offset' => $timezone_offset,
'id_parent' => $parent_agent_id, 'id_parent' => $parent_agent_id,
'satellite_server' => $satellite_server_id
}); });
db_do ($dbh, "UPDATE tagente SET $set WHERE id_agente = ?", @{$values}, $agent_id); db_do ($dbh, "UPDATE tagente SET $set WHERE id_agente = ?", @{$values}, $agent_id);

View File

@ -453,6 +453,16 @@ sub process_xml_data ($$$$$) {
return; 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 # 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. # in order to avoid not only events, also possible invalid data coming from agents.
# But, if agent is in mode autodisable, put it enable and retrieve all data # But, if agent is in mode autodisable, put it enable and retrieve all data
@ -536,7 +546,7 @@ sub process_xml_data ($$$$$) {
} }
# Update agent information # 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 # Update GIS data
if ($pa_config->{'activate_gis'} != 0 && $agent->{'update_gis_data'} == 1) { if ($pa_config->{'activate_gis'} != 0 && $agent->{'update_gis_data'} == 1) {