#9783 Fixed networkmap

This commit is contained in:
Daniel Maya 2022-12-07 15:54:40 +01:00
parent 4f194134cc
commit 3351b6b9bd
1 changed files with 49 additions and 286 deletions

View File

@ -4159,6 +4159,53 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y)
if ((int) $networkmap['source'] === SOURCE_TASK) {
$agents = get_discovery_agents($id_recon, true);
$relations_discovery = modules_get_relations(['id_rt' => $id_recon, 'distinct' => true]);
$relations_maps = db_get_all_rows_sql(
sprintf(
'SELECT * FROM trel_item WHERE id_map = %s AND parent_type = 1 AND child_type = 1',
$id_networkmap
)
);
$id_recon = $id_networkmap;
foreach ($relations_discovery as $key => $discovery) {
foreach ($relations_maps as $key2 => $map) {
if ($map['id_parent_source_data'] == $discovery['module_a']
&& $map['id_child_source_data'] == $discovery['module_b']
) {
hd('entra y borra', true);
unset($relations_discovery[$key]);
unset($relations_maps[$key2]);
continue 2;
} else if ($map['id_parent_source_data'] == $discovery['module_b']
&& $map['id_child_source_data'] == $discovery['module_a']
) {
hd('entra y borra 2', true);
unset($relations_discovery[$key]);
unset($relations_maps[$key2]);
continue 2;
}
}
}
foreach ($relations_discovery as $key => $value) {
// db_process_sql_insert(
// 'trel_item',
// [
// 'id_map' => $id_networkmap,
// 'id_parent' => $parent_node,
// 'id_child' => $child_node,
// 'id_parent_source_data' => $parent,
// 'id_child_source_data' => $node['source_data'],
// 'parent_type' => 0,
// 'child_type' => 0,
// ]
// );
}
hd($relations_discovery, true);
} else if ((int) $networkmap['source'] === SOURCE_NETWORK) {
// Network map, based on direct network.
$agents = networkmap_get_nodes_from_ip_mask(
@ -4267,6 +4314,8 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y)
GROUP BY source_data';
$nodes = db_get_all_rows_sql($sql);
hd($nodes, true);
foreach ($nodes as $node) {
// First the relation parents without l2 interfaces.
$parent = db_get_value_filter(
@ -4372,280 +4421,6 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y)
}
}
// foreach ($interfaces as $interface) {
// $relations = modules_get_relations(
// ['id_module' => $interface['id_agente_modulo']]
// );
// if (empty($relations) === true) {
// $relations = [];
// }
// foreach ($relations as $relation) {
// Get the links althought they are deleted (for to
// avoid to add)
// Check if the module is ping.
// if (modules_get_agentmodule_type($relation['module_a']) === '6') {
// The pings modules are not exist as interface
// the link is with the agent.
// $node_a = db_get_value_filter(
// 'id',
// 'titem',
// [
// 'source_data' => modules_get_agentmodule_agent(
// $relation['module_a']
// ),
// 'id_map' => $id_networkmap,
// ]
// );
// } else {
// $node_a = db_get_value_filter(
// 'id',
// 'titem',
// [
// 'source_data' => $relation['module_a'],
// 'type' => 1,
// 'id_map' => $id_networkmap,
// ]
// );
// }
// Check if the module is ping.
// if (modules_get_agentmodule_type($relation['module_b']) == 6) {
// The pings modules are not exist as interface
// the link is with the agent.
// $node_b = db_get_value_filter(
// 'id',
// 'titem',
// [
// 'source_data' => modules_get_agentmodule_agent(
// $relation['module_b']
// ),
// 'id_map' => $id_networkmap,
// ]
// );
// } else {
// $node_b = db_get_value_filter(
// 'id',
// 'titem',
// [
// 'source_data' => $relation['module_b'],
// 'type' => 1,
// 'id_map' => $id_networkmap,
// ]
// );
// }
// $exist = db_get_row_filter(
// 'trel_item',
// [
// 'id_map' => $id_networkmap,
// 'id_parent_source_data' => $relation['module_a'],
// 'id_child_source_data' => $relation['module_b'],
// 'deleted' => 0,
// ]
// );
// $exist_reverse = db_get_row_filter(
// 'trel_item',
// [
// 'id_map' => $id_networkmap,
// 'id_parent_source_data' => $relation['module_b'],
// 'id_child_source_data' => $relation['module_a'],
// 'deleted' => 0,
// ]
// );
// if (empty($exist) && empty($exist_reverse)) {
// Create the nodes for interfaces
// Ag1 ----- I1 ------ I2 ----- Ag2
// * 2 interfaces nodes
// * 3 relations
// * I1 between I2
// * Ag1 between I1
// * Ag2 between I2
//
// But check if it exists the relations
// agent between interface.
// if ($interface['id_agente_modulo'] == $relation['module_a']) {
// $agent_a = $interface['id_agente'];
// $agent_b = modules_get_agentmodule_agent(
// $relation['module_b']
// );
// } else {
// $agent_a = modules_get_agentmodule_agent(
// $relation['module_a']
// );
// $agent_b = $interface['id_agente'];
// }
// $item_a = db_get_value(
// 'id',
// 'titem',
// 'source_data',
// $agent_a
// );
// $item_b = db_get_value(
// 'id',
// 'titem',
// 'source_data',
// $agent_b
// );
// hd('----------------------', true);
// hd($agent_a, true);
// hd($agent_b, true);
// foreach ($interfaces as $interface) {
// $relations = modules_get_relations(
// ['id_module' => $interface['id_agente_modulo']]
// );
// if (empty($relations) === true) {
// $relations = [];
// }
// foreach ($relations as $relation) {hd($item_a. '<->'. $item_b, true);
// hd('----------------------', true);
// continue;
// $exist_node_interface1 = db_get_row_filter(
// 'titem',
// [
// 'id_map' => $id_networkmap,
// 'type' => 0,
// 'source_data' => $relation['module_a'],
// ]
// );
// if (empty($exist_node_interface1) === true) {
// Crete the interface node
// and create the relation between agent and
// interface.
// $style = [];
// $style['id_agent'] = $agent_a;
// $style['shape'] = 'circle';
// $style['image'] = 'images/mod_snmp_proc.png';
// $style['width'] = 50;
// $style['height'] = 16;
// $style['label'] = modules_get_agentmodule_name($relation['module_a']);
// $id_int1 = db_process_sql_insert(
// 'titem',
// [
// 'id_map' => $id_networkmap,
// 'x' => 666,
// 'y' => 666,
// 'z' => 0,
// 'deleted' => 0,
// 'type' => 1,
// 'refresh' => 0,
// 'source' => 0,
// 'source_data' => $relation['module_a'],
// 'style' => json_encode($style),
// ]
// );
// $node_interface1 = db_get_row_filter(
// 'titem',
// [
// 'id_map' => $id_networkmap,
// 'type' => 1,
// 'id' => $id_int1,
// ]
// );
// $node_agent1 = db_get_value(
// 'id',
// 'titem',
// 'source_data',
// $agent_a
// );
// db_process_sql_insert(
// 'trel_item',
// [
// 'id_map' => $id_networkmap,
// 'id_parent' => $node_agent1,
// 'id_child' => $node_interface1,
// 'id_parent-source_data' => $agent_a,
// 'id_child-source_data' => $relation['module_a'],
// 'parent_type' => 0,
// 'child_type' => 1,
// ]
// );
// } else {
// $node_interface1 = $exist_node_interface1;
// }
// $exist_node_interface2 = db_get_row_filter(
// 'titem',
// [
// 'id_map' => $id_networkmap,
// 'type' => 1,
// 'source_data' => $relation['module_b'],
// ]
// );
// if (empty($exist_node_interface2) === true) {
// Crete the interface node
// and create the relation between agent and
// interface.
// $style = [];
// $style['id_agent'] = $agent_a;
// $style['shape'] = 'circle';
// $style['image'] = 'images/mod_snmp_proc.png';
// $style['width'] = 50;
// $style['height'] = 16;
// $style['label'] = modules_get_agentmodule_name($relation['module_b']);
// $id_int2 = db_process_sql_insert(
// 'titem',
// [
// 'id_map' => $id_networkmap,
// 'x' => 666,
// 'y' => 666,
// 'z' => 0,
// 'deleted' => 0,
// 'type' => 1,
// 'refresh' => 0,
// 'source' => 0,
// 'source_data' => $relation['module_b'],
// 'style' => json_encode($style),
// ]
// );
// $node_interface2 = db_get_row_filter(
// 'titem',
// [
// 'id_map' => $id_networkmap,
// 'type' => 1,
// 'id' => $id_int1,
// ]
// );
// $node_agent1 = db_get_value(
// 'id',
// 'titem',
// 'source_data',
// $agent_a
// );
// db_process_sql_insert(
// 'trel_item',
// [
// 'id_map' => $id_networkmap,
// 'id_parent' => $node_agent1,
// 'id_child' => $node_interface1,
// 'id_parent-source_data' => $agent_a,
// 'id_child-source_data' => $relation['module_b'],
// 'parent_type' => 0,
// 'child_type' => 1,
// ]
// );
// } else {
// $node_interface2 = $exist_node_interface2;
// }
// if (empty($node_interface1) === false && empty($node_interface2) === false) {
// if (is_array($node_interface1) === true) {
// $node_interface1 = $node_interface1['id'];
// }
// if (is_array($node_interface2) === true) {
// $node_interface2 = $node_interface2['id'];
// }
// db_process_sql_insert(
// 'trel_item',
// [
// 'id_map' => $id_networkmap,
// 'id_parent' => $node_interface2,
// 'id_child' => $node_interface1,
// 'id_parent_source_data' => $relation['module_b'],
// 'id_child_source_data' => $relation['module_a'],
// 'parent_type' => 1,
// 'child_type' => 1,
// ]
// );
// }
// }
// }
// }
$relations = modules_get_relations(
[
'id_agent' => $node['source_data'],
@ -4723,18 +4498,6 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y)
if (empty($interfaces) === true) {
$interfaces = [];
}
// hd('interfaces', true);
// foreach ($interfaces as $interface) {
// $relations = modules_get_relations(
// ['id_module' => $interface['id_agente_modulo']]
// );
// if (empty($relations) === true) {
// $relations = [];
// }
// foreach ($relations as $relation) {
// }
// }
}
}