From 5297123d170e673f787691a5334ee309491ceb52 Mon Sep 17 00:00:00 2001 From: Calvo Date: Wed, 8 Jun 2022 13:10:01 +0200 Subject: [PATCH 1/4] Console changes for 8950 --- pandora_console/extras/mr/55.sql | 4 ++ .../pandoradb_migrate_6.0_to_759.mysql.sql | 2 + .../godmode/agentes/agent_manager.php | 41 ++++++++++++++++++- .../godmode/agentes/configurar_agente.php | 4 ++ .../agentes/estado_generalagente.php | 21 ++++++++++ pandora_console/pandoradb.sql | 2 + 6 files changed, 73 insertions(+), 1 deletion(-) diff --git a/pandora_console/extras/mr/55.sql b/pandora_console/extras/mr/55.sql index f53133c456..3da77ea7c0 100644 --- a/pandora_console/extras/mr/55.sql +++ b/pandora_console/extras/mr/55.sql @@ -4,4 +4,8 @@ ALTER TABLE `tservice` ADD COLUMN `enable_sunburst` tinyint(1) NOT NULL default 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; + COMMIT; + diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql index ca68a5472a..73203c82e9 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql @@ -1660,6 +1660,8 @@ ALTER TABLE tagente ADD COLUMN (alias varchar(600) not null default ''); ALTER TABLE tagente ADD `alias_as_name` int(2) unsigned default '0'; ALTER TABLE tagente ADD COLUMN `safe_mode_module` int(10) unsigned NOT NULL default '0'; ALTER TABLE `tagente` ADD COLUMN `cps` int NOT NULL default 0; +ALTER TABLE `tagente` ADD COLUMN `satellite_server` INT NOT NULL DEFAULT 0; + UPDATE tagente SET tagente.alias = tagente.nombre; diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index d1246b298c..afe6a3cfeb 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..86597dae79 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 server: ').$satellite_name.'

'; + } } else { $remote_cfg = ''; } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index ebd940c749..6aa9f990e3 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`), From 5e33df93ac72cee946416520a342b93c0f72f7af Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Thu, 9 Jun 2022 13:29:43 +0200 Subject: [PATCH 2/4] 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) { From 5ce0ebb72a6499e564de24b52e8392ea2e33597b Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 17 Jun 2022 10:09:37 +0200 Subject: [PATCH 3/4] Fix agent view satellite name visual --- pandora_console/operation/agentes/estado_generalagente.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 86597dae79..57109fa837 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -284,7 +284,7 @@ if ($has_remote_conf) { true, ['class' => 'invert_filter'] ); - $remote_cfg .= __('Satellite server: ').$satellite_name.'

'; + $remote_cfg .= $satellite_name.'

'; } } else { $remote_cfg = ''; From 71326bf8bbe1914f4f0245d9b7f763066ba99eee Mon Sep 17 00:00:00 2001 From: Luis Date: Mon, 20 Jun 2022 14:57:45 +0000 Subject: [PATCH 4/4] Update pandoradb_migrate_6.0_to_759.mysql.sql --- pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql index 73203c82e9..ca68a5472a 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql @@ -1660,8 +1660,6 @@ ALTER TABLE tagente ADD COLUMN (alias varchar(600) not null default ''); ALTER TABLE tagente ADD `alias_as_name` int(2) unsigned default '0'; ALTER TABLE tagente ADD COLUMN `safe_mode_module` int(10) unsigned NOT NULL default '0'; ALTER TABLE `tagente` ADD COLUMN `cps` int NOT NULL default 0; -ALTER TABLE `tagente` ADD COLUMN `satellite_server` INT NOT NULL DEFAULT 0; - UPDATE tagente SET tagente.alias = tagente.nombre;