Added Others node
Former-commit-id: 64179fd7b2520e3378d188438f8bc846edb56004
This commit is contained in:
parent
74e86768f8
commit
f9744ca8c8
|
@ -1828,7 +1828,7 @@ function netflow_build_map_data($start_date, $end_date, $top, $aggregate)
|
|||
'status' => '#82B92E',
|
||||
];
|
||||
},
|
||||
$data['sources']
|
||||
array_merge($data['sources'], [__('Others')])
|
||||
);
|
||||
|
||||
$relations = [];
|
||||
|
@ -1839,6 +1839,7 @@ function netflow_build_map_data($start_date, $end_date, $top, $aggregate)
|
|||
$is_ip = true;
|
||||
$src_key = ($is_ip === true) ? 3 : 5;
|
||||
$dst_key = ($is_ip === true) ? 4 : 6;
|
||||
$retrieved_data = array_fill_keys($inverse_nodes, false);
|
||||
|
||||
foreach ($data['lines'] as $line) {
|
||||
if (empty($line) === true) {
|
||||
|
@ -1855,10 +1856,14 @@ function netflow_build_map_data($start_date, $end_date, $top, $aggregate)
|
|||
$index_rel = $src_item.'-'.$dst_item;
|
||||
|
||||
// Check if valid data.
|
||||
if (!isset($value) || !isset($src_item) || !isset($dst_item)) {
|
||||
if (!isset($value) || (!isset($src_item) && !isset($dst_item))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mark as connected source and destination.
|
||||
$retrieved_data[$src_item] = true;
|
||||
$retrieved_data[$dst_item] = true;
|
||||
|
||||
if (isset($relations[$index_rel])) {
|
||||
$relations[$index_rel]['text_start'] += $value;
|
||||
} else {
|
||||
|
@ -1874,9 +1879,39 @@ function netflow_build_map_data($start_date, $end_date, $top, $aggregate)
|
|||
}
|
||||
}
|
||||
|
||||
// Format the data in edges.
|
||||
array_walk(
|
||||
$relations,
|
||||
function (&$elem) {
|
||||
$elem['text_start'] = network_format_bytes($elem['text_start']);
|
||||
}
|
||||
);
|
||||
|
||||
// Search for orphan nodes.
|
||||
$orphan_hosts = [];
|
||||
$orphan_index = (end($inverse_nodes) + 1);
|
||||
foreach ($retrieved_data as $position => $rd) {
|
||||
if ($rd === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$orphan_hosts[$position.'-'.$orphan_index] = [
|
||||
'id_parent' => $orphan_index,
|
||||
'parent_type' => NODE_GENERIC,
|
||||
'child_type' => NODE_GENERIC,
|
||||
'id_child' => $position,
|
||||
'link_color' => '#82B92E',
|
||||
];
|
||||
}
|
||||
|
||||
// If there is not any orphan node, delete it.
|
||||
if (empty($orphan_hosts)) {
|
||||
array_pop($nodes);
|
||||
}
|
||||
|
||||
return [
|
||||
'nodes' => $nodes,
|
||||
'relations' => $relations,
|
||||
'relations' => array_merge($relations, $orphan_hosts),
|
||||
'pure' => 1,
|
||||
'no_pandora_node' => 1,
|
||||
'map_options' => [
|
||||
|
|
|
@ -205,6 +205,7 @@ function network_build_map_data($start, $end, $top, $talker)
|
|||
);
|
||||
|
||||
$relations = [];
|
||||
$orphan_relations = [];
|
||||
foreach ($hosts as $host) {
|
||||
$host_top = network_matrix_get_top(
|
||||
$top,
|
||||
|
@ -228,9 +229,34 @@ function network_build_map_data($start, $end, $top, $talker)
|
|||
'child_type' => NODE_GENERIC,
|
||||
'id_child' => $inverse_hosts[$host],
|
||||
'link_color' => '#82B92E',
|
||||
'text_start' => $sd['sum_bytes'],
|
||||
'text_start' => network_format_bytes($sd['sum_bytes']),
|
||||
];
|
||||
}
|
||||
|
||||
// Put the orphans on Other node.
|
||||
if (empty($host_top)) {
|
||||
$other_id = (end($inverse_hosts) + 1);
|
||||
// TODOS: Add the data.
|
||||
$orphan_relations[$inverse_hosts[$host].'-'.$other_id] = [
|
||||
'id_parent' => $other_id,
|
||||
'parent_type' => NODE_GENERIC,
|
||||
'child_type' => NODE_GENERIC,
|
||||
'id_child' => $inverse_hosts[$host],
|
||||
'link_color' => '#82B92E',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Put the Others node and their relations.
|
||||
if (empty($orphan_relations) === false) {
|
||||
$nodes[] = [
|
||||
'name' => __('Others'),
|
||||
'type' => NODE_GENERIC,
|
||||
'width' => 20,
|
||||
'height' => 20,
|
||||
'status' => '#82B92E',
|
||||
];
|
||||
$relations = array_merge($relations, $orphan_relations);
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
Loading…
Reference in New Issue