#8889 Fixed refresh and duplicate relations

This commit is contained in:
Daniel Maya 2022-08-31 10:08:20 +02:00
parent d3612439fb
commit bb691c2e16
3 changed files with 390 additions and 320 deletions

View File

@ -2131,6 +2131,62 @@ class NetworkMap
} }
if (is_array($edges)) { if (is_array($edges)) {
$array_aux = $edges;
$target_aux = $edges;
foreach ($edges as $key => $rel) {
foreach ($array_aux as $key2 => $rel2) {
if ($key2 <= $key) {
continue;
}
if ($rel['child_type'] == 1 && $rel['parent_type'] == 1
&& $rel2['child_type'] == 1 && $rel2['parent_type'] == 1
) {
if ($rel['id_parent'] == $rel2['id_parent'] && $rel['id_child'] == $rel2['id_child']) {
if ($rel['id_parent_source_data'] == $rel2['id_parent_source_data']) {
if (modules_get_agentmodule_type($rel['id_child_source_data']) === 6) {
unset($target_aux[$key]);
} else if (modules_get_agentmodule_type($rel2['id_child_source_data']) === 6) {
unset($target_aux[$key2]);
}
} else if ($rel['id_child_source_data'] == $rel2['id_child_source_data']) {
if (modules_get_agentmodule_type($rel['id_parent_source_data']) === 6) {
unset($target_aux[$key]);
} else if (modules_get_agentmodule_type($rel2['id_parent_source_data']) === 6) {
unset($target_aux[$key2]);
}
}
} else if ($rel['id_parent'] == $rel2['id_child'] && $rel['id_child'] == $rel2['id_parent']) {
if ($rel['id_parent_source_data'] == $rel2['id_child_source_data']
&& $rel['id_child_source_data'] == $rel2['id_parent_source_data']
) {
unset($target_aux[$key2]);
continue;
}
if ($rel['id_parent_source_data'] == $rel2['id_child_source_data']) {
if (modules_get_agentmodule_type($rel['id_child_source_data']) === 6) {
unset($target_aux[$key]);
} else if (modules_get_agentmodule_type($rel2['id_parent_source_data']) === 6) {
unset($target_aux[$key2]);
}
} else if ($rel['id_child_source_data'] == $rel2['id_parent_source_data']) {
if (modules_get_agentmodule_type($rel['id_parent_source_data']) === 6) {
unset($target_aux[$key]);
} else if (modules_get_agentmodule_type($rel2['id_child_source_data']) === 6) {
unset($target_aux[$key2]);
}
}
}
}
}
}
$edges = [];
foreach ($target_aux as $key => $value) {
$edges[] = $value;
}
foreach ($edges as $rel) { foreach ($edges as $rel) {
$graph .= $this->createDotEdge( $graph .= $this->createDotEdge(
[ [
@ -3431,6 +3487,7 @@ class NetworkMap
node_radius: node_radius, node_radius: node_radius,
holding_area_dimensions: networkmap_holding_area_dimensions, holding_area_dimensions: networkmap_holding_area_dimensions,
url_background_grid: url_background_grid, url_background_grid: url_background_grid,
refresh_time: '.$this->mapOptions['refresh_time'].',
font_size: '.$this->mapOptions['font_size'].', font_size: '.$this->mapOptions['font_size'].',
base_url_homedir: "'.ui_get_full_url(false).'" base_url_homedir: "'.ui_get_full_url(false).'"
}); });

View File

@ -4372,102 +4372,85 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y)
} }
} }
// Get L2 interface relations. // foreach ($interfaces as $interface) {
$interfaces = modules_get_interfaces( // $relations = modules_get_relations(
$node['source_data'], // ['id_module' => $interface['id_agente_modulo']]
[ // );
'id_agente', // if (empty($relations) === true) {
'id_agente_modulo', // $relations = [];
] // }
); // foreach ($relations as $relation) {
if (empty($interfaces) === true) {
$interfaces = [];
}
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 // Get the links althought they are deleted (for to
// avoid to add) // avoid to add)
// Check if the module is ping. // Check if the module is ping.
if (modules_get_agentmodule_type($relation['module_a']) === '6') { // if (modules_get_agentmodule_type($relation['module_a']) === '6') {
// The pings modules are not exist as interface // The pings modules are not exist as interface
// the link is with the agent. // the link is with the agent.
$node_a = db_get_value_filter( // $node_a = db_get_value_filter(
'id', // 'id',
'titem', // 'titem',
[ // [
'source_data' => modules_get_agentmodule_agent( // 'source_data' => modules_get_agentmodule_agent(
$relation['module_a'] // $relation['module_a']
), // ),
'id_map' => $id_networkmap, // 'id_map' => $id_networkmap,
] // ]
); // );
} else { // } else {
$node_a = db_get_value_filter( // $node_a = db_get_value_filter(
'id', // 'id',
'titem', // 'titem',
[ // [
'source_data' => $relation['module_a'], // 'source_data' => $relation['module_a'],
'type' => 1, // 'type' => 1,
'id_map' => $id_networkmap, // 'id_map' => $id_networkmap,
] // ]
); // );
} // }
// Check if the module is ping. // Check if the module is ping.
if (modules_get_agentmodule_type($relation['module_b']) == 6) { // if (modules_get_agentmodule_type($relation['module_b']) == 6) {
// The pings modules are not exist as interface // The pings modules are not exist as interface
// the link is with the agent. // the link is with the agent.
$node_b = db_get_value_filter( // $node_b = db_get_value_filter(
'id', // 'id',
'titem', // 'titem',
[ // [
'source_data' => modules_get_agentmodule_agent( // 'source_data' => modules_get_agentmodule_agent(
$relation['module_b'] // $relation['module_b']
), // ),
'id_map' => $id_networkmap, // 'id_map' => $id_networkmap,
] // ]
); // );
} else { // } else {
$node_b = db_get_value_filter( // $node_b = db_get_value_filter(
'id', // 'id',
'titem', // 'titem',
[ // [
'source_data' => $relation['module_b'], // 'source_data' => $relation['module_b'],
'type' => 1, // 'type' => 1,
'id_map' => $id_networkmap, // 'id_map' => $id_networkmap,
] // ]
); // );
} // }
// $exist = db_get_row_filter(
$exist = db_get_row_filter( // 'trel_item',
'trel_item', // [
[ // 'id_map' => $id_networkmap,
'id_map' => $id_networkmap, // 'id_parent_source_data' => $relation['module_a'],
'id_parent_source_data' => $relation['module_a'], // 'id_child_source_data' => $relation['module_b'],
'id_child_source_data' => $relation['module_b'], // 'deleted' => 0,
'deleted' => 0, // ]
] // );
); // $exist_reverse = db_get_row_filter(
// 'trel_item',
$exist_reverse = db_get_row_filter( // [
'trel_item', // 'id_map' => $id_networkmap,
[ // 'id_parent_source_data' => $relation['module_b'],
'id_map' => $id_networkmap, // 'id_child_source_data' => $relation['module_a'],
'id_parent_source_data' => $relation['module_b'], // 'deleted' => 0,
'id_child_source_data' => $relation['module_a'], // ]
'deleted' => 0, // );
] // if (empty($exist) && empty($exist_reverse)) {
);
if (empty($exist) && empty($exist_reverse)) {
// Create the nodes for interfaces // Create the nodes for interfaces
// Ag1 ----- I1 ------ I2 ----- Ag2 // Ag1 ----- I1 ------ I2 ----- Ag2
// * 2 interfaces nodes // * 2 interfaces nodes
@ -4478,184 +4461,202 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y)
// //
// But check if it exists the relations // But check if it exists the relations
// agent between interface. // agent between interface.
if ($interface['id_agente_modulo'] == $relation['module_a']) { // if ($interface['id_agente_modulo'] == $relation['module_a']) {
$agent_a = $interface['id_agente']; // $agent_a = $interface['id_agente'];
$agent_b = modules_get_agentmodule_agent( // $agent_b = modules_get_agentmodule_agent(
$relation['module_b'] // $relation['module_b']
); // );
} else { // } else {
$agent_a = modules_get_agentmodule_agent( // $agent_a = modules_get_agentmodule_agent(
$relation['module_a'] // $relation['module_a']
); // );
$agent_b = $interface['id_agente']; // $agent_b = $interface['id_agente'];
} // }
// $item_a = db_get_value(
$exist_node_interface1 = db_get_row_filter( // 'id',
'titem', // 'titem',
[ // 'source_data',
'id_map' => $id_networkmap, // $agent_a
'type' => 1, // );
'source_data' => $relation['module_a'], // $item_b = db_get_value(
] // 'id',
); // 'titem',
// 'source_data',
if (empty($exist_node_interface1) === true) { // $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 // Crete the interface node
// and create the relation between agent and // and create the relation between agent and
// interface. // interface.
$style = []; // $style = [];
$style['id_agent'] = $agent_a; // $style['id_agent'] = $agent_a;
$style['shape'] = 'circle'; // $style['shape'] = 'circle';
$style['image'] = 'images/mod_snmp_proc.png'; // $style['image'] = 'images/mod_snmp_proc.png';
$style['width'] = 50; // $style['width'] = 50;
$style['height'] = 16; // $style['height'] = 16;
$style['label'] = modules_get_agentmodule_name($relation['module_a']); // $style['label'] = modules_get_agentmodule_name($relation['module_a']);
$id_int1 = db_process_sql_insert( // $id_int1 = db_process_sql_insert(
'titem', // 'titem',
[ // [
'id_map' => $id_networkmap, // 'id_map' => $id_networkmap,
'x' => 666, // 'x' => 666,
'y' => 666, // 'y' => 666,
'z' => 0, // 'z' => 0,
'deleted' => 0, // 'deleted' => 0,
'type' => 1, // 'type' => 1,
'refresh' => 0, // 'refresh' => 0,
'source' => 0, // 'source' => 0,
'source_data' => $relation['module_a'], // 'source_data' => $relation['module_a'],
'style' => json_encode($style), // 'style' => json_encode($style),
] // ]
); // );
$node_interface1 = db_get_row_filter( // $node_interface1 = db_get_row_filter(
'titem', // 'titem',
[ // [
'id_map' => $id_networkmap, // 'id_map' => $id_networkmap,
'type' => 1, // 'type' => 1,
'id' => $id_int1, // 'id' => $id_int1,
] // ]
); // );
// $node_agent1 = db_get_value(
$node_agent1 = db_get_value( // 'id',
'id', // 'titem',
'titem', // 'source_data',
'source_data', // $agent_a
$agent_a // );
); // db_process_sql_insert(
// 'trel_item',
db_process_sql_insert( // [
'trel_item', // 'id_map' => $id_networkmap,
[ // 'id_parent' => $node_agent1,
'id_map' => $id_networkmap, // 'id_child' => $node_interface1,
'id_parent' => $node_agent1, // 'id_parent-source_data' => $agent_a,
'id_child' => $node_interface1, // 'id_child-source_data' => $relation['module_a'],
'id_parent-source_data' => $agent_a, // 'parent_type' => 0,
'id_child-source_data' => $relation['module_a'], // 'child_type' => 1,
'parent_type' => 0, // ]
'child_type' => 1, // );
] // } else {
); // $node_interface1 = $exist_node_interface1;
} else { // }
$node_interface1 = $exist_node_interface1; // $exist_node_interface2 = db_get_row_filter(
} // 'titem',
// [
$exist_node_interface2 = db_get_row_filter( // 'id_map' => $id_networkmap,
'titem', // 'type' => 1,
[ // 'source_data' => $relation['module_b'],
'id_map' => $id_networkmap, // ]
'type' => 1, // );
'source_data' => $relation['module_b'], // if (empty($exist_node_interface2) === true) {
]
);
if (empty($exist_node_interface2) === true) {
// Crete the interface node // Crete the interface node
// and create the relation between agent and // and create the relation between agent and
// interface. // interface.
$style = []; // $style = [];
$style['id_agent'] = $agent_a; // $style['id_agent'] = $agent_a;
$style['shape'] = 'circle'; // $style['shape'] = 'circle';
$style['image'] = 'images/mod_snmp_proc.png'; // $style['image'] = 'images/mod_snmp_proc.png';
$style['width'] = 50; // $style['width'] = 50;
$style['height'] = 16; // $style['height'] = 16;
$style['label'] = modules_get_agentmodule_name($relation['module_b']); // $style['label'] = modules_get_agentmodule_name($relation['module_b']);
$id_int2 = db_process_sql_insert( // $id_int2 = db_process_sql_insert(
'titem', // '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_map' => $id_networkmap, 'id_agent' => $node['source_data'],
'x' => 666, 'networkmap' => true,
'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']]);
if ($relations === false) { if ($relations === false) {
$relations = []; $relations = [];
} }
// Relations Module <-> Module.
foreach ($relations as $key => $relation) { foreach ($relations as $key => $relation) {
$module_a = $relation['module_a']; $module_a = $relation['module_a'];
$agent_a = modules_get_agentmodule_agent($module_a); $agent_a = modules_get_agentmodule_agent($module_a);
@ -4682,58 +4683,26 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y)
); );
if (empty($exist) === true && empty($exist_reverse) === true) { if (empty($exist) === true && empty($exist_reverse) === true) {
$style = []; $item_a = db_get_value(
$style['id_agent'] = $agent_a; 'id',
$style['shape'] = 'circle';
$style['image'] = 'images/mod_snmp_proc.png';
$style['width'] = 50;
$style['height'] = 16;
$style['label'] = modules_get_agentmodule_name($module_a);
$id_int1 = db_process_sql_insert(
'titem', 'titem',
[ 'source_data',
'id_map' => $id_networkmap, $agent_a
'x' => 666,
'y' => 666,
'z' => 0,
'deleted' => 0,
'type' => 1,
'refresh' => 0,
'source' => 0,
'source_data' => $module_a,
'style' => json_encode($style),
]
); );
$style = []; $item_b = db_get_value(
$style['id_agent'] = $agent_b; 'id',
$style['shape'] = 'circle';
$style['image'] = 'images/mod_snmp_proc.png';
$style['width'] = 50;
$style['height'] = 16;
$style['label'] = modules_get_agentmodule_name($module_b);
$id_int2 = db_process_sql_insert(
'titem', 'titem',
[ 'source_data',
'id_map' => $id_networkmap, $agent_b
'x' => 666,
'y' => 666,
'z' => 0,
'deleted' => 0,
'type' => 1,
'refresh' => 0,
'source' => 0,
'source_data' => $module_b,
'style' => json_encode($style),
]
); );
db_process_sql_insert( db_process_sql_insert(
'trel_item', 'trel_item',
[ [
'id_map' => $id_networkmap, 'id_map' => $id_networkmap,
'id_parent' => $id_int1, 'id_parent' => $item_a,
'id_child' => $id_int2, 'id_child' => $item_b,
'id_parent_source_data' => $module_a, 'id_parent_source_data' => $module_a,
'id_child_source_data' => $module_b, 'id_child_source_data' => $module_b,
'parent_type' => 1, 'parent_type' => 1,
@ -4742,6 +4711,30 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y)
); );
} }
} }
// Get L2 interface relations.
$interfaces = modules_get_interfaces(
$node['source_data'],
[
'id_agente',
'id_agente_modulo',
]
);
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) {
// }
// }
} }
} }

View File

@ -2505,7 +2505,7 @@ function refresh() {
if (array_nodes.length === 0 && array_links.length === 0) { if (array_nodes.length === 0 && array_links.length === 0) {
update_networkmap(); update_networkmap();
$("#spinner_networkmap").css("display", "none"); $("#spinner_networkmap").css("display", "none");
window.location = location; startCountDown(refresh_time);
} else { } else {
if (array_nodes.length > 0) { if (array_nodes.length > 0) {
$.ajax({ $.ajax({
@ -2535,6 +2535,22 @@ function refresh() {
}); });
} }
function startCountDown(duration) {
$("div.vc-countdown").countdown("destroy");
if (!duration) return;
var t = new Date();
t.setTime(t.getTime() + duration * 1000);
$("div.vc-countdown").countdown({
until: t,
format: "MS",
layout: "(%M%nn%M:%S%nn%S Until refreshed) ",
alwaysExpire: true,
onExpiry: function() {
refresh();
}
});
}
function restart_map() { function restart_map() {
$( $(
"<div id='restart_map_confirm' class='dialog ui-dialog-content' title='" + "<div id='restart_map_confirm' class='dialog ui-dialog-content' title='" +
@ -3072,6 +3088,10 @@ function init_graph(parameter_object) {
window.url_background_grid = ""; window.url_background_grid = "";
} }
if (typeof parameter_object.refresh_time != "undefined") {
window.refresh_time = parameter_object.refresh_time;
}
var rect_center_x = graph.nodes[0].x; var rect_center_x = graph.nodes[0].x;
var rect_center_y = graph.nodes[0].y; var rect_center_y = graph.nodes[0].y;