Merge branch 'ent-8590-indicar-a-que-satelite-pertenece-un-agente' into 'develop'

Console changes for 8590

See merge request artica/pandorafms!4947
This commit is contained in:
Daniel Rodriguez 2022-06-20 15:11:42 +00:00
commit bf8cb56895
7 changed files with 84 additions and 4 deletions

View File

@ -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;

View File

@ -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
).'<div class="label_select_child_icons"></div></div></div>';
$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 = '<div class="label_select"><p class="input_label">'.__('Satellite').'</p>';
$table_satellite .= '<div class="label_select_parent">';
$table_satellite .= html_print_input(
[
'type' => 'select',
'fields' => $satellite_names,
'name' => 'satellite_server',
'selected' => $satellite_server,
'nothing' => __('None'),
'nothinf_value' => 0,
'return' => true,
]
).'<div class="label_select_child_icons"></div></div></div>';
}
}
// Description.
$table_description = '<div class="label_select"><p class="input_label">'.__('Description').'</p>';
$table_description .= html_print_textarea(
@ -443,7 +482,7 @@ $table_description .= html_print_textarea(
echo '<div class="first_row">
<div class="box-shadow agent_options '.$agent_options_update.' white_box">
<div class="agent_options_column_left">'.$table_agent_name.$table_alias.$table_ip.$table_primary_group.'</div>
<div class="agent_options_column_right">'.$table_interval.$table_os.$table_server.$table_description.'</div>
<div class="agent_options_column_right">'.$table_interval.$table_os.$table_server.$table_satellite.$table_description.'</div>
</div>';
if (!$new_agent && $alias != '') {
echo $table_qr_code;

View File

@ -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');

View File

@ -265,6 +265,27 @@ if ($has_remote_conf) {
['class' => 'invert_filter']
);
$remote_cfg .= __('Remote configuration enabled').'</p>';
$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 .= '<p>'.html_print_image(
'images/satellite.png',
true,
['class' => 'invert_filter']
);
$remote_cfg .= $satellite_name.'</p>';
}
} else {
$remote_cfg = '';
}

View File

@ -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`),

View File

@ -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);

View File

@ -453,6 +453,16 @@ sub process_xml_data ($$$$$) {
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.
# 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
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) {