From fa7f519d3446a16b87bb4f623cf9dca2d4dfb765 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Tue, 12 Feb 2019 14:52:18 +0100 Subject: [PATCH] Merged from develop. Former-commit-id: 438c0bfa6cfa77ef0b75df02f3bce020122692b9 --- .../godmode/agentes/configurar_agente.php | 40 +++++---- .../godmode/massive/massive_edit_agents.php | 17 ++-- pandora_console/include/functions_modules.php | 86 ++++++++++--------- 3 files changed, 76 insertions(+), 67 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index c6a01fbe53..dfa28988a8 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -824,23 +824,25 @@ if ($update_agent) { ] ); - # Update the configuration files - if ($old_values['intervalo'] != $intervalo) { - enterprise_hook( - 'config_agents_update_config_token', - array($id_agente, 'interval', $intervalo) - ); - } - if ($old_values['disabled'] != $disabled) { - enterprise_hook( - 'config_agents_update_config_token', - array($id_agente, 'standby', $disabled ? "1" : "0") - ); - // Validate alerts for disabled agents. - if ($disabled) { - alerts_validate_alert_agent($id_agente); - } - } + if ($old_value === false) { + // Create custom field if not exist + $update_custom = db_process_sql_insert( + 'tagent_custom_data', + [ + 'id_field' => $key, + 'id_agent' => $id_agente, + 'description' => $value, + ] + ); + } else { + $update_custom = db_process_sql_update( + 'tagent_custom_data', + ['description' => $value], + [ + 'id_field' => $key, + 'id_agent' => $id_agente, + ] + ); if ($update_custom == 1) { $update_custom_result = 1; @@ -943,6 +945,10 @@ if ($update_agent) { $disabled ? '1' : '0', ] ); + // Validate alerts for disabled agents. + if ($disabled) { + alerts_validate_alert_agent($id_agente); + } } if ($tpolicy_group_old) { diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 0b449ac8db..2011eec564 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -63,16 +63,9 @@ if ($update_agents) { $values['intervalo'] = get_parameter('interval'); } - if ($disabled_old !== false && $disabled_old != $values['disabled']) { - enterprise_hook( - 'config_agents_update_config_token', - array($id_agent, 'standby', $values['disabled']) - ); - // Validate alerts for disabled agents. - if ($values['disabled'] == 1) { - alerts_validate_alert_agent($id_agent); - } - } + if (get_parameter('id_os', '') != -1) { + $values['id_os'] = get_parameter('id_os'); + } if (get_parameter('id_parent', '') != '') { $values['id_parent'] = get_parameter('id_agent_parent', 0); @@ -212,6 +205,10 @@ if ($update_agents) { $values['disabled'], ] ); + // Validate alerts for disabled agents. + if ($values['disabled'] == 1) { + alerts_validate_alert_agent($id_agent); + } } if ($group_old || $result) { diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index d14483d088..164660fc25 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -311,48 +311,54 @@ function modules_copy_agent_module_to_agent($id_agent_module, $id_destiny_agent, * * @return True if the module was disabled. False if not. */ -function modules_change_disabled($id_agent_module, $new_value = 1) { - $id_agent_module = (array) $id_agent_module; - - $id_agent_module_changed = array(); - - foreach ($id_agent_module as $id_module) { - // If the module is already disabled/enabled ignore - $current_disabled = db_get_value('disabled', 'tagente_modulo', - 'id_agente_modulo', $id_module); - if ($current_disabled == $new_value) { - continue; - } +function modules_change_disabled($id_agent_module, $new_value=1) +{ + $id_agent_module = (array) $id_agent_module; - // Validate alerts for disabled modules. - if ($new_value == 1) { - alerts_validate_alert_module($id_module); - } + $id_agent_module_changed = []; - $id_agent_changed[] = modules_get_agentmodule_agent($id_module); - $id_agent_module_changed[] = $id_module; - } - - if (empty($id_agent_module_changed)) { - return NOERR; - } - else { - $result = db_process_sql_update('tagente_modulo', - array('disabled' => (int) $new_value), - array('id_agente_modulo' => $id_agent_module_changed)); - } - - if ($result) { - // Change the agent flag to update modules count - db_process_sql_update('tagente', - array('update_module_count' => 1), - array('id_agente' => $id_agent_changed)); - - return NOERR; - } - else { - return ERR_GENERIC; - } + foreach ($id_agent_module as $id_module) { + // If the module is already disabled/enabled ignore + $current_disabled = db_get_value( + 'disabled', + 'tagente_modulo', + 'id_agente_modulo', + $id_module + ); + if ($current_disabled == $new_value) { + continue; + } + // Validate alerts for disabled modules. + if ($new_value == 1) { + alerts_validate_alert_module($id_module); + } + + $id_agent_changed[] = modules_get_agentmodule_agent($id_module); + $id_agent_module_changed[] = $id_module; + } + + if (empty($id_agent_module_changed)) { + return NOERR; + } else { + $result = db_process_sql_update( + 'tagente_modulo', + ['disabled' => (int) $new_value], + ['id_agente_modulo' => $id_agent_module_changed] + ); + } + + if ($result) { + // Change the agent flag to update modules count + db_process_sql_update( + 'tagente', + ['update_module_count' => 1], + ['id_agente' => $id_agent_changed] + ); + + return NOERR; + } else { + return ERR_GENERIC; + } }