mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
Remove service elements when removing items itselves and multiple fixes
This commit is contained in:
parent
a98a72354b
commit
70b8eb77a3
@ -500,7 +500,7 @@ if (enterprise_installed()) {
|
|||||||
false,
|
false,
|
||||||
// Delete_groups.
|
// Delete_groups.
|
||||||
// Do not show the primary group in this selection.
|
// Do not show the primary group in this selection.
|
||||||
array_merge($secondary_groups_selected['plain'], [$agent['id_grupo']])
|
array_merge(($secondary_groups_selected['plain'] ?? []), [$agent['id_grupo']])
|
||||||
// Include_groups.
|
// Include_groups.
|
||||||
// Size.
|
// Size.
|
||||||
// Simple_multiple_options.
|
// Simple_multiple_options.
|
||||||
|
@ -2095,106 +2095,8 @@ if ($delete_module) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
enterprise_include_once('include/functions_config_agents.php');
|
// Also call base function to delete modules madafakas de los cojones.
|
||||||
enterprise_hook('config_agents_delete_module_in_conf', [modules_get_agentmodule_agent($id_borrar_modulo), modules_get_agentmodule_name($id_borrar_modulo)]);
|
modules_delete_agent_module($id_borrar_modulo);
|
||||||
|
|
||||||
// Init transaction.
|
|
||||||
$error = 0;
|
|
||||||
|
|
||||||
// First delete from tagente_modulo -> if not successful, increment
|
|
||||||
// error. NOTICE that we don't delete all data here, just marking for deletion
|
|
||||||
// and delete some simple data.
|
|
||||||
$values = [
|
|
||||||
'nombre' => 'pendingdelete',
|
|
||||||
'disabled' => 1,
|
|
||||||
'delete_pending' => 1,
|
|
||||||
];
|
|
||||||
$result = db_process_sql_update(
|
|
||||||
'tagente_modulo',
|
|
||||||
$values,
|
|
||||||
['id_agente_modulo' => $id_borrar_modulo]
|
|
||||||
);
|
|
||||||
if ($result === false) {
|
|
||||||
$error++;
|
|
||||||
} else {
|
|
||||||
// Set flag to update module status count.
|
|
||||||
db_process_sql(
|
|
||||||
'UPDATE tagente
|
|
||||||
SET update_module_count = 1, update_alert_count = 1
|
|
||||||
WHERE id_agente = '.$module_data['id_agente']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = db_process_sql_delete(
|
|
||||||
'tagente_estado',
|
|
||||||
['id_agente_modulo' => $id_borrar_modulo]
|
|
||||||
);
|
|
||||||
if ($result === false) {
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = db_process_sql_delete(
|
|
||||||
'tagente_datos_inc',
|
|
||||||
['id_agente_modulo' => $id_borrar_modulo]
|
|
||||||
);
|
|
||||||
if ($result === false) {
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alerts_delete_alert_agent_module(
|
|
||||||
false,
|
|
||||||
['id_agent_module' => $id_borrar_modulo]
|
|
||||||
) === false
|
|
||||||
) {
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = db_process_delete_temp(
|
|
||||||
'ttag_module',
|
|
||||||
'id_agente_modulo',
|
|
||||||
$id_borrar_modulo
|
|
||||||
);
|
|
||||||
if ($result === false) {
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trick to detect if we are deleting a synthetic module (avg or arithmetic)
|
|
||||||
// If result is empty then module doesn't have this type of submodules.
|
|
||||||
$ops_json = enterprise_hook('modules_get_synthetic_operations', [$id_borrar_modulo]);
|
|
||||||
$result_ops_synthetic = json_decode($ops_json);
|
|
||||||
if (!empty($result_ops_synthetic)) {
|
|
||||||
$result = enterprise_hook('modules_delete_synthetic_operations', [$id_borrar_modulo]);
|
|
||||||
if ($result === false) {
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$result_components = enterprise_hook('modules_get_synthetic_components', [$id_borrar_modulo]);
|
|
||||||
$count_components = 1;
|
|
||||||
if (!empty($result_components)) {
|
|
||||||
// Get number of components pending to delete to know when it's needed to update orders.
|
|
||||||
$num_components = count($result_components);
|
|
||||||
$last_target_module = 0;
|
|
||||||
foreach ($result_components as $id_target_module) {
|
|
||||||
// Detects change of component or last component to update orders.
|
|
||||||
if (($count_components == $num_components)
|
|
||||||
|| ($last_target_module != $id_target_module)
|
|
||||||
) {
|
|
||||||
$update_orders = true;
|
|
||||||
} else {
|
|
||||||
$update_orders = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = enterprise_hook('modules_delete_synthetic_operations', [$id_target_module, $id_borrar_modulo, $update_orders]);
|
|
||||||
|
|
||||||
if ($result === false) {
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$count_components++;
|
|
||||||
$last_target_module = $id_target_module;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for errors.
|
// Check for errors.
|
||||||
if ($error != 0) {
|
if ($error != 0) {
|
||||||
|
@ -36,6 +36,7 @@ include_javascript_d3();
|
|||||||
|
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
|
||||||
function prepend_table_simple($row, $id=false)
|
function prepend_table_simple($row, $id=false)
|
||||||
{
|
{
|
||||||
global $table_simple;
|
global $table_simple;
|
||||||
@ -598,8 +599,12 @@ if ($moduletype == MODULE_DATA) {
|
|||||||
$table_advanced->colspan[1][1] = 2;
|
$table_advanced->colspan[1][1] = 2;
|
||||||
$interval_factor = 1;
|
$interval_factor = 1;
|
||||||
if (isset($id_agente)) {
|
if (isset($id_agente)) {
|
||||||
$agent_interval = agents_get_interval($id_agente);
|
$agent_interval = (float) agents_get_interval($id_agente);
|
||||||
|
if ($agent_interval > 0) {
|
||||||
|
$interval = (float) $interval;
|
||||||
$interval_factor = ($interval / $agent_interval);
|
$interval_factor = ($interval / $agent_interval);
|
||||||
|
}
|
||||||
|
|
||||||
$table_advanced->data[1][1] = human_time_description_raw($interval).' ('.sprintf(__('Agent interval x %s'), $interval_factor).') ';
|
$table_advanced->data[1][1] = human_time_description_raw($interval).' ('.sprintf(__('Agent interval x %s'), $interval_factor).') ';
|
||||||
} else {
|
} else {
|
||||||
$table_advanced->data[1][1] = sprintf(__('Agent interval x %s'), $interval_factor);
|
$table_advanced->data[1][1] = sprintf(__('Agent interval x %s'), $interval_factor);
|
||||||
|
@ -2417,6 +2417,30 @@ function agents_delete_agent($id_agents, $disableACL=false)
|
|||||||
$id_agent
|
$id_agent
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Process a controlled module ellimination, keeping the old behaviour
|
||||||
|
// a couple of lines below this section.
|
||||||
|
try {
|
||||||
|
$filter = ['id_agente' => $id_agent];
|
||||||
|
$modules = [];
|
||||||
|
$rows = \db_get_all_rows_filter(
|
||||||
|
'tagente_modulo',
|
||||||
|
$filter
|
||||||
|
);
|
||||||
|
|
||||||
|
if (is_array($rows) === true) {
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$modules[] = PandoraFMS\Module::build($row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
$module->delete();
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Ignore.
|
||||||
|
error_log($e->getMessage().' in '.$e->getFile().':'.$e->getLine());
|
||||||
|
}
|
||||||
|
|
||||||
// The status of the module
|
// The status of the module
|
||||||
db_process_delete_temp('tagente_estado', 'id_agente', $id_agent);
|
db_process_delete_temp('tagente_estado', 'id_agente', $id_agent);
|
||||||
|
|
||||||
@ -2456,6 +2480,7 @@ function agents_delete_agent($id_agents, $disableACL=false)
|
|||||||
$target_filter
|
$target_filter
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (is_array($commands) === true) {
|
||||||
foreach ($commands as $command) {
|
foreach ($commands as $command) {
|
||||||
$rcmd_id = $command['rcmd_id'];
|
$rcmd_id = $command['rcmd_id'];
|
||||||
$rcmd = new RCMDFile($rcmd_id);
|
$rcmd = new RCMDFile($rcmd_id);
|
||||||
@ -2467,6 +2492,17 @@ function agents_delete_agent($id_agents, $disableACL=false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove agents from service child list.
|
||||||
|
enterprise_include_once('include/functions_services.php');
|
||||||
|
\enterprise_hook(
|
||||||
|
'service_elements_removal_tool',
|
||||||
|
[
|
||||||
|
$id_agent,
|
||||||
|
SERVICE_ELEMENT_AGENT,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// tagente_datos_inc
|
// tagente_datos_inc
|
||||||
// Dont delete here, this records are deleted later, in database script
|
// Dont delete here, this records are deleted later, in database script
|
||||||
// db_process_delete_temp ("tagente_datos_inc", "id_agente_modulo", $where_modules, true);
|
// db_process_delete_temp ("tagente_datos_inc", "id_agente_modulo", $where_modules, true);
|
||||||
|
@ -524,10 +524,13 @@ function io_json_mb_encode($string, $encode_options=0)
|
|||||||
$v = json_encode($string, $encode_options);
|
$v = json_encode($string, $encode_options);
|
||||||
$v = preg_replace_callback(
|
$v = preg_replace_callback(
|
||||||
"/\\\\u([0-9a-zA-Z]{4})/",
|
"/\\\\u([0-9a-zA-Z]{4})/",
|
||||||
create_function(
|
function ($matches) {
|
||||||
'$matches',
|
return mb_convert_encoding(
|
||||||
'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UTF-16");'
|
pack('H*', $matches[1]),
|
||||||
),
|
'UTF-8',
|
||||||
|
'UTF-16'
|
||||||
|
);
|
||||||
|
},
|
||||||
$v
|
$v
|
||||||
);
|
);
|
||||||
$v = preg_replace('/\\\\\//', '/', $v);
|
$v = preg_replace('/\\\\\//', '/', $v);
|
||||||
|
@ -387,7 +387,7 @@ function modules_change_disabled($id_agent_module, $new_value=1)
|
|||||||
*
|
*
|
||||||
* @param mixed Agent module id to be deleted. Accepts an array with ids.
|
* @param mixed Agent module id to be deleted. Accepts an array with ids.
|
||||||
*
|
*
|
||||||
* @return True if the module was deleted. False if not.
|
* @return boolean True if the module was deleted. False if not.
|
||||||
*/
|
*/
|
||||||
function modules_delete_agent_module($id_agent_module)
|
function modules_delete_agent_module($id_agent_module)
|
||||||
{
|
{
|
||||||
@ -455,6 +455,16 @@ function modules_delete_agent_module($id_agent_module)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove module from service child list.
|
||||||
|
enterprise_include_once('include/functions_services.php');
|
||||||
|
\enterprise_hook(
|
||||||
|
'service_elements_removal_tool',
|
||||||
|
[
|
||||||
|
$id_agent_module,
|
||||||
|
SERVICE_ELEMENT_MODULE,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
alerts_delete_alert_agent_module(0, $where);
|
alerts_delete_alert_agent_module(0, $where);
|
||||||
|
|
||||||
db_process_sql_delete('tgraph_source', $where);
|
db_process_sql_delete('tgraph_source', $where);
|
||||||
@ -477,6 +487,130 @@ function modules_delete_agent_module($id_agent_module)
|
|||||||
);
|
);
|
||||||
db_process_sql_delete('ttag_module', $where);
|
db_process_sql_delete('ttag_module', $where);
|
||||||
|
|
||||||
|
$id_borrar_modulo = $id_agent_module;
|
||||||
|
|
||||||
|
enterprise_include_once('include/functions_config_agents.php');
|
||||||
|
enterprise_hook(
|
||||||
|
'config_agents_delete_module_in_conf',
|
||||||
|
[
|
||||||
|
modules_get_agentmodule_agent($id_borrar_modulo),
|
||||||
|
modules_get_agentmodule_name($id_borrar_modulo),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Init transaction.
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
|
// First delete from tagente_modulo -> if not successful, increment
|
||||||
|
// error. NOTICE that we don't delete all data here, just marking for deletion
|
||||||
|
// and delete some simple data.
|
||||||
|
$values = [
|
||||||
|
'nombre' => 'pendingdelete',
|
||||||
|
'disabled' => 1,
|
||||||
|
'delete_pending' => 1,
|
||||||
|
];
|
||||||
|
$result = db_process_sql_update(
|
||||||
|
'tagente_modulo',
|
||||||
|
$values,
|
||||||
|
['id_agente_modulo' => $id_borrar_modulo]
|
||||||
|
);
|
||||||
|
if ($result === false) {
|
||||||
|
$error++;
|
||||||
|
} else {
|
||||||
|
// Set flag to update module status count.
|
||||||
|
db_process_sql(
|
||||||
|
'UPDATE tagente
|
||||||
|
SET update_module_count = 1, update_alert_count = 1
|
||||||
|
WHERE id_agente = '.$id_agent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = db_process_sql_delete(
|
||||||
|
'tagente_estado',
|
||||||
|
['id_agente_modulo' => $id_borrar_modulo]
|
||||||
|
);
|
||||||
|
if ($result === false) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = db_process_sql_delete(
|
||||||
|
'tagente_datos_inc',
|
||||||
|
['id_agente_modulo' => $id_borrar_modulo]
|
||||||
|
);
|
||||||
|
if ($result === false) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alerts_delete_alert_agent_module(
|
||||||
|
false,
|
||||||
|
['id_agent_module' => $id_borrar_modulo]
|
||||||
|
) === false
|
||||||
|
) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = db_process_delete_temp(
|
||||||
|
'ttag_module',
|
||||||
|
'id_agente_modulo',
|
||||||
|
$id_borrar_modulo
|
||||||
|
);
|
||||||
|
if ($result === false) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trick to detect if we are deleting a synthetic module (avg or arithmetic)
|
||||||
|
// If result is empty then module doesn't have this type of submodules.
|
||||||
|
$ops_json = enterprise_hook(
|
||||||
|
'modules_get_synthetic_operations',
|
||||||
|
[$id_borrar_modulo]
|
||||||
|
);
|
||||||
|
$result_ops_synthetic = json_decode($ops_json);
|
||||||
|
if (!empty($result_ops_synthetic)) {
|
||||||
|
$result = enterprise_hook(
|
||||||
|
'modules_delete_synthetic_operations',
|
||||||
|
[$id_borrar_modulo]
|
||||||
|
);
|
||||||
|
if ($result === false) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result_components = enterprise_hook(
|
||||||
|
'modules_get_synthetic_components',
|
||||||
|
[$id_borrar_modulo]
|
||||||
|
);
|
||||||
|
$count_components = 1;
|
||||||
|
if (!empty($result_components)) {
|
||||||
|
// Get number of components pending to delete to know when it's needed to update orders.
|
||||||
|
$num_components = count($result_components);
|
||||||
|
$last_target_module = 0;
|
||||||
|
foreach ($result_components as $id_target_module) {
|
||||||
|
$update_orders = false;
|
||||||
|
// Detects change of component or last component to update orders.
|
||||||
|
if (($count_components == $num_components)
|
||||||
|
|| ($last_target_module != $id_target_module)
|
||||||
|
) {
|
||||||
|
$update_orders = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = enterprise_hook(
|
||||||
|
'modules_delete_synthetic_operations',
|
||||||
|
[
|
||||||
|
$id_target_module,
|
||||||
|
$id_borrar_modulo,
|
||||||
|
$update_orders,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($result === false) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$count_components++;
|
||||||
|
$last_target_module = $id_target_module;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,6 +588,13 @@ class Agent extends Entity
|
|||||||
$this->fields['id_agente']
|
$this->fields['id_agente']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Delete modules.
|
||||||
|
if ($this->modules !== null) {
|
||||||
|
foreach ($this->modules as $module) {
|
||||||
|
$module->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unset($this->fields);
|
unset($this->fields);
|
||||||
unset($this->modules);
|
unset($this->modules);
|
||||||
}
|
}
|
||||||
|
@ -1325,7 +1325,14 @@ $agent_interfaces = agents_get_network_interfaces(
|
|||||||
['id_agente' => $id_agente]
|
['id_agente' => $id_agente]
|
||||||
);
|
);
|
||||||
|
|
||||||
$agent_interfaces_count = count($agent_interfaces[$id_agente]['interfaces']);
|
if (is_array($agent_interfaces[$id_agente]['interfaces']) !== true
|
||||||
|
|| is_object($agent_interfaces[$id_agente]['interfaces']) !== true
|
||||||
|
) {
|
||||||
|
$agent_interfaces_count = 0;
|
||||||
|
} else {
|
||||||
|
$agent_interfaces_count = count($agent_interfaces[$id_agente]['interfaces']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($agent_interfaces_count > 0) {
|
if ($agent_interfaces_count > 0) {
|
||||||
$interfacetab['text'] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&tab=interface">'.html_print_image(
|
$interfacetab['text'] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&tab=interface">'.html_print_image(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user