From 8a7702e054933170b28b75f4aec8c20e914d4f0d Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 18 Mar 2019 09:01:53 +0100 Subject: [PATCH 1/2] Update networkmap class with simple map Former-commit-id: cb6bd489ba973cf0f9c6eda8dee062518f33f382 --- .../include/class/NetworkMap.class.php | 991 ++++++++++-------- 1 file changed, 550 insertions(+), 441 deletions(-) diff --git a/pandora_console/include/class/NetworkMap.class.php b/pandora_console/include/class/NetworkMap.class.php index 8f153eb415..ffc8450aca 100644 --- a/pandora_console/include/class/NetworkMap.class.php +++ b/pandora_console/include/class/NetworkMap.class.php @@ -117,6 +117,16 @@ class NetworkMap */ public $mapOptions; + /** + * loadfile function array + * file path + * function name + * extra parameter(cluster) + * + * @var array + */ + public $loadfile; + /** * Base constructor. @@ -154,6 +164,15 @@ class NetworkMap $this->mapOptions['strict_user'] = false; $this->mapOptions['size_canvas'] = null; $this->mapOptions['old_mode'] = false; + $this->mapOptions['baseurl'] = ui_get_full_url(false, false, false, false); + $this->mapOptions['width'] = '100%'; + $this->mapOptions['height'] = 600; + $this->mapOptions['node_radius'] = 40; + $this->mapOptions['id_cluster'] = null; + $this->mapOptions['tooltip'] = false; + $this->mapOptions['size_image'] = 40; + $this->mapOptions['page_tooltip'] = null; + $this->mapOptions['map_filter'] = [ 'dont_show_subgroups' => 0, 'node_radius' => 40, @@ -206,6 +225,14 @@ class NetworkMap } } + // loadfile options + // This is only used while generating simple maps + if (is_array($options['loadfile'])) { + foreach ($options['loadfile'] as $k => $v) { + $this->loadfile[$k] = $v; + } + } + // Load from tmap. if ($options['id_map']) { $this->idMap = $options['id_map']; @@ -482,35 +509,51 @@ class NetworkMap public function generateDotGraph() { if (!isset($this->dotGraph)) { - // Generate dot file. - $this->dotGraph = networkmap_generate_dot( - get_product_name(), - $this->idGroup, - $this->mapOptions['simple'], - $this->mapOptions['font_size'], - $this->mapOptions['layout'], - $this->mapOptions['nooverlap'], - $this->mapOptions['z_dash'], - $this->mapOptions['ranksep'], - $this->mapOptions['center'], - $this->mapOptions['regen'], - $this->mapOptions['pure'], - $this->mapOptions['id'], - $this->mapOptions['show_snmp_modules'], - $this->mapOptions['cut_names'], - $this->mapOptions['relative'], - $this->mapOptions['text_filter'], - $this->network, - $this->mapOptions['dont_show_subgroups'], - // Strict user (strict_user). - false, - // Canvas size (size_canvas). - null, - $this->mapOptions['old_mode'], - $this->mapOptions['map_filter'] - ); - } + if (isset($this->mode) && $this->mode === 'simple') { + include_once $config['homedir'].'/include/functions_maps.php'; + $graph .= open_graph(); + foreach ($this->nodes as $key => $value) { + $graph .= create_node($value, $this->mapOptions['font_size']); + } + + foreach ($this->relations as $key => $relation) { + $graph .= create_edge($key, $relation); + } + + $graph .= close_graph(); + + $this->dotGraph = $graph; + } else { + // Generate dot file. + $this->dotGraph = networkmap_generate_dot( + get_product_name(), + $this->idGroup, + $this->mapOptions['simple'], + $this->mapOptions['font_size'], + $this->mapOptions['layout'], + $this->mapOptions['nooverlap'], + $this->mapOptions['z_dash'], + $this->mapOptions['ranksep'], + $this->mapOptions['center'], + $this->mapOptions['regen'], + $this->mapOptions['pure'], + $this->mapOptions['id'], + $this->mapOptions['show_snmp_modules'], + $this->mapOptions['cut_names'], + $this->mapOptions['relative'], + $this->mapOptions['text_filter'], + $this->network, + $this->mapOptions['dont_show_subgroups'], + // Strict user (strict_user). + false, + // Canvas size (size_canvas). + null, + $this->mapOptions['old_mode'], + $this->mapOptions['map_filter'] + ); + } + } } @@ -652,158 +695,171 @@ class NetworkMap unlink($filename_dot); - $nodes = networkmap_loadfile( - $this->idMap, - $filename_plain, - $relation_nodes, - $this->dotGraph - ); + if (isset($this->mode) && $this->mode === 'simple') { + if (isset($this->loadfile)) { + include_once $this->loadfile[0]; + $func = $this->loadfile[1]; + // Extra parameter. Used in clustermap. + if (isset($this->mapOptions['id_cluster'])) { + $this->graph = $func($filename_plain, $this->dotGraph, $this->mapOptions['id_cluster']); + } else { + $this->graph = $func($filename_plain, $this->dotGraph); + } + } else { + } + } else { + $nodes = networkmap_loadfile( + $this->idMap, + $filename_plain, + $relation_nodes, + $this->dotGraph + ); - unlink($filename_plain); + unlink($filename_plain); - /* - * Graphviz section ends here. - */ + /* + * Graphviz section ends here. + */ - /* - * Calculate references. - */ + /* + * Calculate references. + */ - // Set the position of modules. - foreach ($nodes as $key => $node) { - if ($node['type'] == 'module') { - // Search the agent of this module for to get the - // position. - foreach ($nodes as $key2 => $node2) { - if ($node2['id_agent'] != 0 && $node2['type'] == 'agent') { - if ($node2['id_agent'] == $node['id_agent']) { - $nodes[$key]['coords'][0] = ($nodes[$key2]['coords'][0] + $node['height'] / 2); - $nodes[$key]['coords'][1] = ($nodes[$key2]['coords'][1] + $node['width'] / 2); + // Set the position of modules. + foreach ($nodes as $key => $node) { + if ($node['type'] == 'module') { + // Search the agent of this module for to get the + // position. + foreach ($nodes as $key2 => $node2) { + if ($node2['id_agent'] != 0 && $node2['type'] == 'agent') { + if ($node2['id_agent'] == $node['id_agent']) { + $nodes[$key]['coords'][0] = ($nodes[$key2]['coords'][0] + $node['height'] / 2); + $nodes[$key]['coords'][1] = ($nodes[$key2]['coords'][1] + $node['width'] / 2); + } } } } } - } - $nodes_and_relations['nodes'] = []; - $index = 0; - $node_center = []; - foreach ($nodes as $key => $node) { - $nodes_and_relations['nodes'][$index]['id'] = $node['id']; - $nodes_and_relations['nodes'][$index]['id_map'] = $this->idMap; + $nodes_and_relations['nodes'] = []; + $index = 0; + $node_center = []; + foreach ($nodes as $key => $node) { + $nodes_and_relations['nodes'][$index]['id'] = $node['id']; + $nodes_and_relations['nodes'][$index]['id_map'] = $this->idMap; - $children_count = 0; - foreach ($relation_nodes as $relation) { - if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) { - if ($nodes[$relation['id_parent']]['id_agent'] == $node['id_agent']) { - $children_count++; - } - } else if ($relation['parent_type'] == 'module') { - if ($nodes[$relation['id_parent']]['id_module'] == $node['id_module']) { - $children_count++; + $children_count = 0; + foreach ($relation_nodes as $relation) { + if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) { + if ($nodes[$relation['id_parent']]['id_agent'] == $node['id_agent']) { + $children_count++; + } + } else if ($relation['parent_type'] == 'module') { + if ($nodes[$relation['id_parent']]['id_module'] == $node['id_module']) { + $children_count++; + } } } + + if (empty($node_center) || $node_center['counter'] < $children_count) { + $node_center['x'] = (int) $node['coords'][0]; + $node_center['y'] = (int) $node['coords'][1]; + $node_center['counter'] = $children_count; + } + + $nodes_and_relations['nodes'][$index]['x'] = (int) $node['coords'][0]; + $nodes_and_relations['nodes'][$index]['y'] = (int) $node['coords'][1]; + + if (($node['type'] == 'agent') || ($node['type'] == '')) { + $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_agent']; + $nodes_and_relations['nodes'][$index]['type'] = 0; + } else { + $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_module']; + $nodes_and_relations['nodes'][$index]['id_agent'] = $node['id_agent']; + $nodes_and_relations['nodes'][$index]['type'] = 1; + } + + $style = []; + $style['shape'] = 'circle'; + $style['image'] = $node['image']; + $style['width'] = $node['width']; + $style['height'] = $node['height']; + $style['label'] = $node['text']; + $nodes_and_relations['nodes'][$index]['style'] = json_encode($style); + + $index++; } - if (empty($node_center) || $node_center['counter'] < $children_count) { - $node_center['x'] = (int) $node['coords'][0]; - $node_center['y'] = (int) $node['coords'][1]; - $node_center['counter'] = $children_count; + $nodes_and_relations['relations'] = []; + $index = 0; + + foreach ($relation_nodes as $relation) { + $nodes_and_relations['relations'][$index]['id_map'] = $this->idMap; + + if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) { + $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; + $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_agent']; + $nodes_and_relations['relations'][$index]['parent_type'] = 0; + } else if ($relation['parent_type'] == 'module') { + $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; + $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_module']; + $nodes_and_relations['relations'][$index]['parent_type'] = 1; + } else { + $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; + $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; + $nodes_and_relations['relations'][$index]['parent_type'] = 3; + } + + if (($relation['child_type'] == 'agent') || ($relation['child_type'] == '')) { + $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; + $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_agent']; + $nodes_and_relations['relations'][$index]['child_type'] = 0; + } else if ($relation['child_type'] == 'module') { + $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; + $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_module']; + $nodes_and_relations['relations'][$index]['child_type'] = 1; + } else { + $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; + $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; + $nodes_and_relations['relations'][$index]['child_type'] = 3; + } + + $index++; } - $nodes_and_relations['nodes'][$index]['x'] = (int) $node['coords'][0]; - $nodes_and_relations['nodes'][$index]['y'] = (int) $node['coords'][1]; + if ($this->idMap > 0 && (!isset($this->map['__simulated']))) { + if (enterprise_installed()) { + $nodes_and_relations = enterprise_hook( + 'save_generate_nodes', + [ + $this->idMap, + $nodes_and_relations, + ] + ); + } - if (($node['type'] == 'agent') || ($node['type'] == '')) { - $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_agent']; - $nodes_and_relations['nodes'][$index]['type'] = 0; - } else { - $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_module']; - $nodes_and_relations['nodes'][$index]['id_agent'] = $node['id_agent']; - $nodes_and_relations['nodes'][$index]['type'] = 1; - } + $center = [ + 'x' => $node_center['x'], + 'y' => $node_center['y'], + ]; - $style = []; - $style['shape'] = 'circle'; - $style['image'] = $node['image']; - $style['width'] = $node['width']; - $style['height'] = $node['height']; - $style['label'] = $node['text']; - $nodes_and_relations['nodes'][$index]['style'] = json_encode($style); - - $index++; - } - - $nodes_and_relations['relations'] = []; - $index = 0; - - foreach ($relation_nodes as $relation) { - $nodes_and_relations['relations'][$index]['id_map'] = $this->idMap; - - if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_agent']; - $nodes_and_relations['relations'][$index]['parent_type'] = 0; - } else if ($relation['parent_type'] == 'module') { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_module']; - $nodes_and_relations['relations'][$index]['parent_type'] = 1; - } else { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; - $nodes_and_relations['relations'][$index]['parent_type'] = 3; - } - - if (($relation['child_type'] == 'agent') || ($relation['child_type'] == '')) { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_agent']; - $nodes_and_relations['relations'][$index]['child_type'] = 0; - } else if ($relation['child_type'] == 'module') { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_module']; - $nodes_and_relations['relations'][$index]['child_type'] = 1; - } else { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; - $nodes_and_relations['relations'][$index]['child_type'] = 3; - } - - $index++; - } - - if ($this->idMap > 0 && (!isset($this->map['__simulated']))) { - if (enterprise_installed()) { - $nodes_and_relations = enterprise_hook( - 'save_generate_nodes', + $this->map['center_x'] = $center['x']; + $this->map['center_y'] = $center['y']; + db_process_sql_update( + 'tmap', [ - $this->idMap, - $nodes_and_relations, - ] + 'center_x' => $this->map['center_x'], + 'center_y' => $this->map['center_y'], + ], + ['id' => $this->idMap] ); + } else { + $this->map['center_x'] = $node_center['x']; + $this->map['center_y'] = $node_center['y']; } - $center = [ - 'x' => $node_center['x'], - 'y' => $node_center['y'], - ]; - - $this->map['center_x'] = $center['x']; - $this->map['center_y'] = $center['y']; - db_process_sql_update( - 'tmap', - [ - 'center_x' => $this->map['center_x'], - 'center_y' => $this->map['center_y'], - ], - ['id' => $this->idMap] - ); - } else { - $this->map['center_x'] = $node_center['x']; - $this->map['center_y'] = $node_center['y']; + $this->graph = $nodes_and_relations; } - - $this->graph = $nodes_and_relations; - } @@ -814,221 +870,245 @@ class NetworkMap */ public function loadMapData() { - $networkmap = $this->map; + if (isset($this->mode) && $this->mode === 'simple') { + $output .= ''; + + return $output; + } else { + $networkmap = $this->map; + + $simulate = false; + if (!isset($networkmap['__simulated'])) { + $networkmap['filter'] = json_decode( + $networkmap['filter'], + true + ); + $networkmap['filter']['holding_area'] = [ + 500, + 500, + ]; + $holding_area_title = __('Holding Area'); + } else { + $simulate = true; + $holding_area_title = ''; + $networkmap['filter']['holding_area'] = [ + 0, + 0, + ]; + } + + $this->graph['relations'] = clean_duplicate_links( + $this->graph['relations'] ); - $networkmap['filter']['holding_area'] = [ - 500, - 500, - ]; - $holding_area_title = __('Holding Area'); - } else { - $simulate = true; - $holding_area_title = ''; - $networkmap['filter']['holding_area'] = [ - 0, - 0, - ]; - } - $this->graph['relations'] = clean_duplicate_links( - $this->graph['relations'] - ); + // Print some params to handle it in js. + html_print_input_hidden('product_name', get_product_name()); + html_print_input_hidden('center_logo', ui_get_full_url(ui_get_logo_to_center_networkmap())); - // Print some params to handle it in js. - html_print_input_hidden('product_name', get_product_name()); - html_print_input_hidden('center_logo', ui_get_full_url(ui_get_logo_to_center_networkmap())); + $output .= ''; + + return $output; } - - $relations = $this->graph['relations']; - - if ($relations === false) { - $relations = []; - } - - // Clean the relations and transform the module relations into - // interfaces. - networkmap_clean_relations_for_js($relations); - - $links_js = networkmap_links_to_js_links( - $relations, - $nodes_graph, - $simulate - ); - - $array_aux = []; - foreach ($links_js as $link_js) { - if ($link_js['deleted']) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['target'] == -1) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['source'] == -1) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['target'] == $link_js['source']) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['arrow_start'] == 'module' && $link_js['arrow_end'] == 'module') { - $output .= 'networkmap.links.push('.json_encode($link_js).");\n"; - $array_aux[$link_js['id_agent_start']] = 1; - unset($links_js[$link_js['id']]); - } - } - - foreach ($links_js as $link_js) { - if (($link_js['id_agent_end'] === 0) && $array_aux[$link_js['id_agent_start']] === 1) { - continue; - } else { - $output .= 'networkmap.links.push('.json_encode($link_js).");\n"; - } - } - - $output .= ' - //////////////////////////////////////////////////////////////////// - // INTERFACE STATUS COLORS - //////////////////////////////////////////////////////////////////// - '; - - $module_color_status = []; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_NORMAL, - 'color' => COL_NORMAL, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_CRITICAL_BAD, - 'color' => COL_CRITICAL, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_WARNING, - 'color' => COL_WARNING, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_STATUS_ALERT_FIRED, - 'color' => COL_ALERTFIRED, - ]; - $module_color_status_unknown = COL_UNKNOWN; - - $output .= 'var module_color_status = '.json_encode($module_color_status).";\n"; - $output .= "var module_color_status_unknown = '".$module_color_status_unknown."';\n"; - - $output .= ' - //////////////////////////////////////////////////////////////////// - // Other vars - //////////////////////////////////////////////////////////////////// - '; - - $output .= "var translation_none = '".__('None')."';\n"; - $output .= "var dialog_node_edit_title = '".__('Edit node %s')."';\n"; - $output .= "var holding_area_title = '".$holding_area_title."';\n"; - $output .= "var edit_menu = '".__('Show details and options')."';\n"; - $output .= "var interface_link_add = '".__('Add a interface link')."';\n"; - $output .= "var set_parent_link = '".__('Set parent interface')."';\n"; - $output .= "var set_as_children_menu = '".__('Set as children')."';\n"; - $output .= "var set_parent_menu = '".__('Set parent')."';\n"; - $output .= "var abort_relationship_menu = '".__('Abort the action of set relationship')."';\n"; - $output .= "var delete_menu = '".__('Delete')."';\n"; - $output .= "var add_node_menu = '".__('Add node')."';\n"; - $output .= "var set_center_menu = '".__('Set center')."';\n"; - $output .= "var refresh_menu = '".__('Refresh')."';\n"; - $output .= "var refresh_holding_area_menu = '".__('Refresh Holding area')."';\n"; - $output .= "var ok_button = '".__('Proceed')."';\n"; - $output .= "var message_to_confirm = '".__('Resetting the map will delete all customizations you have done, including manual relationships between elements, new items, etc.')."';\n"; - $output .= "var warning_message = '".__('WARNING')."';\n"; - $output .= "var ok_button = '".__('Proceed')."';\n"; - $output .= "var cancel_button = '".__('Cancel')."';\n"; - $output .= "var restart_map_menu = '".__('Restart map')."';\n"; - $output .= "var abort_relationship_interface = '".__('Abort the interface relationship')."';\n"; - $output .= "var abort_relationship_menu = '".__('Abort the action of set relationship')."';\n"; - - $output .= ''; - - return $output; } @@ -1446,46 +1526,57 @@ class NetworkMap { $output = ''; - // Generate JS for advanced controller. - $output .= ' - -'; - - if ($return === false) { + if (isset($this->mode) && $this->mode === 'simple') { + $output .= ''; echo $output; - } + } else { + // Generate JS for advanced controller. + $output .= ' - return $output; + '; + + if ($return === false) { + echo $output; + } + + return $output; + } } @@ -1499,55 +1590,73 @@ class NetworkMap { global $config; - ui_require_css_file('networkmap'); - ui_require_css_file('jquery.contextMenu', 'include/styles/js/'); - $output = ''; - $minimap_display = ''; - if ($this->mapOptions['pure']) { - $minimap_display = 'none'; + + if (isset($this->mode) && $this->mode === 'simple') { + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''."\n"; + + $output .= '
'; + $output .= ''; + + $output .= ''; + $output .= '
'; + + return $output; + } else { + ui_require_css_file('networkmap'); + ui_require_css_file('jquery.contextMenu', 'include/styles/js/'); + + $minimap_display = ''; + if ($this->mapOptions['pure']) { + $minimap_display = 'none'; + } + + $networkmap = $this->map; + $networkmap['filter'] = json_decode($networkmap['filter'], true); + + $networkmap['filter']['l2_network_interfaces'] = 1; + + $output .= ''; + $output .= ''; + $output .= ''; + + // Open networkconsole_id div. + $output .= '
'; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= '
'; + + $output .= '
map; - $networkmap['filter'] = json_decode($networkmap['filter'], true); - - $networkmap['filter']['l2_network_interfaces'] = 1; - - $output .= ''; - $output .= ''; - $output .= ''; - - // Open networkconsole_id div. - $output .= '
'; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= '
'; - - $output .= '
Date: Mon, 18 Mar 2019 09:05:47 +0100 Subject: [PATCH 2/2] new generic functions Former-commit-id: 09352ca97ea73505acdb44d14cde79b0d916d286 --- pandora_console/include/functions_maps.php | 216 ++++++++++++++++++ .../include/styles/cluster_view.css | 2 +- 2 files changed, 217 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_maps.php b/pandora_console/include/functions_maps.php index 2de8dc4b57..ed9b1bab06 100644 --- a/pandora_console/include/functions_maps.php +++ b/pandora_console/include/functions_maps.php @@ -221,3 +221,219 @@ function run_graphviz($filename_map, $filename_dot, $layout, $graph) return $filename_plain; } + + +function open_graph($size_x=50, $size_y=25) +{ + $size = ''; + + $size = $size_x.','.$size_y; + + // BEWARE: graphwiz DONT use single ('), you need double ("). + $head = 'graph vmwaremap { labeljust=l; margin=0; '; + $head .= 'ratio=fill;'; + $head .= 'root=0;'; + $head .= 'rankdir=LR;'; + $head .= 'size="'.$size.'";'; + + return $head; +} + + +function create_node($node, $font_size=10) +{ + // Set node status. + if (isset($node['status'])) { + switch ($node['status']) { + case AGENT_MODULE_STATUS_NORMAL: + $status_color = COL_NORMAL; + // Normal monitor. + break; + + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $status_color = COL_CRITICAL; + // Critical monitor. + break; + + case AGENT_MODULE_STATUS_WARNING: + $status_color = COL_WARNING; + // Warning monitor. + break; + + case AGENT_STATUS_ALERT_FIRED: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_WARNING_ALERT: + $status_color = COL_ALERTFIRED; + // Alert fired. + break; + + case AGENT_MODULE_STATUS_NOT_INIT: + $status_color = COL_NOTINIT; + // Not init. + break; + + default: + $status_color = COL_UNKNOWN; + // Unknown monitor. + break; + } + + $status_color = 'color="'.$status_color.'",'; + } else { + $status_color = ''; + } + + // Short name. + if (isset($node['nombre'])) { + $name = io_safe_output(strtolower($node['nombre'])); + if (strlen($name) > 16) { + $name = substr($name, 0, 16).'...'; + } + } + + // Set node icon. + if (isset($node['image'])) { + if (file_exists($node['image'])) { + $img_node = $node['image']; + } else { + $img_node = null; + } + } else { + $img_node = null; + } + + $result = $node['id_node'].' [ '.$status_color.' fontsize='.$font_size.', style="filled", fixedsize=true, width=0.40, height=0.40, label=< +
'.html_print_image($img_node, true, false, false, true).'
'.$name.'
>, + shape="doublecircle", + tooltip="ajax.php?page=operation/agentes/ver_agente&get_agent_status_tooltip=1&id_agent='.$node['id'].'"];'; + + return $result; +} + + +/** + * Returns an edge definition. + * + * @param string $head Origin. + * @param string $tail Target. + * + * @return string Edge str. + */ +function create_edge($head, $tail) +{ + // Token edgeURL allows node navigation. + $edge = $head.' -- '.$tail.'[color="#BDBDBD", headclip=false, tailclip=false];'."\n"; + + return $edge; +} + + +// Closes a graph definition +function close_graph() +{ + return '}'; +} + + +function loadfile_map($file='', $graph) +{ + global $config; + + $networkmap_nodes = []; + + $relations = []; + + $other_file = file($file); + $graph = explode(']', $graph); + + $ids = []; + foreach ($graph as $node) { + $line = str_replace("\n", ' ', $node); + if (preg_match('/([0-9]+) \[.*tooltip.*id_agent=([0-9]+)/', $line, $match) != 0) { + $ids[$match[1]] = ['id_agent' => $match[2]]; + } + } + + foreach ($other_file as $key => $line) { + $line = preg_replace('/[ ]+/', ' ', $line); + + $data = []; + + if (preg_match('/^node.*$/', $line) != 0) { + $items = explode(' ', $line); + $node_id = $items[1]; + $node_x = ($items[2] * 100); + // 200 is for show more big + $node_y = ($height_map - $items[3] * 100); + // 200 is for show more big + $data['id'] = $node_id; + $data['image'] = ''; + $data['width'] = 10; + $data['height'] = 10; + $data['id_agent'] = 0; + + if (preg_match('/ $line_orig, + 'dest' => $line_dest, + ]; + } + } + + return $networkmap_nodes; +} diff --git a/pandora_console/include/styles/cluster_view.css b/pandora_console/include/styles/cluster_view.css index 74e30f1a8c..4d8f02ccb9 100644 --- a/pandora_console/include/styles/cluster_view.css +++ b/pandora_console/include/styles/cluster_view.css @@ -58,7 +58,7 @@ overflow-y: scroll; } -#cluster_map { +#simple_map { border: 1px solid lightgray; width: 900px; height: 500px;