From 8bc980528820af605ef7d8efa7b07973e9b9b719 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 3 May 2018 12:57:24 +0200 Subject: [PATCH 1/8] [Realtime Graphs] Added the hidden type snmp_module --- .../extensions/realtime_graphs.php | 45 +++++++++++++------ .../extensions/realtime_graphs/ajax.php | 1 + .../realtime_graphs/realtime_graphs.js | 2 +- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/pandora_console/extensions/realtime_graphs.php b/pandora_console/extensions/realtime_graphs.php index a218d59710..53b1d8387d 100644 --- a/pandora_console/extensions/realtime_graphs.php +++ b/pandora_console/extensions/realtime_graphs.php @@ -69,26 +69,40 @@ function pandora_realtime_graphs () { $graph = get_parameter('graph', 'cpu_load'); $refresh = get_parameter('refresh', '1000'); - $data['graph'] = __('Graph') . '  ' . html_print_select ($graph_fields, 'graph', $graph, '', '', 0, true); + if ($graph != 'snmp_module') { + $data['graph'] = __('Graph') . '  ' . html_print_select ($graph_fields, 'graph', $graph, '', '', 0, true); + } $refresh_fields[1000] = human_time_description_raw(1, true, 'large'); $refresh_fields[5000] = human_time_description_raw(5, true, 'large'); $refresh_fields[10000] = human_time_description_raw(10, true, 'large'); $refresh_fields[30000] = human_time_description_raw(30, true, 'large'); + if ($graph == 'snmp_module') { + $agent_alias = get_parameter('agent_alias', ''); + $module_name = get_parameter('module_name', ''); + $module_incremental = get_parameter ('incremental', 0); + $data['module_info'] = "$agent_alias: $module_name"; + + // Append all the hidden in this cell + $data['module_info'] .= html_print_input_hidden ('incremental', $module_incremental, true); + $data['module_info'] .= html_print_select ( + array('snmp_module' => '-'), 'graph', 'snmp_module', '', '', 0, true, false, true, '', false, 'display: none;' + ); + } $data['refresh'] = __('Refresh interval') . '  ' . html_print_select ($refresh_fields, 'refresh', $refresh, '', '', 0, true); - $data['incremental'] = __('Incremental') . '  ' . html_print_checkbox ('incremental', 1, 0, true); + if ($graph != 'snmp_module') { + $data['incremental'] = __('Incremental') . '  ' . html_print_checkbox ('incremental', 1, 0, true); + } $data['reset'] = html_print_button(__('Clear graph'), 'reset', false, 'clearGraph()', 'class="sub delete" style="margin-top:0px;"', true); $table->data[] = $data; - - - if ($graph == 'snmp_interface') { - $snmp_address = ''; - $snmp_community = ''; - $snmp_oid = ''; - $snmp_ver = '1'; - $snmp_inc = false; - + + if ($graph == 'snmp_interface' || $graph == 'snmp_module') { + $snmp_address = get_parameter('snmp_address', ''); + $snmp_community = get_parameter('snmp_community', ''); + $snmp_oid = get_parameter('snmp_oid', ''); + $snmp_ver = get_parameter('snmp_ver', ''); + $data = array(); $data['snmp_address'] = __('Target IP') . '  ' . html_print_input_text ('ip_target', $snmp_address, '', 50, 255, true); @@ -111,9 +125,14 @@ function pandora_realtime_graphs () { $data['snmp_ver'] = __('Version') . '  ' . html_print_select ($snmp_versions, 'snmp_version', $snmp_ver, '', '', 0, true); $data['snmp_ver'] .= '  ' . html_print_button (__('SNMP walk'), 'snmp_walk', false, 'snmpBrowserWindow()', 'class="sub next"', true); $table->colspan[2]['snmp_ver'] = 2; - + $table->data[] = $data; - + + // Hide some options in snmp_module graphs + if ($graph == 'snmp_module') { + $table->rowstyle[1] = "display: none;"; + $table->rowstyle[2] = "display: none;"; + } snmp_browser_print_container (false, '100%', '60%', 'none'); } diff --git a/pandora_console/extensions/realtime_graphs/ajax.php b/pandora_console/extensions/realtime_graphs/ajax.php index 89ea428ee2..7c3eb0c3b5 100644 --- a/pandora_console/extensions/realtime_graphs/ajax.php +++ b/pandora_console/extensions/realtime_graphs/ajax.php @@ -59,6 +59,7 @@ switch($graph) { $data = exec("ps aux | grep pandora_server | grep -v grep | awk '{ print $3 }'"); break; case 'snmp_interface': + case 'snmp_module': $snmp_address = $_POST['snmp_address']; $snmp_community = $_POST['snmp_community']; $snmp_ver = $_POST['snmp_ver']; diff --git a/pandora_console/extensions/realtime_graphs/realtime_graphs.js b/pandora_console/extensions/realtime_graphs/realtime_graphs.js index 538a68f144..53baa810e4 100644 --- a/pandora_console/extensions/realtime_graphs/realtime_graphs.js +++ b/pandora_console/extensions/realtime_graphs/realtime_graphs.js @@ -37,7 +37,7 @@ var plot = $.plot("#" + id, data, options); var refresh = parseInt($('#refresh').val()); -var incremental = $('#checkbox-incremental').is(':checked'); +var incremental = $('#checkbox-incremental').is(':checked') || $('#hidden-incremental').val() == 1; var incremental_base = 0; var last_inc = 0; var to; From 5783e56a2ed679f2183772b2b32f13da57b0f930 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 3 May 2018 12:57:48 +0200 Subject: [PATCH 2/8] Fixed a PHP warning (invalida foreach) --- .../include/functions_snmp_browser.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index 0170b4ebe8..c6698d70cd 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -576,16 +576,17 @@ function snmp_browser_print_container ($return = false, $width = '100%', $height enterprise_include_once ('include/functions_satellite.php'); $rows = get_proxy_servers(); - foreach ($rows as $row) { - if ($row['server_type'] != 13) { - $s_type = " (Standard)"; + if ($rows !== false) { + foreach ($rows as $row) { + if ($row['server_type'] != 13) { + $s_type = " (Standard)"; + } + else { + $s_type = " (Satellite)"; + } + $servers_to_exec[$row['id_server']] = $row['name'] . $s_type; + } } - else { - $s_type = " (Satellite)"; - } - - $servers_to_exec[$row['id_server']] = $row['name'] . $s_type; - } } $table->data[1][1] = '' . __('Server to execute') . '   '; $table->data[1][1] .= html_print_select($servers_to_exec, 'server_to_exec', '', '', '', '', true); From 2885885cc47b50c0004bae1b93fcea1c46d31b72 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 3 May 2018 13:02:17 +0200 Subject: [PATCH 3/8] Fixed a JS error (invalid parameter in pandoraAreaGraph) --- pandora_console/include/graphs/functions_flot.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index df5e7f28ad..4a5deb4443 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -497,6 +497,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, // Javascript code + if ($font_size == '') $font_size = '\'\''; $return .= "'; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; // Store servers timezone offset to be retrieved from js set_js_value('timezone_offset', date('Z', time())); diff --git a/pandora_console/extensions/realtime_graphs/realtime_graphs.js b/pandora_console/extensions/realtime_graphs/realtime_graphs.js index 53baa810e4..6c535f2e5d 100644 --- a/pandora_console/extensions/realtime_graphs/realtime_graphs.js +++ b/pandora_console/extensions/realtime_graphs/realtime_graphs.js @@ -58,9 +58,11 @@ function refresh_graph () { postvars['snmp_address'] = $('#text-ip_target').val(); postvars['refresh'] = refresh; - + + var rel_path = $("#hidden-rel_path").val(); + $.ajax({ - url: "extensions/realtime_graphs/ajax.php", + url: rel_path + "extensions/realtime_graphs/ajax.php", type: "POST", dataType: "json", data: postvars, diff --git a/pandora_console/include/functions_extensions.php b/pandora_console/include/functions_extensions.php index 160ba3ac41..47e30d71fd 100755 --- a/pandora_console/include/functions_extensions.php +++ b/pandora_console/include/functions_extensions.php @@ -92,28 +92,27 @@ function extensions_is_extension ($page) { * * @param bool $enterprise */ -function extensions_get_extensions ($enterprise = false) { - - $dir = EXTENSIONS_DIR; - $master_dir = ENTERPRISE_DIR . '/' . EXTENSIONS_DIR; +function extensions_get_extensions ($enterprise = false, $rel_path = '') { + + $dir = $rel_path . EXTENSIONS_DIR; + $master_dir = $rel_path . ENTERPRISE_DIR . '/' . EXTENSIONS_DIR; $handle = false; if ($enterprise) { - $dir = ENTERPRISE_DIR . '/' . EXTENSIONS_DIR; + $dir = $rel_path . ENTERPRISE_DIR . '/' . EXTENSIONS_DIR; if (defined("METACONSOLE")) { - $dir = '../' . EXTENSIONS_DIR; - $master_dir = '../' . EXTENSIONS_DIR; + $dir = $rel_path . '../' . EXTENSIONS_DIR; + $master_dir = $rel_path . '../' . EXTENSIONS_DIR; } } else { if (defined("METACONSOLE")) { - $dir = '../../' . $dir; - $master_dir = '../' . EXTENSIONS_DIR; + $dir = $rel_path . '../../' . $dir; + $master_dir = $rel_path . '../' . EXTENSIONS_DIR; } } - + if (file_exists ($dir)) $handle = @opendir ($dir); - if (empty ($handle)) return; @@ -148,7 +147,7 @@ function extensions_get_extensions ($enterprise = false) { /* Load extensions in enterprise directory */ if (! $enterprise && file_exists ($master_dir)) - return array_merge ($extensions, extensions_get_extensions (true)); + return array_merge ($extensions, extensions_get_extensions (true, $rel_path)); return $extensions; } diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index dfb4cb3610..4eea443856 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2711,11 +2711,13 @@ function get_module_realtime_link_graph ($module) { 'snmp_address' => $module['ip_target'], 'snmp_community' => $module['snmp_community'], 'snmp_oid' => $module['snmp_oid'], - 'snmp_ver' => $module['tcp_send'] + 'snmp_ver' => $module['tcp_send'], + 'hide_header' => 1, + 'rel_path' => '../../' ); // Incremental type if ($module['id_tipo_modulo'] == 16) $params['incremental'] = 1; - $link = "index.php?sec=view&sec2=extensions/realtime_graphs&"; //FIXME: Not definitive URL + $link = "operation/agentes/realtime_win.php?"; foreach ($params as $p_key => $p_value) { $link .= "$p_key=" . urlencode(io_safe_output($p_value)) . "&"; } @@ -2723,7 +2725,7 @@ function get_module_realtime_link_graph ($module) { $win_handle = "realtime_" . dechex(crc32($module["id_agente_modulo"].$module["nombre"])); - $link_button = '' . + $link_button = '' . html_print_image("images/chart_curve.png", true, array("border" => '0', "alt" => "")) . //FIXME: Not definitive image '   '; diff --git a/pandora_console/operation/agentes/realtime_win.php b/pandora_console/operation/agentes/realtime_win.php new file mode 100644 index 0000000000..6106583c80 --- /dev/null +++ b/pandora_console/operation/agentes/realtime_win.php @@ -0,0 +1,105 @@ +"; + echo ""; + ui_print_error_message(__('There was a problem connecting with the node')); + echo ""; + echo ""; + exit; + } +} + +$user_language = get_user_language ($config['id_user']); +if (file_exists ('../../include/languages/'.$user_language.'.mo')) { + $l10n = new gettext_reader (new CachedFileReader ('../../include/languages/'.$user_language.'.mo')); + $l10n->load_tables(); +} + +echo ''; +?> + + + + 0) { + $query = ui_get_url_refresh (false); + echo ''; + } + ?> + + Pandora FMS Realtime Module Graph + + + + + + + + + + + + + + + From 0f4daee237e47b3eb28c75d059822e98e586e51a Mon Sep 17 00:00:00 2001 From: fermin831 Date: Fri, 4 May 2018 13:18:33 +0200 Subject: [PATCH 6/8] Added icon to realtime SNMP graph --- pandora_console/images/realtime_shortcut.png | Bin 0 -> 527 bytes pandora_console/include/functions_modules.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 pandora_console/images/realtime_shortcut.png diff --git a/pandora_console/images/realtime_shortcut.png b/pandora_console/images/realtime_shortcut.png new file mode 100644 index 0000000000000000000000000000000000000000..eb2f5673a70251db646575380599740a7f1ead2e GIT binary patch literal 527 zcmV+q0`UEbP)LI7k6NTDH6;RU>YMiL8vI$=Ia7y|`B z&M3g=FOYKp0*K^bFTfT$P$%ri844hGLVYd>#EGClXTss84N&?6kOFCXfSzE`txrIS zAgEi;BeCD3Yhpw)u@LIkL?HHuTGt4~@8Q9N&1$I0|1ks!1tBAm3LS}#6o3F@qA+s` zfG}2PLKUnBMFcU41s3ek5CnmGAQk}XRRnQZkkkqgVVDAtx{p*!Y=E*iKttaFD0YB_ z6z>8xJOFA0xyArwAhdw+eQ2-RrM=l(p5e3SE6JQQu!Q#b0q*4nM0fDfvgBoxjn*IWz@*s5!kbTC2 zC;TozH6n|FGzvnCob^z{4Dlr?SeQDJn{Htdh3wKmX!tphY32u@!$8UG0{~W&x`-V= RbX))c002ovPDHLkV1iHo#hd^D literal 0 HcmV?d00001 diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 4eea443856..b4490003a4 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2726,7 +2726,7 @@ function get_module_realtime_link_graph ($module) { $win_handle = "realtime_" . dechex(crc32($module["id_agente_modulo"].$module["nombre"])); $link_button = '' . - html_print_image("images/chart_curve.png", true, array("border" => '0', "alt" => "")) . //FIXME: Not definitive image + html_print_image("images/realtime_shortcut.png", true, array("border" => '0', "alt" => "")) . '   '; return $link_button; From fd91ba63f673d8eab9f41c8242de3b87bbce8e04 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Mon, 7 May 2018 12:53:12 +0200 Subject: [PATCH 7/8] Added realtime graph to monitor view --- pandora_console/include/ajax/module.php | 3 ++- pandora_console/include/functions_modules.php | 9 ++++++++- .../operation/agentes/status_monitor.php | 15 +++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 7f81514b06..10b181baee 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -1084,7 +1084,8 @@ if ($list_modules) { $win_handle=dechex(crc32($module["id_agente_modulo"].$module["nombre"])); // Try to display the SNMP module realtime graph - $data[8] .= get_module_realtime_link_graph($module); + $rt_button .= get_module_realtime_link_graph($module); + if (!empty($rt_button)) $data[8] = $rt_button . "  "; # Show events for boolean modules by default. if ($graph_type == 'boolean') { diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index b4490003a4..f166aa1a23 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2692,7 +2692,14 @@ function recursive_get_dt_from_modules_tree (&$f_modules, $modules, $deep) { * @return string All the HTML code to paint the button */ function get_module_realtime_link_graph ($module) { + global $config; + // Sometimes some parameters are renamed + if (!isset($module['id_tipo_modulo'])) $module['id_tipo_modulo'] = $module['module_type']; + if (!isset($module['nombre'])) $module['nombre'] = $module['module_name']; + + // Avoid to show on metaconsole + if (is_metaconsole()) return ''; // Realtime graph is an extension and it should be enabled if (!extensions_is_enabled_extension("realtime_graphs.php")) return ''; // Only to remote_snmp, remote_snmp_proc. snmp_snmp_inc @@ -2727,7 +2734,7 @@ function get_module_realtime_link_graph ($module) { $link_button = '' . html_print_image("images/realtime_shortcut.png", true, array("border" => '0', "alt" => "")) . - '   '; + ''; return $link_button; } diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index f630953dd5..57946cf610 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -753,7 +753,11 @@ switch ($config['dbtype']) { tagente.id_grupo AS id_group, tagente.id_agente AS id_agent, tagente_modulo.id_tipo_modulo AS module_type, - tagente_modulo.module_interval, + tagente_modulo.module_interval, + tagente_modulo.tcp_send, + tagente_modulo.ip_target, + tagente_modulo.snmp_community, + tagente_modulo.snmp_oid, tagente_estado.datos, tagente_estado.estado, tagente_modulo.min_warning, @@ -1272,12 +1276,11 @@ if (!empty($result)) { $graph_params_str = http_build_query($graph_params); $link = 'winopeng(\''.$url.'?'.$graph_params_str.'\',\''.$win_handle.'\')'; - - $data[7] = ''; - + + $data[7] = get_module_realtime_link_graph($row); + if(!is_snapshot_data($row['datos'])){ - - $data[7] = '' . html_print_image('images/chart_curve.png', true, array('border' => '0', 'alt' => '')) . ''; + $data[7] .= '' . html_print_image('images/chart_curve.png', true, array('border' => '0', 'alt' => '')) . ''; } $data[7] .= '' . - html_print_image("images/realtime_shortcut.png", true, array("border" => '0', "alt" => "")) . + html_print_image( + "images/realtime_shortcut.png", + true, + array("border" => '0', "alt" => "", 'title' => __('Realtime SNMP graph')) + ) . ''; return $link_button;