Fixed the lost config data in modules from policy when update something in the module. TICKET: #1874

This commit is contained in:
mdtrooper 2015-03-04 14:55:44 +01:00
parent b79d572959
commit 50bbdf5590
1 changed files with 19 additions and 11 deletions

View File

@ -781,6 +781,8 @@ $edit_module = (bool) get_parameter ('edit_module');
if ($update_module || $create_module) {
$id_grupo = agents_get_agent_group ($id_agente);
$id_agent_module = (int) get_parameter ('id_agent_module');
if (!check_acl ($config["id_user"], $id_grupo, "AW")) {
db_pandora_audit("ACL Violation",
"Trying to create a module without admin rights");
@ -855,8 +857,8 @@ if ($update_module || $create_module) {
$macros = io_json_mb_encode($macros);
$conf_array = explode("\n",$configuration_data);
foreach($conf_array as $line) {
if(preg_match("/^module_name\s*(.*)/", $line, $match)) {
foreach ($conf_array as $line) {
if (preg_match("/^module_name\s*(.*)/", $line, $match)) {
$new_configuration_data .= "module_name $name\n";
}
// We delete from conf all the module macros starting with _field
@ -867,7 +869,7 @@ if ($update_module || $create_module) {
$macros_for_data = enterprise_hook('config_agents_get_macros_data_conf', array($_POST));
if($macros_for_data !== ENTERPRISE_NOT_HOOK && $macros_for_data != '') {
if ($macros_for_data !== ENTERPRISE_NOT_HOOK && $macros_for_data != '') {
// Add macros to configuration file
$new_configuration_data = str_replace('module_end', $macros_for_data."module_end", $new_configuration_data);
}
@ -947,9 +949,10 @@ if ($update_module || $create_module) {
$wday = get_parameter('wday');
$cron_interval = "$minute $hour $mday $month $wday";
if ($prediction_module != 3) {
if ($prediction_module != MODULE_PREDICTION_SYNTHETIC) {
unset($serialize_ops);
enterprise_hook('modules_delete_synthetic_operations', array($id_agent_module));
enterprise_hook('modules_delete_synthetic_operations',
array($id_agent_module));
}
$active_snmp_v3 = get_parameter('active_snmp_v3');
@ -968,8 +971,11 @@ if ($update_module || $create_module) {
// Make changes in the conf file if necessary
enterprise_include_once('include/functions_config_agents.php');
if (!policies_is_module_in_policy($id_agent_module)) {
enterprise_hook('config_agents_write_module_in_conf',
array($id_agente, io_safe_output($old_configuration_data), io_safe_output($configuration_data), $disabled));
array($id_agente, io_safe_output($old_configuration_data),
io_safe_output($configuration_data), $disabled));
}
}
// MODULE UPDATE
@ -1038,7 +1044,9 @@ if ($update_module) {
unset($values['module_interval']);
}
if ($prediction_module == 3 && $serialize_ops == '') {
if ($prediction_module == MODULE_PREDICTION_SYNTHETIC &&
$serialize_ops == '') {
$result = false;
}
else {
@ -1069,7 +1077,7 @@ if ($update_module) {
$edit_module = true;
db_pandora_audit("Agent management",
"Fail to try update module '$name' for agent ".$agent["nombre"]);
"Fail to try update module '$name' for agent " . $agent["nombre"]);
}
else {
if ($prediction_module == 3) {