Merged from develop.

Former-commit-id: 438c0bfa6cfa77ef0b75df02f3bce020122692b9
This commit is contained in:
Ramon Novoa 2019-02-12 14:52:18 +01:00
parent 6e236c404b
commit fa7f519d34
3 changed files with 76 additions and 67 deletions

View File

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

View File

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

View File

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