From 24f6eb4c8ff8f9b9c1b4f9fc1e30d093535bb846 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Fri, 23 Jul 2010 12:14:07 +0000 Subject: [PATCH] 2010-07-23 Sergio Martin * include/functions_networkmap.php include/functions_db.php operation/agentes/networkmap.topology.php operation/agentes/networkmap.groups.php operation/agentes/ver_agente.php operation/agentes/networkmap.php: Rewritted the get status of modules and agents and writted the same feature for groups and policys. Added the groups view network map. All for pending task: 3019636 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3057 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 11 + pandora_console/include/functions_db.php | 172 +++++++++- .../include/functions_networkmap.php | 307 +++++++++++++++++- .../operation/agentes/networkmap.groups.php | 205 ++++++++++++ .../operation/agentes/networkmap.php | 184 +++-------- .../operation/agentes/networkmap.topology.php | 175 ++++++++++ .../operation/agentes/ver_agente.php | 60 +++- 7 files changed, 959 insertions(+), 155 deletions(-) create mode 100644 pandora_console/operation/agentes/networkmap.groups.php create mode 100644 pandora_console/operation/agentes/networkmap.topology.php diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 51dd68eab1..24c1a3952c 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2010-07-23 Sergio Martin + + * include/functions_networkmap.php + include/functions_db.php + operation/agentes/networkmap.topology.php + operation/agentes/networkmap.groups.php + operation/agentes/ver_agente.php + operation/agentes/networkmap.php: Rewritted the get status of modules + and agents and writted the same feature for groups and policys. Added + the groups view network map. All for pending task: 3019636 + 2010-07-23 Dario Rodriguez * operation/agentes/ver_agente.php: Changed code to use print_page_header diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index e0876d87cf..dc50e99578 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -782,6 +782,17 @@ function get_module_type_name ($id_type) { return (string) get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', (int) $id_type); } +/** + * Get the name of a module type + * + * @param int $id_type Type id + * + * @return string The name of the given type. + */ +function get_module_type_icon ($id_type) { + return (string) get_db_value ('icon', 'ttipo_modulo', 'id_tipo', (int) $id_type); +} + /** * Get agent id of an agent module. * @@ -1400,6 +1411,17 @@ function get_agent_interval ($id_agent) { return (int) get_db_value ('intervalo', 'tagente', 'id_agente', $id_agent); } +/** + * Get the operating system of an agent. + * + * @param int Agent id. + * + * @return int The interval value of a given agent + */ +function get_agent_os ($id_agent) { + return (int) get_db_value ('id_os', 'tagente', 'id_agente', $id_agent); +} + /** * Get the flag value of an agent module. * @@ -2596,19 +2618,24 @@ function get_agentmodule_status ($id_agentmodule = 0) { $times_fired = get_db_value ('SUM(times_fired)', 'talert_template_modules', 'id_agent_module', $id_agentmodule); if ($times_fired > 0) { - return 4; // Alert + return 4; // Alert fired } - - $status_row = get_db_row ("tagente_estado", "id_agente_modulo", $id_agentmodule); - // Not init or current_interval == 0: Return current status and avoid problems here ! + /*// Not init or current_interval == 0: Return current status and avoid problems here ! if ($status_row["current_interval"] == 0) + return $status_row["estado"];*/ + + $module_type = get_agentmodule_type($id_agentmodule); + + // Asynchronous and keepalive modules cant be unknown + if(($module_type >= 21 && $module_type <= 23) || $module_type == 100) { return $status_row["estado"]; - + } + // Unknown status - if ( ($status_row["current_interval"] * 2) + $status_row["utimestamp"] < $current_timestamp){ + if ($status_row["current_interval"] == 0 || ($status_row["current_interval"] * 2) + $status_row["utimestamp"] < $current_timestamp){ $status = 3; } else { @@ -2627,21 +2654,122 @@ function get_agentmodule_status ($id_agentmodule = 0) { * The value -1 is returned in case the agent has exceed its interval. */ function get_agent_status ($id_agent = 0) { + $modules = get_agent_modules ($id_agent, 'id_agente_modulo', array('disabled' => 0)); + + $modules_status = array(); + $modules_async = 0; + foreach($modules as $module) { + $modules_status[] = get_agentmodule_status($module); + + $module_type = get_agentmodule_type($module); + if(($module_type >= 21 && $module_type <= 23) || $module_type == 100) { + $modules_async++; + } + } + + // If all the modules are asynchronous or keep alive, the gruop cannot be unknown + if($modules_async < count($modules)) { + $time = get_system_time (); + $status = get_db_value_filter ('COUNT(*)', + 'tagente', + array ('id_agente' => (int) $id_agent, + 'UNIX_TIMESTAMP(ultimo_contacto) + intervalo * 2 > '.$time, + 'UNIX_TIMESTAMP(ultimo_contacto_remoto) + intervalo * 2 > '.$time)); + if (! $status) + return -1; + } + + // Status is 0 for normal, 1 for critical, 2 for warning and 3 for unknown. 4 for alert fired + + // Checking if any module has alert fired (4) + if(is_int(array_search(4,$modules_status))){ + return 4; + } + // Checking if any module has unknown status (3) + elseif(is_int(array_search(3,$modules_status))){ + return 3; + } + // Checking if any module has critical status (1) + elseif(is_int(array_search(1,$modules_status))){ + return 1; + } + // Checking if any module has warning status (2) + elseif(is_int(array_search(2,$modules_status))){ + return 2; + } + else { + return 0; + } + +} + +function get_group_status ($id_group = 0) { + $agents = get_group_agents($id_group); + + $agents_status = array(); + foreach($agents as $key => $agent){ + $agents_status[] = get_agent_status($key); + } + + $childrens = get_childrens($id_group); + + foreach($childrens as $key => $child){ + $agents_status[] = get_group_status($key); + } + + // Status is 0 for normal, 1 for critical, 2 for warning and 3/-1 for unknown. 4 for fired alerts + + // Checking if any agent has fired alert (4) + if(is_int(array_search(4,$agents_status))){ + return 4; + } + // Checking if any agent has unknown status (-1) + elseif(is_int(array_search(-1,$agents_status))){ + return -1; + } + // Checking if any agents module has unknown status (3) + elseif(is_int(array_search(3,$agents_status))){ + return 3; + } + // Checking if any agent has critical status (1) + elseif(is_int(array_search(1,$agents_status))){ + return 1; + } + // Checking if any agent has warning status (2) + elseif(is_int(array_search(2,$agents_status))){ + return 2; + } + else { + return 0; + } + + return $status; +} + +/** + * Get the worst status of all modules of the agents of a group. + * + * @param int Id module to check. + * + * @return int Worst status of a module for all of its agents. + * The value -1 is returned in case the agent has exceed its interval. <-- DISABLED + */ +function get_module_status ($id_module = 0) { $time = get_system_time (); - $status = get_db_value_filter ('COUNT(*)', + /*$status = get_db_value_filter ('COUNT(*)', 'tagente', array ('id_agente' => (int) $id_agent, 'UNIX_TIMESTAMP(ultimo_contacto) + intervalo * 2 > '.$time, 'UNIX_TIMESTAMP(ultimo_contacto_remoto) + intervalo * 2 > '.$time)); if (! $status) - return -1; + return -1;*/ - $status = get_db_sql ("SELECT MAX(estado) - FROM tagente_estado, tagente_modulo - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 - AND tagente_modulo.delete_pending = 0 - AND tagente_modulo.id_agente = $id_agent"); + $status = get_db_sql ("SELECT estado + FROM tagente_estado, tagente_modulo + WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 + AND tagente_modulo.delete_pending = 0 + AND tagente_modulo.id_agente_modulo = ".$id_module); // TODO: Check any alert for that agent who has recept alerts fired @@ -3124,6 +3252,17 @@ function get_agent_group ($id_agent) { return (int) get_db_value ('id_grupo', 'tagente', 'id_agente', (int) $id_agent); } +/** + * This function gets the modulegroup for a given group + * + * @param int The group id + * + * @return int The modulegroup id + */ +function get_agentmodule_modulegroup ($id_module) { + return (int) get_db_value ('id_module_group', 'tagente_modulo', 'id_agente_modulo', (int) $id_module); +} + /** * This function gets the group name for a given group id * @@ -3169,7 +3308,10 @@ function get_modulegroups () { * @return string The modulegroup name */ function get_modulegroup_name ($modulegroup_id) { - return (string) get_db_value ('name', 'tmodule_group', 'id_mg', (int) $modulegroup_id); + if($modulegroup_id == 0) + return false; + else + return (string) get_db_value ('name', 'tmodule_group', 'id_mg', (int) $modulegroup_id); } /** diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 8cdc9c52e6..248f8a73e8 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -113,12 +113,175 @@ function generate_dot ($pandora_name, $group = 0, $simple = 0, $font_size = 12, return $graph; } +// Generate a dot graph definition for graphviz with groups +function generate_dot_groups ($pandora_name, $group = 0, $simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0, $zoom = 1, $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0, $modwithalerts = 0, $module_group = 0, $hidepolicymodules = 0, $depth = 'all') { + + global $config; + + $parents = array(); + $orphans = array(); + + $filter = array (); + $filter['disabled'] = 0; + + // Get groups data + if ($group > 0) { + $filter['id_grupo'] = $group; + $groups[0] = get_db_row ('tgrupo', 'id_grupo', $group); + } + else { + $groups = get_db_all_rows_in_table ('tgrupo'); + } + + + // Open Graph + $graph = open_graph ($layout, $nooverlap, $pure, $zoom, $ranksep, $font_size); + + $node_count = 0; + + // Parse groups + $nodes = array (); + $nodes_groups = array(); + foreach ($groups as $group) { + $node_count ++; + $group['type'] = 'group'; + $group['id_node'] = $node_count; + + // Add node + $nodes_groups[$group['id_grupo']] = $group; + } + + $node_count = 0; + + foreach ($nodes_groups as $node_group) { + + $node_count++; + + // Save node parent information to define edges later + if ($node_group['parent'] != "0") { + $parents[$node_count] = $nodes_groups[$node_group['parent']]['id_node']; + } else { + $orphans[$node_count] = 1; + } + + $nodes[$node_count] = $node_group; + } + + if($depth != 'group') { + // Get agents data + $agents = get_agents ($filter, + array ('id_grupo, nombre, id_os, id_agente')); + if ($agents === false) + return false; + + // Parse agents + $nodes_agents = array(); + foreach ($agents as $agent) { + $node_count ++; + // Save node parent information to define edges later + $parents[$node_count] = $agent['parent'] = $nodes_groups[$agent['id_grupo']]['id_node']; + + $agent['id_node'] = $node_count; + $agent['type'] = 'agent'; + // Add node + $nodes[$node_count] = $nodes_agents[$agent['id_agente']] = $agent; + + if($depth == 'agent'){ + continue; + } + + // Get agent modules data + $modules = get_agent_modules ($agent['id_agente'], false, array('disabled' => 0)); + // Parse modules + foreach ($modules as $key => $module) { + $node_count ++; + $agent_module = get_agentmodule($key); + $alerts_module = get_db_sql('SELECT count(*) as num FROM talert_template_modules WHERE id_agent_module = '.$key); + + if($alerts_module == 0 && $modwithalerts){ + continue; + } + + if($agent_module['id_module_group'] != $module_group && $module_group != 0){ + continue; + } + + if($hidepolicymodules && $config['enterprise_installed']){ + enterprise_include_once('include/functions_policies.php'); + if(isModuleInPolicy($key)) { + continue; + } + } + + // Save node parent information to define edges later + $parents[$node_count] = $agent_module['parent'] = $agent['id_node']; + + $agent_module['id_node'] = $node_count; + + $agent_module['type'] = 'module'; + // Add node + $nodes[$node_count] = $agent_module; + } + } + } + + if (empty ($nodes)) { + return false; + } + // 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; + } + + switch($node['type']){ + case 'group': + $graph .= create_group_node ($node , $simple, $font_size)."\n\t\t"; + break; + case 'agent': + $graph .= create_agent_node ($node , $simple, $font_size)."\n\t\t"; + break; + case 'module': + $graph .= create_module_node ($node , $simple, $font_size)."\n\t\t"; + break; + } + } + + // 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, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap2'); + } else { + $orphans[$node] = 1; + } + } + + // Create a central node if orphan nodes exist + if (count ($orphans)) { + $graph .= create_pandora_node ($pandora_name, $font_size, $simple); + } + + // Define edges for orphan nodes + foreach (array_keys($orphans) as $node) { + $graph .= create_edge ('0', $node, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap2'); + } + + // Close graph + $graph .= close_graph (); + + return $graph; +} + // Returns an edge definition -function create_edge ($head, $tail, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group) { +function create_edge ($head, $tail, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, $sec2 = 'operation/agentes/networkmap') { // edgeURL allows node navigation $edge = $head.' -- '.$tail.'[color="#BDBDBD", headclip=false, tailclip=false, - edgeURL="index.php?sec=estado&sec2=operation/agentes/networkmap¢er='.$head. + edgeURL="index.php?sec=estado&sec2='.$sec2.'¢er='.$head. '&layout='.$layout.'&nooverlap=' .$nooverlap.'&pure='.$pure. '&zoom='.$zoom.'&ranksep='.$ranksep.'&simple='.$simple.'®en=1'. '&font_size='.$font_size.'&group='.$group.'"];'; @@ -182,6 +345,146 @@ function create_node ($agent, $simple = 0, $font_size = 10) { return $node; } +// Returns a group node definition +function create_group_node ($group, $simple = 0, $font_size = 10) { + $status = get_group_status ($group['id_grupo']); + + // Set node status + switch($status) { + case 0: + $status_color = '#8DFF1D'; // Normal monitor + break; + case 1: + $status_color = '#FF1D1D'; // Critical monitor + break; + case 2: + $status_color = '#FFE308'; // Warning monitor + break; + case 4: + $status_color = '#FFE308'; // Alert fired + break; + default: + $status_color = '#BBBBBB'; // Unknown monitor + break; + } + + $icon = get_group_icon($group['id_grupo']); + + if ($simple == 0){ + // Set node icon + if (file_exists ('images/groups_small/'.$icon.'.png')) { + $img_node = ''; + } else { + $img_node = '-'; + } + + $name = get_group_name($group['id_grupo']); + + $node = $group['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.30, height=0.30, label=< +
'.$img_node.'
'.$name.'
>, + shape="ellipse", 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'].'"];'; + } else { + $node = $group['id_node'] . ' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.20, height=0.20, label="", tooltip="ajax.php?page=operation/agentes/ver_agente&get_group_status_tooltip=1&id_group='.$group['id_grupo'].'"];'; + } + return $node; +} + +// Returns a node definition +function create_agent_node ($agent, $simple = 0, $font_size = 10) { + $status = get_agent_status($agent['id_agente']); + + // Set node status + switch($status) { + case 0: + $status_color = '#8DFF1D'; // Normal monitor + break; + case 1: + $status_color = '#FF1D1D'; // Critical monitor + break; + case 2: + $status_color = '#FFE308'; // Warning monitor + break; + case 4: + $status_color = '#FFE308'; // Alert fired + break; + default: + $status_color = '#BBBBBB'; // Unknown monitor + break; + } + + // Check for alert + /*$sql = sprintf ('SELECT COUNT(talert_template_modules.id) + FROM talert_template_modules, tagente_modulo, tagente + WHERE tagente.id_agente = %d + AND tagente.disabled = 0 + AND tagente.id_agente = tagente_modulo.id_agente + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module + AND talert_template_modules.times_fired > 0 ', + $agent['id_agente']); + $alert_modules = get_db_sql ($sql); + if ($alert_modules) + $status_color = '#FFE308';*/ + + // Short name + $name = strtolower ($agent["nombre"]); + if (strlen ($name) > 16) + $name = substr ($name, 0, 16); + + if ($simple == 0){ + // Set node icon + if (file_exists ('images/networkmap/'.$agent['id_os'].'.png')) { + $img_node = 'images/networkmap/'.$agent['id_os'].'.png'; + } else { + $img_node = 'images/networkmap/0.png'; + } + + $node = $agent['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.40, height=0.40, label=< +
'.$name.'
>, + shape="ellipse", 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'].'"];'; + } else { + $node = $agent['id_node'] . ' [ color="' . $status_color . '", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.20, height=0.20, label="", tooltip="ajax.php?page=operation/agentes/ver_agente&get_agent_status_tooltip=1&id_agent='.$agent['id_agente'].'"];'; + } + return $node; +} + +// Returns a module node definition +function create_module_node ($module, $simple = 0, $font_size = 10) { + $status = get_agentmodule_status($module['id_agente_modulo']); + + // Set node status + switch($status) { + case 0: + $status_color = '#8DFF1D'; // Normal monitor + break; + case 1: + $status_color = '#FF1D1D'; // Critical monitor + break; + case 2: + $status_color = '#FFE308'; // Warning monitor + break; + case 4: + $status_color = '#FFE308'; // Alert fired + break; + default: + $status_color = '#BBBBBB'; // Unknown monitor + break; + } + + + if ($simple == 0){ + $node = $module['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.30, height=0.30, label=< +
'.print_moduletype_icon ($module['id_tipo_modulo'], true).'
'.$module['nombre'].'
>, + shape="ellipse", 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'].'"];'; + } else { + $node = $module['id_node'] . ' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.20, height=0.20, label="", tooltip="ajax.php?page=operation/agentes/ver_agente&get_agentmodule_status_tooltip=1&id_module='.$module['id_agente_modulo'].'"];'; + } + return $node; +} + // Returns the definition of the central module function create_pandora_node ($name, $font_size = 10, $simple = 0) { $img = ''; diff --git a/pandora_console/operation/agentes/networkmap.groups.php b/pandora_console/operation/agentes/networkmap.groups.php new file mode 100644 index 0000000000..7e92dca73c --- /dev/null +++ b/pandora_console/operation/agentes/networkmap.groups.php @@ -0,0 +1,205 @@ + 'circular', + 'radial' => 'radial', + 'spring1' => 'spring 1', + 'spring2' => 'spring 2', + 'flat' => 'flat'); + +echo '
'; +echo ''; +echo '
'; +echo ''; +echo ''; +echo ''; +echo ''; +echo ''; +echo ''; +echo '
' . __('Group') . '
'; +print_select_from_sql ('SELECT id_grupo, nombre FROM tgrupo WHERE id_grupo > 0 ORDER BY nombre', 'group', $group, '', 'All', 0, false); +echo '
' . __('Module group') . '
'; +print_select_from_sql ('SELECT id_mg, name FROM tmodule_group', 'module_group', $module_group, '', 'All', 0, false); +echo '
' . __('Layout') . '
'; +print_select ($layout_array, 'layout', $layout, '', '', ''); +echo '
' . __('Depth') . '
'; +$depth_levels = array('all' => __('All'), 'agent' => __('Agents'), 'group' => __('Groups')); +print_select ($depth_levels, 'depth', $depth, '', '', '', 0, false, false); +echo '
'; + +echo '
'; + +echo ''; +echo ''; +echo ''; + +echo ''; + +if(($depth == 'all') && $config['enterprise_installed']) { + echo ''; +} + +echo ''; + +echo ''; + +if ($pure == "1") { + // Zoom + $zoom_array = array ( + '1' => 'x1', + '1.2' => 'x2', + '1.6' => 'x3', + '2' => 'x4', + '2.5' => 'x5', + '5' => 'x10', + ); + + echo ''; + +} + +if ($nooverlap == 1){ + echo ""; +} + +echo ""; + +//echo ' Display groups '; +echo ''; +echo '
' . __('No Overlap') . '
'; +print_checkbox ('nooverlap', '1', $nooverlap); +echo '
' . __('Only modules with alerts') . '
'; +print_checkbox ('modwithalerts', '1', $modwithalerts); +echo '
' . __('Hide policy modules') . '
'; + print_checkbox ('hidepolicymodules', '1', $hidepolicymodules); + echo '
' . __('Simple') . '
'; +print_checkbox ('simple', '1', $simple); +echo '
' . __('Regenerate') . '
'; +print_checkbox ('regen', '1', $regen); +echo '
' . __('Zoom') . '
'; + print_select ($zoom_array, 'zoom', $zoom, '', '', '', 0, false, false, false); + echo '
"; + echo __('Distance between nodes') . '
'; + print_input_text ('ranksep', $ranksep, $alt = 'Separation between elements in the map (in Non-overlap mode)', 3, 4, 0); + echo "
"; +echo __('Font') . '
'; +print_input_text ('font_size', $font_size, $alt = 'Font size (in pt)', 2, 4, 0); +echo "
'; +print_submit_button (__('Update'), "updbutton", false, 'class="sub upd"'); +echo '
'; +echo '
'; + +// Set filter +$filter = get_filter ($layout); + +// Generate dot file +$graph = generate_dot_groups (__('Pandora FMS'), $group, $simple, $font_size, $layout, $nooverlap, $zoom, $ranksep, $center, $regen, $pure, $modwithalerts, $module_group, $hidepolicymodules, $depth); + +if ($graph === false) { + print_error_message (__('Map could not be generated')); + echo '
' . __('No agents found') . '
'; + return; +} + +// 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 +$filename_map = $config["attachment_store"]."/networkmap_".$layout; +$filename_img = "attachment/networkmap_".$layout."_".$font_size; +$filename_dot = $config["attachment_store"]."/networkmap_".$layout; +if ($simple) { + $filename_map .= "_simple"; + $filename_img .= "_simple"; + $filename_dot .= "_simple"; +} +if ($nooverlap) { + $filename_map .= "_nooverlap"; + $filename_img .= "_nooverlap"; + $filename_dot .= "_nooverlap"; +} +$filename_map .= ".map"; +$filename_img .= ".png"; +$filename_dot .= ".dot"; + +if ($regen != 1 && file_exists ($filename_img) && filemtime ($filename_img) > get_system_time () - 300) { + $result = true; +} else { + $fh = @fopen ($filename_dot, 'w'); + if ($fh === false) { + $result = false; + } else { + fwrite ($fh, $graph); + $cmd = "$filter -Tcmapx -o".$filename_map." -Tpng -o".$filename_img." ".$filename_dot; + $result = system ($cmd); + fclose ($fh); + unlink ($filename_dot); + } +} + +if ($result !== false) { + if (! file_exists ($filename_map)) { + print_error_message (__('Map could not be generated')); + echo $result; + echo "
Apparently something went wrong reading the output.
"; + echo "
Is ".$config["attachment_store"]." readable by the webserver process?"; + echo "

Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver process?"; + return; + } + print_image ($filename_img, false, array ("alt" => __('Network map'), "usemap" => "#networkmap")); + require ($filename_map); +} else { + print_error_message (__('Map could not be generated')); + echo $result; + echo "
Apparently something went wrong executing the command or writing the output.
"; + echo "
Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver process?"; + echo "

Is your webserver restricted from executing command line tools through the system() call (PHP Safe Mode or SELinux)"; + echo "

Is ".$config["attachment_store"]." writeable by the webserver process? To change this do the following (POSIX-based systems): chown <apache user> ".$config["attachment_store"]; + return; +} + +?> diff --git a/pandora_console/operation/agentes/networkmap.php b/pandora_console/operation/agentes/networkmap.php index 79b37db2ff..a2c98c5c18 100644 --- a/pandora_console/operation/agentes/networkmap.php +++ b/pandora_console/operation/agentes/networkmap.php @@ -39,151 +39,61 @@ $regen = (int) 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); +$activeTab = get_parameter ('tab', 'topology'); /* Main code */ if ($pure == 1) { - $onheader = ''; - $onheader .= print_image ("images/normalscreen.png", true, array ('title' => __('Normal screen'), 'alt' => __('Normal screen'))); - $onheader .= ''; + $buttons['screen'] = array('active' => false, + 'text' => '' . + print_image("images/normalscreen.png", true, array ('title' => __('Normal screen'))) .''); + } else { - $onheader = ''; - $onheader .= print_image ("images/fullscreen.png", true, array ('title' => __('Full screen'), 'alt' => __('Normal screen'))); - $onheader .= ''; + $buttons['screen'] = array('active' => false, + 'text' => '' . + print_image("images/fullscreen.png", true, array ('title' => __('Full screen'))) .''); +} +if($config['enterprise_installed']) { + $buttons['policies'] = array('active' => $activeTab == 'policies', + 'text' => '' . + print_image("images/policies.png", true, array ("title" => __('Policies view'))) .''); +} + +$buttons['groups'] = array('active' => $activeTab == 'groups', + 'text' => '' . + print_image("images/group.png", true, array ("title" => __('Groups view'))) .''); + +$buttons['topology'] = array('active' => $activeTab == 'topology', + 'text' => '' . + print_image("images/recon.png", true, array ("title" => __('Topology view'))) .''); + +switch($activeTab){ + case 'topology': + $title = __('Topology view'); + break; + case 'groups': + $title = __('Groups view'); + break; + case 'policies': + $title = __('Policies view'); + break; } -print_page_header (__('Network map'), "images/bricks.png", false, "", false, $onheader); +print_page_header (__('Network map')." - ".$title, "images/bricks.png", false, "", false, $buttons); -// Layout selection -$layout_array = array ( - 'circular' => 'circular', - 'radial' => 'radial', - 'spring1' => 'spring 1', - 'spring2' => 'spring 2', - 'flat' => 'flat'); - -echo '
'; -echo ''; -echo ''; -echo ''; -echo ''; - -echo ''; - -echo ''; - -echo ''; - -if ($pure == "1") { - // Zoom - $zoom_array = array ( - '1' => 'x1', - '1.2' => 'x2', - '1.6' => 'x3', - '2' => 'x4', - '2.5' => 'x5', - '5' => 'x10', - ); - - echo ''; - -} - -if ($nooverlap == 1){ - echo ""; -} - -echo ""; - -//echo ' Display groups '; -echo ''; -echo '
' . __('Group') . '
'; -print_select_groups(false, false, false, 'group', $group, '', 'All', 0, false); -echo '
' . __('Layout') . '
'; -print_select ($layout_array, 'layout', $layout, '', '', ''); -echo '
' . __('No Overlap') . '
'; -print_checkbox ('nooverlap', '1', $nooverlap); -echo '
' . __('Simple') . '
'; -print_checkbox ('simple', '1', $simple); -echo '
' . __('Regenerate') . '
'; -print_checkbox ('regen', '1', $regen); -echo '
' . __('Zoom') . '
'; - print_select ($zoom_array, 'zoom', $zoom, '', '', '', 0, false, false, false); - echo '
"; - echo __('Distance between nodes') . '
'; - print_input_text ('ranksep', $ranksep, $alt = 'Separation between elements in the map (in Non-overlap mode)', 3, 4, 0); - echo "
"; -echo __('Font') . '
'; -print_input_text ('font_size', $font_size, $alt = 'Font size (in pt)', 2, 4, 0); -echo "
'; -print_submit_button (__('Update'), "updbutton", false, 'class="sub upd"'); -echo '
'; - -// Set filter -$filter = get_filter ($layout); - -// Generate dot file -$graph = generate_dot (__('Pandora FMS'), $group, $simple, $font_size, $layout, $nooverlap, $zoom, $ranksep, $center, $regen, $pure); - -if ($graph === false) { - print_error_message (__('Map could not be generated')); - echo '
' . __('No agents found') . '
'; - return; -} - -// 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 -$filename_map = $config["attachment_store"]."/networkmap_".$layout; -$filename_img = "attachment/networkmap_".$layout."_".$font_size; -$filename_dot = $config["attachment_store"]."/networkmap_".$layout; -if ($simple) { - $filename_map .= "_simple"; - $filename_img .= "_simple"; - $filename_dot .= "_simple"; -} -if ($nooverlap) { - $filename_map .= "_nooverlap"; - $filename_img .= "_nooverlap"; - $filename_dot .= "_nooverlap"; -} -$filename_map .= ".map"; -$filename_img .= ".png"; -$filename_dot .= ".dot"; - -if ($regen != 1 && file_exists ($filename_img) && filemtime ($filename_img) > get_system_time () - 300) { - $result = true; -} else { - $fh = @fopen ($filename_dot, 'w'); - if ($fh === false) { - $result = false; - } else { - fwrite ($fh, $graph); - $cmd = "$filter -Tcmapx -o".$filename_map." -Tpng -o".$filename_img." ".$filename_dot; - $result = system ($cmd); - fclose ($fh); - unlink ($filename_dot); - } -} - -if ($result !== false) { - if (! file_exists ($filename_map)) { - print_error_message (__('Map could not be generated')); - echo $result; - echo "
Apparently something went wrong reading the output.
"; - echo "
Is ".$config["attachment_store"]." readable by the webserver process?"; - echo "

Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver process?"; - return; - } - print_image ($filename_img, false, array ("alt" => __('Network map'), "usemap" => "#networkmap")); - require ($filename_map); -} else { - print_error_message (__('Map could not be generated')); - echo $result; - echo "
Apparently something went wrong executing the command or writing the output.
"; - echo "
Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver process?"; - echo "

Is your webserver restricted from executing command line tools through the system() call (PHP Safe Mode or SELinux)"; - echo "

Is ".$config["attachment_store"]." writeable by the webserver process? To change this do the following (POSIX-based systems): chown <apache user> ".$config["attachment_store"]; - return; +switch ($activeTab) { + case 'topology': + require_once('operation/agentes/networkmap.topology.php'); + break; + case 'groups': + require_once('operation/agentes/networkmap.groups.php'); + break; + case 'policies': + require_once(''.ENTERPRISE_DIR.'/operation/policies/networkmap.policies.php'); + break; + default: + enterprise_selectTab($activeTab); + break; } ?> diff --git a/pandora_console/operation/agentes/networkmap.topology.php b/pandora_console/operation/agentes/networkmap.topology.php new file mode 100644 index 0000000000..4679e9da29 --- /dev/null +++ b/pandora_console/operation/agentes/networkmap.topology.php @@ -0,0 +1,175 @@ + 'circular', + 'radial' => 'radial', + 'spring1' => 'spring 1', + 'spring2' => 'spring 2', + 'flat' => 'flat'); + +echo '
'; +echo ''; +echo ''; +echo ''; +echo ''; + +echo ''; + +echo ''; + +echo ''; + +if ($pure == "1") { + // Zoom + $zoom_array = array ( + '1' => 'x1', + '1.2' => 'x2', + '1.6' => 'x3', + '2' => 'x4', + '2.5' => 'x5', + '5' => 'x10', + ); + + echo ''; + +} + +if ($nooverlap == 1){ + echo ""; +} + +echo ""; + +//echo ' Display groups '; +echo ''; +echo '
' . __('Group') . '
'; +print_select_groups(false, false, false, 'group', $group, '', 'All', 0, false); +echo '
' . __('Layout') . '
'; +print_select ($layout_array, 'layout', $layout, '', '', ''); +echo '
' . __('No Overlap') . '
'; +print_checkbox ('nooverlap', '1', $nooverlap); +echo '
' . __('Simple') . '
'; +print_checkbox ('simple', '1', $simple); +echo '
' . __('Regenerate') . '
'; +print_checkbox ('regen', '1', $regen); +echo '
' . __('Zoom') . '
'; + print_select ($zoom_array, 'zoom', $zoom, '', '', '', 0, false, false, false); + echo '
"; + echo __('Distance between nodes') . '
'; + print_input_text ('ranksep', $ranksep, $alt = 'Separation between elements in the map (in Non-overlap mode)', 3, 4, 0); + echo "
"; +echo __('Font') . '
'; +print_input_text ('font_size', $font_size, $alt = 'Font size (in pt)', 2, 4, 0); +echo "
'; +print_submit_button (__('Update'), "updbutton", false, 'class="sub upd"'); +echo '
'; + +// Set filter +$filter = get_filter ($layout); + +// Generate dot file +$graph = generate_dot (__('Pandora FMS'), $group, $simple, $font_size, $layout, $nooverlap, $zoom, $ranksep, $center, $regen, $pure); + +if ($graph === false) { + print_error_message (__('Map could not be generated')); + echo '
' . __('No agents found') . '
'; + return; +} + +// 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 +$filename_map = $config["attachment_store"]."/networkmap_".$layout; +$filename_img = "attachment/networkmap_".$layout."_".$font_size; +$filename_dot = $config["attachment_store"]."/networkmap_".$layout; +if ($simple) { + $filename_map .= "_simple"; + $filename_img .= "_simple"; + $filename_dot .= "_simple"; +} +if ($nooverlap) { + $filename_map .= "_nooverlap"; + $filename_img .= "_nooverlap"; + $filename_dot .= "_nooverlap"; +} +$filename_map .= ".map"; +$filename_img .= ".png"; +$filename_dot .= ".dot"; + +if ($regen != 1 && file_exists ($filename_img) && filemtime ($filename_img) > get_system_time () - 300) { + $result = true; +} else { + $fh = @fopen ($filename_dot, 'w'); + if ($fh === false) { + $result = false; + } else { + fwrite ($fh, $graph); + $cmd = "$filter -Tcmapx -o".$filename_map." -Tpng -o".$filename_img." ".$filename_dot; + $result = system ($cmd); + fclose ($fh); + unlink ($filename_dot); + } +} + +if ($result !== false) { + if (! file_exists ($filename_map)) { + print_error_message (__('Map could not be generated')); + echo $result; + echo "
Apparently something went wrong reading the output.
"; + echo "
Is ".$config["attachment_store"]." readable by the webserver process?"; + echo "

Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver process?"; + return; + } + print_image ($filename_img, false, array ("alt" => __('Network map'), "usemap" => "#networkmap")); + require ($filename_map); +} else { + print_error_message (__('Map could not be generated')); + echo $result; + echo "
Apparently something went wrong executing the command or writing the output.
"; + echo "
Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver process?"; + echo "

Is your webserver restricted from executing command line tools through the system() call (PHP Safe Mode or SELinux)"; + echo "

Is ".$config["attachment_store"]." writeable by the webserver process? To change this do the following (POSIX-based systems): chown <apache user> ".$config["attachment_store"]; + return; +} + +?> diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index d786009ca3..32c61e9734 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -30,6 +30,8 @@ if (is_ajax ()) { $get_agent_json = (bool) get_parameter ('get_agent_json'); $get_agent_modules_json = (bool) get_parameter ('get_agent_modules_json'); $get_agent_status_tooltip = (bool) get_parameter ("get_agent_status_tooltip"); + $get_agentmodule_status_tooltip = (bool) get_parameter ("get_agentmodule_status_tooltip"); + $get_group_status_tooltip = (bool) get_parameter ("get_group_status_tooltip"); $get_agents_group_json = (bool) get_parameter ("get_agents_group_json"); $get_agent_modules_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_json_for_multiple_agents"); $get_agent_modules_json_for_multiple_agents_id = (bool) get_parameter("get_agent_modules_json_for_multiple_agents_id"); @@ -118,7 +120,9 @@ if (is_ajax ()) { if ($get_agent_status_tooltip) { $id_agent = (int) get_parameter ('id_agent'); $agent = get_db_row ('tagente', 'id_agente', $id_agent); - echo '

'.$agent['nombre'].'

'; + echo '

'; + echo ' '; + echo printTruncateText($agent['nombre'],25,false,true,false).'

'; echo ''.__('Main IP').': '.$agent['direccion'].'
'; echo ''.__('Group').': '; echo ' '; @@ -202,6 +206,60 @@ if (is_ajax ()) { return; } + if ($get_agentmodule_status_tooltip) { + $id_module = (int) get_parameter ('id_module'); + $module = get_db_row ('tagente_modulo', 'id_agente_modulo', $id_module); + echo '

'; + echo ' '; + echo printTruncateText($module['nombre'],25,false,true,false).'

'; + echo ''.__('Type').': '; + $agentmoduletype = get_agentmodule_type ($module['id_agente_modulo']); + echo get_moduletype_name ($agentmoduletype).' '; + echo '
'; + echo ''.__('Module group').': '; + $modulegroup = get_modulegroup_name (get_agentmodule_modulegroup ($module['id_agente_modulo'])); + if($modulegroup === false){ + echo __('None').'
'; + } + else{ + echo $modulegroup.'
'; + } + echo ''.__('Agent').': '; + echo printTruncateText(get_agentmodule_agent_name ($module['id_agente_modulo']),25,false,true,false).'
'; + + return; + } + + if ($get_group_status_tooltip) { + $id_group = (int) get_parameter ('id_group'); + $group = get_db_row ('tgrupo', 'id_grupo', $id_group); + echo '

'; + echo printTruncateText($group['nombre'],25,false,true,false).'

'; + echo ''.__('Parent').': '; + if($group['parent'] == 0) { + echo __('None').'
'; + } + else { + $group_parent = get_db_row ('tgrupo', 'id_grupo', $group['parent']); + echo ' '; + echo $group_parent['nombre'].'
'; + } + echo ''.__('Sons').': '; + $groups_sons = get_db_all_fields_in_table ('tgrupo', 'parent', $group['id_grupo']); + if($groups_sons === false){ + echo __('None').'
'; + } + else{ + echo '

'; + foreach($groups_sons as $group_son) { + echo ' '; + echo $group_son['nombre'].'
'; + } + } + + return; + } + return; }