From d13e7bbf44d7db6917684bb1a5f1a8be67b38c14 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 18 Mar 2019 09:05:47 +0100 Subject: [PATCH] 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;