From 1f7e0a36e4c0f776510871179ed7119aee63a0d8 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 22 Sep 2014 18:41:39 +0200 Subject: [PATCH] Now is possible to show a graph of the interface traffic from the agent view * pandora_console/operation/agentes/interface_traffic_graph_win.php: Added file. Shows a combined graph of the interface traffic. * pandora_console/operation/agentes/estado_generalagente.php: Now a graph icons will appear on the interface information if the modules ifInOctects and ifOutOctets exists for this interface. * pandora_console/include/functions_custom_graphs.php: Modified the function "custom_graphs_print" to add a new parameter to set the base url of the graph images. --- .../include/functions_custom_graphs.php | 4 +- .../agentes/estado_generalagente.php | 87 ++++-- .../agentes/interface_traffic_graph_win.php | 272 ++++++++++++++++++ 3 files changed, 342 insertions(+), 21 deletions(-) create mode 100644 pandora_console/operation/agentes/interface_traffic_graph_win.php diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index 41b28bb872..4b1c12acf0 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -152,7 +152,7 @@ function custom_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGr function custom_graphs_print($id_graph, $height, $width, $period, $stacked = null, $return = false, $date = 0, $only_image = false, - $background_color = 'white', $modules_param = array()) { + $background_color = 'white', $modules_param = array(), $homeurl = '') { global $config; @@ -210,7 +210,7 @@ function custom_graphs_print($id_graph, $height, $width, $period, $stacked, $date, $only_image, - '', + $homeurl, 1, false, false, diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index a148403914..5441cbdada 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -379,7 +379,7 @@ $filter = array( "id_agente" => $id_agente, "id_tipo_modulo" => (int)db_get_value("id_tipo", "ttipo_modulo", "nombre", "remote_snmp_proc") ); -$modules = agents_get_modules ($id_agente, $columns, $filter); +$modules = agents_get_modules($id_agente, $columns, $filter); if (! empty($modules)) { $table_interface = new stdClass(); @@ -387,7 +387,8 @@ if (! empty($modules)) { $table_interface->class = 'databox'; $table_interface->width = '100%'; $table_interface->style = array(); - $table_interface->style[1] = 'width: 30px;'; + $table_interface->style['interface_status'] = 'width: 30px;'; + $table_interface->style['interface_graph'] = 'width: 20px;'; $table_interface->head = array(); $options = array( "class" => "closed", @@ -396,7 +397,7 @@ if (! empty($modules)) { $table_interface->head[0] = html_print_image("images/go.png", true, $options) . "  "; $table_interface->head[0] .= '' . __('Interface information') .' (SNMP)'; $table_interface->head_colspan = array(); - $table_interface->head_colspan[0] = 4; + $table_interface->head_colspan[0] = 5; $table_interface->data = array(); foreach ($modules as $key => $module) { @@ -405,7 +406,7 @@ if (! empty($modules)) { if (preg_match ("/_(.+)$/", (string)$module['nombre'], $matches)) { if ($matches[1]) { $interface_name = $matches[1]; - + $module_id = $module['id_agente_modulo']; $db_status = modules_get_agentmodule_status($module_id); $module_value = modules_get_last_value ($module_id); @@ -428,12 +429,59 @@ if (! empty($modules)) { $description = $matches[0]; } } + + // Get the ifInOctets and ifOutOctets modules of the interface + $columns = array( + "id_agente_modulo", + "nombre" + ); + $interface_traffic_modules = agents_get_modules($id_agente, $columns, "nombre LIKE 'if%Octets_$interface_name'"); + if (!empty($interface_traffic_modules) && count($interface_traffic_modules) >= 2) { + $interface_traffic_modules_aux = array('in' => '', 'out' => ''); + foreach ($interface_traffic_modules as $interface_traffic_module) { + if (preg_match ("/if(.+)Octets_$interface_name$/i", (string)$interface_traffic_module['nombre'], $matches)) { + if (strtolower($matches[1]) == 'in') { + $interface_traffic_modules_aux['in'] = $interface_traffic_module['id_agente_modulo']; + } + elseif (strtolower($matches[1]) == 'out') { + $interface_traffic_modules_aux['out'] = $interface_traffic_module['id_agente_modulo']; + } + } + } + if (!empty($interface_traffic_modules_aux['in']) && !empty($interface_traffic_modules_aux['out'])) { + $interface_traffic_modules = $interface_traffic_modules_aux; + } + else { + $interface_traffic_modules = false; + } + } + else { + $interface_traffic_modules = false; + } + + if ($interface_traffic_modules != false) { + $params = array( + 'interface_name' => $interface_name, + 'agent_id' => $id_agente, + 'traffic_module_in' => $interface_traffic_modules_aux['in'], + 'traffic_module_out' => $interface_traffic_modules_aux['out'] + ); + $params_json = json_encode($params); + $params_encoded = base64_encode($params_json); + $win_handle = dechex(crc32($module_id.$interface_name)); + $graph_link = "" . + html_print_image("images/chart_curve.png", true, array("title" => __('Interface traffic'))) . ""; + } + else { + $graph_link = ""; + } $data = array(); - $data[0] = "" . $interface_name . ""; - $data[1] = $status; - $data[2] = $ip_target; - $data[3] = $description; + $data['interface_name'] = "" . $interface_name . ""; + $data['interface_status'] = $status; + $data['interface_graph'] = $graph_link; + $data['interface_ip'] = $ip_target; + $data['interface_mac'] = $description; $table_interface->data[] = $data; } } @@ -446,17 +494,18 @@ if (! empty($modules)) { $(document).ready (function () { $("#agent_interface_info").find("tbody").hide(); $("#agent_interface_info").find("thead").click (function () { - var arrow = $("#agent_interface_info").find("thead").find("img"); - if (arrow.hasClass("closed")) { - arrow.removeClass("closed"); - arrow.prop("src", "images/down.png"); - $("#agent_interface_info").find("tbody").show(); - } else { - arrow.addClass("closed"); - arrow.prop("src", "images/go.png"); - $("#agent_interface_info").find("tbody").hide(); - } - }); + var arrow = $("#agent_interface_info").find("thead").find("img"); + if (arrow.hasClass("closed")) { + arrow.removeClass("closed"); + arrow.prop("src", "images/down.png"); + $("#agent_interface_info").find("tbody").show(); + } else { + arrow.addClass("closed"); + arrow.prop("src", "images/go.png"); + $("#agent_interface_info").find("tbody").hide(); + } + }) + .css('cursor', 'pointer'); }); load_tables(); +} + +echo ''; + +$params_json = base64_decode((string) get_parameter('params')); +$params = json_decode($params_json, true); + +$interface_name = (string) $params['interface_name']; +$agent_id = (int) $params['agent_id']; +$interface_traffic_modules = array( + 'in' => (int) $params['traffic_module_in'], + 'out' => (int) $params['traffic_module_out'] + ); +?> + + + + 0) { + $query = ui_get_url_refresh(false); + + echo ''; + } +?> + + Pandora FMS Graph (<?php echo agents_get_name($agent_id) . ' - ' . $interface_name; ?>) + + + + + + + + + 1) { + $height = $height * ($zoom / 2.1); + $width = $width * ($zoom / 1.4); + + echo ""; + } + + $current = date("Y-m-d"); + + if ($start_date != $current) + $date = strtotime($start_date); + else + $date = $utime; + + $urlImage = ui_get_full_url(false); + + if ($config['flash_charts'] == 1) + echo '
'; + else + echo '
'; + + $modules = array($interface_traffic_modules['in'], $interface_traffic_modules['out']); + custom_graphs_print(0, $height, $width, $period, null, false, $date, false, 'white', $modules, $config['homeurl']); + + echo '
'; + + /////////////////////////// + // SIDE MENU + /////////////////////////// + $side_layer_params = array(); + // TOP TEXT + $side_layer_params['top_text'] = "
" . html_print_image('images/config_mc.png', true, array('width' => '16px')) . ' ' . __('Pandora FMS Graph configuration menu') . "
"; + $side_layer_params['body_text'] = "'; // outer + + // ICONS + $side_layer_params['icon_closed'] = '/images/graphmenu_arrow_hide.png'; + $side_layer_params['icon_open'] = '/images/graphmenu_arrow.png'; + + // SIZE + $side_layer_params['width'] = 500; + + // POSITION + $side_layer_params['position'] = 'left'; + + html_print_side_layer($side_layer_params); + + // Hidden div to forced title + html_print_div(array('id' => 'forced_title_layer', 'class' => 'forced_title_layer', 'hidden' => true)); +?> + + + +