diff --git a/pandora_console/extras/mr/55.sql b/pandora_console/extras/mr/55.sql index 747a8da934..246e8b641f 100644 --- a/pandora_console/extras/mr/55.sql +++ b/pandora_console/extras/mr/55.sql @@ -38,6 +38,8 @@ ALTER TABLE `tbackup` MODIFY COLUMN `id_user` VARCHAR(255) DEFAULT ''; ALTER TABLE `tservice` ADD COLUMN `enable_sunburst` tinyint(1) NOT NULL default 0; ALTER TABLE `tdashboard` MODIFY `name` TEXT NOT NULL DEFAULT ''; +ALTER TABLE `tagente` ADD COLUMN `satellite_server` INT NOT NULL default 0; +ALTER TABLE `tmetaconsole_agent` ADD COLUMN `satellite_server` INT NOT NULL default 0; SET @st_oum763 = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tautoconfig' AND table_schema = DATABASE() AND column_name = 'disabled') > 0, "SELECT 1", @@ -49,3 +51,4 @@ EXECUTE pr_oum763; DEALLOCATE PREPARE pr_oum763; COMMIT; + diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index a9282fa1af..95bb218d62 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -245,8 +245,11 @@ if (!$new_agent && $alias != '') { } // Remote configuration available. + $remote_agent = false; if (isset($filename)) { if (file_exists($filename['md5'])) { + $remote_agent = true; + $agent_name = agents_get_name($id_agente); $agent_name = io_safe_output($agent_name); $agent_md5 = md5($agent_name, false); @@ -427,6 +430,42 @@ $table_server .= html_print_select( true ).'
'; + +$table_satellite = ''; +if ($remote_agent === true) { + // Satellite server selector. + $satellite_servers = db_get_all_rows_filter( + 'tserver', + ['server_type' => SERVER_TYPE_ENTERPRISE_SATELLITE], + [ + 'id_server', + 'name', + ] + ); + + $satellite_names = []; + if (empty($satellite_servers) === false) { + foreach ($satellite_servers as $s_server) { + $satellite_names[$s_server['id_server']] = $s_server['name']; + } + + $table_satellite = '

'.__('Satellite').'

'; + $table_satellite .= '
'; + + $table_satellite .= html_print_input( + [ + 'type' => 'select', + 'fields' => $satellite_names, + 'name' => 'satellite_server', + 'selected' => $satellite_server, + 'nothing' => __('None'), + 'nothinf_value' => 0, + 'return' => true, + ] + ).'
'; + } +} + // Description. $table_description = '

'.__('Description').'

'; $table_description .= html_print_textarea( @@ -443,7 +482,7 @@ $table_description .= html_print_textarea( echo '
'.$table_agent_name.$table_alias.$table_ip.$table_primary_group.'
-
'.$table_interval.$table_os.$table_server.$table_description.'
+
'.$table_interval.$table_os.$table_server.$table_satellite.$table_description.'
'; if (!$new_agent && $alias != '') { echo $table_qr_code; diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 8e63416b97..4d26746ed1 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -155,6 +155,7 @@ $alert_d7 = 1; $alert_recovery = 0; $alert_priority = 0; $server_name = ''; +$satellite_server = 0; $grupo = 0; $id_os = 9; // Windows. @@ -985,6 +986,7 @@ if ($update_agent) { $old_values = db_get_row('tagente', 'id_agente', $id_agente); $fields = db_get_all_fields_in_table('tagent_custom_fields'); $secondary_groups = (string) get_parameter('secondary_hidden', ''); + $satellite_server = (int) get_parameter('satellite_server', 0); if ($fields === false) { $fields = []; @@ -1092,6 +1094,7 @@ if ($update_agent) { 'quiet' => $quiet, 'cps' => $cps, 'safe_mode_module' => $safe_mode_module, + 'satellite_server' => $satellite_server, ]; if ($config['metaconsole_agent_cache'] == 1) { @@ -1230,6 +1233,7 @@ if ($id_agente) { $cps = $agent['cps']; $safe_mode_module = $agent['safe_mode_module']; $safe_mode = ($safe_mode_module) ? 1 : 0; + $satellite_server = (int) $agent['satellite_server']; } $update_module = (bool) get_parameter('update_module'); diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 26775a9315..57109fa837 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -265,6 +265,27 @@ if ($has_remote_conf) { ['class' => 'invert_filter'] ); $remote_cfg .= __('Remote configuration enabled').'

'; + + $satellite_server = (int) db_get_value_filter( + 'satellite_server', + 'tagente', + ['id_agente' => $id_agente] + ); + + if (empty($satellite_server) === false) { + $satellite_name = db_get_value_filter( + 'name', + 'tserver', + ['id_server' => $satellite_server] + ); + + $remote_cfg .= '

'.html_print_image( + 'images/satellite.png', + true, + ['class' => 'invert_filter'] + ); + $remote_cfg .= $satellite_name.'

'; + } } else { $remote_cfg = ''; } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 5550bc5413..100b83cf96 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -88,6 +88,7 @@ CREATE TABLE IF NOT EXISTS `tagente` ( `alias_as_name` TINYINT NOT NULL DEFAULT 0, `safe_mode_module` INT UNSIGNED NOT NULL DEFAULT 0, `cps` INT NOT NULL DEFAULT 0, + `satellite_server` INT NOT NULL DEFAULT 0, PRIMARY KEY (`id_agente`), KEY `nombre` (`nombre`(255)), KEY `direccion` (`direccion`), @@ -3468,6 +3469,7 @@ CREATE TABLE IF NOT EXISTS `tmetaconsole_agent` ( `alias_as_name` TINYINT NOT NULL DEFAULT 0, `safe_mode_module` INT UNSIGNED NOT NULL DEFAULT 0, `cps` INT NOT NULL DEFAULT 0, + `satellite_server` INT NOT NULL DEFAULT 0, PRIMARY KEY (`id_agente`), KEY `nombre` (`nombre`(255)), KEY `direccion` (`direccion`), 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 083fb77f8e..8d7a28a356 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) {