From ac69a237861334dbf67096ad7f01ff1be32291ab Mon Sep 17 00:00:00 2001 From: zarzuelo <zarzuelo@gmail.com> Date: Mon, 23 Apr 2012 14:21:54 +0000 Subject: [PATCH] 2012-04-23 Sergio Martin <sergio.martin@artica.es> * include/functions_networkmap.php include/ajax/networkmap.ajax.php operation/agentes/networkmap.topology.php: Fixed several errors in the apache log when generate networkmap and add to the root node a little map summary git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6103 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 +++ .../include/ajax/networkmap.ajax.php | 70 +++++++++++++++++++ .../include/functions_networkmap.php | 23 +++--- .../operation/agentes/networkmap.topology.php | 2 +- 4 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 pandora_console/include/ajax/networkmap.ajax.php diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 61b35383d6..6e97fcdb37 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2012-04-23 Sergio Martin <sergio.martin@artica.es> + + * include/functions_networkmap.php + include/ajax/networkmap.ajax.php + operation/agentes/networkmap.topology.php: Fixed several + errors in the apache log when generate networkmap and add + to the root node a little map summary + 2012-04-23 Dario Rodriguez <dario.rodriguez@artica.es> * godmode/reporting/visual_console_builder.data.php: Fixed a problem diff --git a/pandora_console/include/ajax/networkmap.ajax.php b/pandora_console/include/ajax/networkmap.ajax.php new file mode 100644 index 0000000000..0105eaa786 --- /dev/null +++ b/pandora_console/include/ajax/networkmap.ajax.php @@ -0,0 +1,70 @@ +<?php + +//Pandora FMS- http://pandorafms.com +// ================================================== +// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas +// Please see http://pandorafms.org for full contribution list + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation; version 2 + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +global $config; + +// Login check +check_login (); + +if (! check_acl ($config['id_user'], 0, "IR")) { + db_pandora_audit("ACL Violation", + "Trying to access report builder"); + require ("general/noaccess.php"); + exit; +} + +$action = get_parameter('action'); + +switch($action) { + case 'get_networkmap_summary': + $stats = get_parameter('stats', array()); + $stats = json_decode(base64_decode($stats),true); + + $summary = '<br>'; + + if(isset($stats['policies'])) { + $summary .= count($stats['policies'])." x ".html_print_image('images/policies.png',true).' '.__('Policies')."<br>"; + } + + if(isset($stats['groups'])) { + // TODO: GET STATUS OF THE GROUPS AND ADD IT TO SUMMARY + $summary .= count($stats['groups'])." x ".html_print_image('images/group.png',true).' '.__('Groups')."<br>"; + } + + if(isset($stats['agents'])) { + $summary .= count($stats['agents'])." x ".html_print_image('images/bricks.png',true).' '.__('Agents')."<br>"; + // TODO: GET STATUS OF THE AGENTS AND ADD IT TO SUMMARY + //~ $status_agents = array(); + //~ foreach($stats['agents'] as $id_agent) { + //~ $st = agents_get_status($id_agent); + //~ if(!isset($status_agents[$st])) { + //~ $status_agents[$st] = 0; + //~ } + //~ $status_agents[$st] ++; + //~ } + } + + if(isset($stats['modules'])) { + // TODO: GET STATUS OF THE MODULES AND ADD IT TO SUMMARY + $summary .= count($stats['modules'])." x ".html_print_image('images/brick.png',true).' '.__('Modules')."<br>"; + } + + echo '<h3>'.__('Map summary').'</h3><strong>'.$summary.'</strong>'; + break; +} + + +?> diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 872a8f0dc4..21a517bbb2 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -139,9 +139,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0, $simple = 0, $font_ switch($node['type']){ case 'agent': $graph .= networkmap_create_agent_node ($node , $simple, $font_size, $cut_names, $relative)."\n\t\t"; + $stats['agents'][] = $node['id_agente']; break; case 'module': $graph .= networkmap_create_module_node ($node , $simple, $font_size)."\n\t\t"; + $stats['modules'][] = $node['id_agente_modulo']; break; } } @@ -158,7 +160,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0, $simple = 0, $font_ // Create a central node if orphan nodes exist if (count ($orphans) || empty ($nodes)) { - $graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple); + $graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple, $stats); } // Define edges for orphan nodes @@ -309,12 +311,15 @@ function networkmap_generate_dot_groups ($pandora_name, $group = 0, $simple = 0, switch($node['type']){ case 'group': $graph .= networkmap_create_group_node ($node , $simple, $font_size)."\n\t\t"; + $stats['groups'][] = $node['id_grupo']; break; case 'agent': - $graph .= networkmap_create_agent_node ($node , $simple, $font_size)."\n\t\t"; + $graph .= networkmap_create_agent_node ($node , $simple, $font_size, true, true)."\n\t\t"; + $stats['agents'][] = $node['id_agente']; break; case 'module': $graph .= networkmap_create_module_node ($node , $simple, $font_size)."\n\t\t"; + $stats['modules'][] = $node['id_agente_modulo']; break; } } @@ -330,7 +335,7 @@ function networkmap_generate_dot_groups ($pandora_name, $group = 0, $simple = 0, // Create a central node if orphan nodes exist if (count ($orphans)) { - $graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple); + $graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple, $stats); } // Define edges for orphan nodes @@ -399,7 +404,7 @@ function networkmap_create_group_node ($group, $simple = 0, $font_size = 10) { } $node = $group['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.30, height=0.30, label=<<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD>'.$img_node.'</TD></TR> - <TR><TD>'.$name.'</TD></TR></TABLE>>, + <TR><TD>'.io_safe_output($name).'</TD></TR></TABLE>>, shape="invtrapezium", URL="index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$group['id_grupo'].'", tooltip="ajax.php?page=operation/agentes/ver_agente&get_group_status_tooltip=1&id_group='.$group['id_grupo'].'"];'; } @@ -453,7 +458,7 @@ function networkmap_create_agent_node ($agent, $simple = 0, $font_size = 10, $cu } $node = $agent['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.40, height=0.40, label=<<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD>' . $img_node . '</TD></TR> - <TR><TD>'.$name.'</TD></TR></TABLE>>, + <TR><TD>'.io_safe_output($name).'</TD></TR></TABLE>>, shape="doublecircle", URL="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent['id_agente'].'", tooltip="ajax.php?page=operation/agentes/ver_agente&get_agent_status_tooltip=1&id_agent='.$agent['id_agente'].'"];'; } @@ -490,7 +495,7 @@ function networkmap_create_module_node ($module, $simple = 0, $font_size = 10) { if ($simple == 0){ $node = $module['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.30, height=0.30, label=<<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD>' . ui_print_moduletype_icon ($module['id_tipo_modulo'], true, true, false). '</TD></TR> - <TR><TD>'.$module['nombre'].'</TD></TR></TABLE>>, + <TR><TD>'.io_safe_output($module['nombre']).'</TD></TR></TABLE>>, shape="circle", URL="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$module['id_agente'].'", tooltip="ajax.php?page=operation/agentes/ver_agente&get_agentmodule_status_tooltip=1&id_module='.$module['id_agente_modulo'].'"];'; } @@ -501,7 +506,7 @@ function networkmap_create_module_node ($module, $simple = 0, $font_size = 10) { } // Returns the definition of the central module -function networkmap_create_pandora_node ($name, $font_size = 10, $simple = 0) { +function networkmap_create_pandora_node ($name, $font_size = 10, $simple = 0, $stats = array()) { $img = '<TR><TD>' . html_print_image("images/networkmap/pandora_node.png", true, false, false, true) . '</TD></TR>'; $name = '<TR><TD BGCOLOR="#FFFFFF">'.$name.'</TD></TR>'; $label = '<TABLE BORDER="0">'.$img.$name.'</TABLE>'; @@ -509,8 +514,10 @@ function networkmap_create_pandora_node ($name, $font_size = 10, $simple = 0) { $label = ''; } + $stats_json = base64_encode(json_encode($stats)); + $node = '0 [ color="#364D1F", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.8, height=0.6, label=<'.$label.'>, - shape="ellipse", URL="index.php?sec=estado&sec2=operation/agentes/group_view" ];'; + shape="ellipse", tooltip="ajax.php?page=include/ajax/networkmap.ajax&action=get_networkmap_summary&stats='.$stats_json.'", URL="index.php?sec=estado&sec2=operation/agentes/group_view" ];'; return $node; } diff --git a/pandora_console/operation/agentes/networkmap.topology.php b/pandora_console/operation/agentes/networkmap.topology.php index bee75f72f4..b5e5010833 100644 --- a/pandora_console/operation/agentes/networkmap.topology.php +++ b/pandora_console/operation/agentes/networkmap.topology.php @@ -32,7 +32,7 @@ require_once ('include/functions_networkmap.php'); $filter = networkmap_get_filter ($layout); // Generate dot file -$graph = networkmap_generate_dot (__('Pandora FMS'), $group, $simple, $font_size, $layout, $nooverlap, $zoom, $ranksep, $center, $regen, $pure, $id_networkmap, $show_snmp_modules); +$graph = networkmap_generate_dot (__('Pandora FMS'), $group, $simple, $font_size, $layout, $nooverlap, $zoom, $ranksep, $center, $regen, $pure, $id_networkmap, $show_snmp_modules, true, true); if ($graph === false) { ui_print_error_message (__('Map could not be generated'));