From 63efa3169952884ee7c805a32790beec716ae446 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Mon, 13 Apr 2009 15:11:55 +0000 Subject: [PATCH] 2009-04-13 Ramon Novoa * operation/agentes/networkmap.php: Added support for group filtering and node navigation (clicking on the edges). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1616 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 5 + .../operation/agentes/networkmap.php | 94 ++++++++++++++----- 2 files changed, 75 insertions(+), 24 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 6f4427de83..3a9f14b244 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2009-04-13 Ramon Novoa + + * operation/agentes/networkmap.php: Added support for group filtering + and node navigation (clicking on the edges). + 2009-04-13 Esteban Sanchez * godmode/agentes/agent_manager.php: Fixed an error when an agent was diff --git a/pandora_console/operation/agentes/networkmap.php b/pandora_console/operation/agentes/networkmap.php index 3ba2d76656..2c5b796d72 100644 --- a/pandora_console/operation/agentes/networkmap.php +++ b/pandora_console/operation/agentes/networkmap.php @@ -30,12 +30,35 @@ if (! give_acl ($config['id_user'], 0, "AR")) { $pandora_name = 'Pandora FMS'; -// Generate a dot graph definition for graphviz -function generate_dot ($simple = 0, $font_size) { - global $config; - global $pandora_name; +// Load variables +$layout = (string) get_parameter ('layout', 'radial'); +$nooverlap = (boolean) get_parameter ('nooverlap', 0); +$pure = (int) get_parameter ('pure'); +$zoom = (float) get_parameter ('zoom'); +$ranksep = (float) get_parameter ('ranksep', 2.5); +$simple = (boolean) get_parameter ('simple', 0); +$regen = (boolean) get_parameter ('regen',1); // Always regen by default +$font_size = (int) get_parameter ('font_size', 12); +$group = (int) get_parameter ('group', 0); +$center = (int) get_parameter ('center', 0); + +// Check if a node descends from a given node +function is_descendant ($node, $ascendant, $parents) { + if (! isset ($parents[$node])) { + return false; + } + + if ($node == $ascendant) { + return true; + } - $group_id = -1; + return is_descendant ($parents[$node], $ascendant, $parents); +} + +// Generate a dot graph definition for graphviz +function generate_dot ($group, $simple, $font_size) { + global $config, $pandora_name, $center; + $parents = array(); $orphans = array(); @@ -46,7 +69,10 @@ function generate_dot ($simple = 0, $font_size) { $agents = get_db_all_rows_sql ('SELECT id_grupo, nombre, id_os, id_parent, id_agente FROM tagente WHERE disabled = 0 + ' . ($group < 1 ? '' : "AND id_grupo = $group") . ' ORDER BY id_grupo'); + + // Parse agents if ($agents){ foreach ($agents as $agent) { if (give_acl ($config["id_user"], $agent["id_grupo"], "AR") == 0) @@ -59,19 +85,36 @@ function generate_dot ($simple = 0, $font_size) { } // Add node - $graph .= create_node ($agent , $simple, $font_size)."\n\t\t"; + $nodes[$agent['id_agente']] = $agent; } } - + + // Create nodes + foreach ($nodes as $node_id => $node) { + if ($center > 0 && ! is_descendant ($node_id, $center, $parents)) { + unset ($parents[$node_id]); + unset ($orphans[$node_id]); + unset ($nodes[$node_id]); + continue; + } + + $graph .= create_node ($node , $simple, $font_size)."\n\t\t"; + } + + // Define edges + foreach ($parents as $node => $parent_id) { + // Verify that the parent is in the graph + if (isset ($nodes[$parent_id])) { + $graph .= create_edge ($node, $parent_id); + } else { + $orphans[$node] = 1; + } + } + // Create a central node if orphan nodes exist if (count ($orphans)) { $graph .= create_pandora_node ($pandora_name, $font_size); } - - // Define edges - foreach ($parents as $node => $parent_id) { - $graph .= create_edge ($node, $parent_id); - } // Define edges for orphan nodes foreach (array_keys($orphans) as $node) { @@ -86,7 +129,16 @@ function generate_dot ($simple = 0, $font_size) { // Returns an edge definition function create_edge ($head, $tail) { - $edge = $head.' -- '.$tail.'[color="#BDBDBD", headclip=false, tailclip=false];'; + global $layout, $nooverlap, $pure, $zoom, + $ranksep, $simple, $regen, $font_size, $group; + + // edgeURL allows node navigation + $edge = $head.' -- '.$tail.'[color="#BDBDBD", headclip=false, tailclip=false, + edgeURL="index.php?sec=estado&sec2=operation/agentes/networkmap¢er='.$head. + '&layout='.$layout.'&nooverlap=' .$nooverlap.'&pure='.$pure. + '&zoom='.$zoom.'&ranksep='.$ranksep.'&simple='.$simple.'®en=1'. + '&font_size='.$font_size.'&group='.$group.'"];'; + return $edge; } @@ -243,15 +295,6 @@ function set_filter () { } /* Main code */ -// Load variables -$layout = (string) get_parameter ('layout', 'radial'); -$nooverlap = (boolean) get_parameter ('nooverlap', 0); -$pure = (int) get_parameter ('pure'); -$zoom = (float) get_parameter ('zoom'); -$ranksep = (float) get_parameter ('ranksep', 2.5); -$simple = (boolean) get_parameter ('simple', 0); -$regen = (boolean) get_parameter ('regen',1); // Always regen by default -$font_size = (int) get_parameter ('font_size', 12); echo '

'.__('Pandora Agents').' » '.__('Network Map').' '; if ($pure == 1) { @@ -273,9 +316,12 @@ $layout_array = array ( 'spring2' => 'spring 2', 'flat' => 'flat'); -echo '
'; +echo ''; echo ''; echo ''; +echo ''; echo ''; @@ -331,7 +377,7 @@ echo '
' . __('Group') . '  '; +print_select_from_sql ('SELECT id_grupo, nombre FROM tgrupo WHERE id_grupo > 1 ORDER BY nombre', 'group', $group, '', 'All', 0, false); +echo '' . __('Layout') . '  '; print_select ($layout_array, 'layout', $layout, '', '', ''); echo '
'; $filter = set_filter (); // Generate dot file -$graph = generate_dot ($simple, $font_size); +$graph = generate_dot ($group, $simple, $font_size); // Generate image and map // If image was generated just a few minutes ago, then don't regenerate (it takes long) unless regen checkbox is set