fixed error create modules

This commit is contained in:
Daniel Barbero Martin 2019-05-27 15:27:46 +02:00
parent 36a12d16be
commit bc64589046
1 changed files with 39 additions and 32 deletions

View File

@ -1428,32 +1428,11 @@ if ($update_module || $create_module) {
$module_in_policy = enterprise_hook('policies_is_module_in_policy', [$id_agent_module]); $module_in_policy = enterprise_hook('policies_is_module_in_policy', [$id_agent_module]);
$module_linked = enterprise_hook('policies_is_module_linked', [$id_agent_module]); $module_linked = enterprise_hook('policies_is_module_linked', [$id_agent_module]);
if ((!$module_in_policy && !$module_linked && $update_module)
|| ( $module_in_policy && !$module_linked && $update_module)
) {
enterprise_hook(
'config_agents_update_module_in_conf',
[
$id_agente,
io_safe_output($old_configuration_data),
io_safe_output($configuration_data),
$disabled,
]
);
} else {
enterprise_hook(
'config_agents_write_module_in_conf',
[
$id_agente,
io_safe_output($old_configuration_data),
io_safe_output($configuration_data),
$disabled,
]
);
}
} }
// Initialize result of the action (insert or update).
$success_action = NOERR;
// MODULE UPDATE. // MODULE UPDATE.
if ($update_module) { if ($update_module) {
$id_agent_module = (int) get_parameter('id_agent_module'); $id_agent_module = (int) get_parameter('id_agent_module');
@ -1589,6 +1568,8 @@ if ($update_module) {
break; break;
} }
// I save the result of the action (insert or update).
$success_action = $result;
$result = false; $result = false;
ui_print_error_message($msg); ui_print_error_message($msg);
@ -1630,6 +1611,9 @@ if ($update_module) {
// MODULE INSERT. // MODULE INSERT.
if ($create_module) { if ($create_module) {
// Old configuration data must always be empty in case of creation.
$old_configuration_data = '';
if (isset($_POST['combo_snmp_oid'])) { if (isset($_POST['combo_snmp_oid'])) {
$combo_snmp_oid = get_parameter_post('combo_snmp_oid'); $combo_snmp_oid = get_parameter_post('combo_snmp_oid');
} }
@ -1639,12 +1623,6 @@ if ($create_module) {
} }
$id_module = (int) get_parameter('id_module'); $id_module = (int) get_parameter('id_module');
// Commented because can't create prediction modules
/*
if ($id_module == 5) {
$prediction_module = 1;
}
*/
switch ($config['dbtype']) { switch ($config['dbtype']) {
case 'oracle': case 'oracle':
@ -1768,17 +1746,26 @@ if ($create_module) {
break; break;
} }
// I save the result of the action (insert or update).
$success_action = $id_agent_module;
$id_agent_module = false; $id_agent_module = false;
ui_print_error_message($msg); ui_print_error_message($msg);
$edit_module = true; $edit_module = true;
$moduletype = $id_module; $moduletype = $id_module;
db_pandora_audit( db_pandora_audit(
'Agent management', 'Agent management',
"Fail to try added module '$name' for agent ".$agent['alias'] 'Fail to try added module '.$name.' for agent '.$agent['alias']
); );
} else { } else {
if ($prediction_module == 3) { if ($prediction_module == 3) {
enterprise_hook('modules_create_synthetic_operations', [$id_agent_module, $serialize_ops]); enterprise_hook(
'modules_create_synthetic_operations',
[
$id_agent_module,
$serialize_ops,
]
);
} }
// Update the module interval. // Update the module interval.
@ -1801,6 +1788,26 @@ if ($create_module) {
} }
} }
// Fix to stop the module from being added to the agent's conf
// when an error occurred while updating or inserting.
if ($update_module || $create_module) {
if ((!$module_in_policy && !$module_linked)
|| ($module_in_policy && !$module_linked)
) {
if ($success_action > 0) {
enterprise_hook(
'config_agents_write_module_in_conf',
[
$id_agente,
io_safe_output($old_configuration_data),
io_safe_output($configuration_data),
$disabled,
]
);
}
}
}
// MODULE DELETION // MODULE DELETION
// =================. // =================.
if ($delete_module) { if ($delete_module) {