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_value === false) {
if ($old_values['intervalo'] != $intervalo) { // Create custom field if not exist
enterprise_hook( $update_custom = db_process_sql_insert(
'config_agents_update_config_token', 'tagent_custom_data',
array($id_agente, 'interval', $intervalo) [
); 'id_field' => $key,
} 'id_agent' => $id_agente,
if ($old_values['disabled'] != $disabled) { 'description' => $value,
enterprise_hook( ]
'config_agents_update_config_token', );
array($id_agente, 'standby', $disabled ? "1" : "0") } else {
); $update_custom = db_process_sql_update(
// Validate alerts for disabled agents. 'tagent_custom_data',
if ($disabled) { ['description' => $value],
alerts_validate_alert_agent($id_agente); [
} 'id_field' => $key,
} 'id_agent' => $id_agente,
]
);
if ($update_custom == 1) { if ($update_custom == 1) {
$update_custom_result = 1; $update_custom_result = 1;
@ -943,6 +945,10 @@ if ($update_agent) {
$disabled ? '1' : '0', $disabled ? '1' : '0',
] ]
); );
// Validate alerts for disabled agents.
if ($disabled) {
alerts_validate_alert_agent($id_agente);
}
} }
if ($tpolicy_group_old) { if ($tpolicy_group_old) {

View File

@ -63,16 +63,9 @@ if ($update_agents) {
$values['intervalo'] = get_parameter('interval'); $values['intervalo'] = get_parameter('interval');
} }
if ($disabled_old !== false && $disabled_old != $values['disabled']) { if (get_parameter('id_os', '') != -1) {
enterprise_hook( $values['id_os'] = get_parameter('id_os');
'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_parent', '') != '') { if (get_parameter('id_parent', '') != '') {
$values['id_parent'] = get_parameter('id_agent_parent', 0); $values['id_parent'] = get_parameter('id_agent_parent', 0);
@ -212,6 +205,10 @@ if ($update_agents) {
$values['disabled'], $values['disabled'],
] ]
); );
// Validate alerts for disabled agents.
if ($values['disabled'] == 1) {
alerts_validate_alert_agent($id_agent);
}
} }
if ($group_old || $result) { 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. * @return True if the module was disabled. False if not.
*/ */
function modules_change_disabled($id_agent_module, $new_value = 1) { function modules_change_disabled($id_agent_module, $new_value=1)
$id_agent_module = (array) $id_agent_module; {
$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;
}
// Validate alerts for disabled modules. $id_agent_module_changed = [];
if ($new_value == 1) {
alerts_validate_alert_module($id_module);
}
$id_agent_changed[] = modules_get_agentmodule_agent($id_module); foreach ($id_agent_module as $id_module) {
$id_agent_module_changed[] = $id_module; // If the module is already disabled/enabled ignore
} $current_disabled = db_get_value(
'disabled',
if (empty($id_agent_module_changed)) { 'tagente_modulo',
return NOERR; 'id_agente_modulo',
} $id_module
else { );
$result = db_process_sql_update('tagente_modulo', if ($current_disabled == $new_value) {
array('disabled' => (int) $new_value), continue;
array('id_agente_modulo' => $id_agent_module_changed)); }
} // Validate alerts for disabled modules.
if ($new_value == 1) {
if ($result) { alerts_validate_alert_module($id_module);
// Change the agent flag to update modules count }
db_process_sql_update('tagente',
array('update_module_count' => 1), $id_agent_changed[] = modules_get_agentmodule_agent($id_module);
array('id_agente' => $id_agent_changed)); $id_agent_module_changed[] = $id_module;
}
return NOERR;
} if (empty($id_agent_module_changed)) {
else { return NOERR;
return ERR_GENERIC; } 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;
}
} }