From a0a74cf7bb5b52c5e39b4bd909a26aa9a69ae6d8 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 18 Jan 2022 13:01:49 +0100 Subject: [PATCH] add new chart histogram --- pandora_console/include/class/Tree.class.php | 53 +++++++++++++++---- .../include/javascript/tree/TreeController.js | 29 ++++++++++ .../operation/agentes/status_monitor.php | 27 ++++++++++ 3 files changed, 98 insertions(+), 11 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 73e19c0d38..8dd8b97698 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -669,15 +669,20 @@ class Tree // HTML of the server type image $module['serverTypeHTML'] = servers_show_type($module['server_type']); - // Link to the Module graph - // ACL + // Link to the Module graph. + // ACL. $acl_graphs = false; $module['showGraphs'] = 0; - // Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions - if (!empty($group_id) && !is_metaconsole()) { - $acl_graphs = check_acl_one_of_groups($config['id_user'], $all_groups, 'RR'); - } else if (!empty($all_groups)) { + // Avoid the check on the metaconsole. + // Too slow to show/hide an icon depending on the permissions. + if (empty($group_id) === false && is_metaconsole() === false) { + $acl_graphs = check_acl_one_of_groups( + $config['id_user'], + $all_groups, + 'RR' + ); + } else if (empty($all_groups) === false) { $acl_graphs = true; } @@ -686,8 +691,24 @@ class Tree } if ($module['showGraphs']) { + $tresholds = true; + if (empty((float) $module['min_warning']) === true + && empty((float) $module['max_warning']) === true + && empty($module['warning_inverse']) === true + && empty((float) $module['min_critical']) === true + && empty((float) $module['max_critical']) === true + && empty($module['critical_inverse']) === true + ) { + $tresholds = false; + } + $graphType = return_graphtype($module['id_module_type']); - $url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false); + $url = ui_get_full_url( + 'operation/agentes/stat_win.php', + false, + false, + false + ); $winHandle = dechex(crc32($module['id'].$module['name'])); $graph_params = [ @@ -697,20 +718,20 @@ class Tree 'refresh' => SECONDS_10MINUTES, ]; - if (is_metaconsole()) { - // Set the server id + if (is_metaconsole() === true) { + // Set the server id. $graph_params['server'] = $module['serverID']; } $graph_params_str = http_build_query($graph_params); - $moduleGraphURL = "$url?$graph_params_str"; + $moduleGraphURL = $url.'?'.$graph_params_str; $module['moduleGraph'] = [ 'url' => $moduleGraphURL, 'handle' => $winHandle, ]; - // Info to be able to open the snapshot image new page + // Info to be able to open the snapshot image new page. $module['snapshot'] = ui_get_snapshot_link( [ 'id_module' => $module['id'], @@ -720,6 +741,16 @@ class Tree ], true ); + + if ($tresholds === true || $graphType === 'boolean') { + $graph_params['histogram'] = 1; + $graph_params_str_th = http_build_query($graph_params); + $moduleGraphURLTh = $url.'?'.$graph_params_str_th; + $module['histogramGraph'] = [ + 'url' => $moduleGraphURLTh, + 'handle' => $winHandle, + ]; + } } $module_alerts = alerts_get_alerts_agent_module($module['id']); diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index afa55434c0..6d2d14bf7c 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -990,6 +990,35 @@ var TreeController = { typeof element.showGraphs != "undefined" && element.showGraphs != 0 ) { + // Graph hisstogram pop-up + if (typeof element.histogramGraph != "undefined") { + var graphImageHistogram = $( + ' ' + ); + + graphImageHistogram + .addClass("module-graph") + .click(function(e) { + e.stopPropagation(); + try { + winopeng_var( + element.histogramGraph.url, + element.histogramGraph.handle, + 800, + 480 + ); + } catch (error) { + // console.log(error); + } + }); + + $content.append(graphImageHistogram); + } + // Graph pop-up if (typeof element.moduleGraph != "undefined") { if (element.statusImageHTML.indexOf("data:image") != -1) { diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 16961214cf..5e5ab2b43f 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -1725,6 +1725,17 @@ $table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you } if ($row['history_data'] == 1 && $acl_graphs) { + $tresholds = true; + if (empty((float) $module['min_warning']) === true + && empty((float) $module['max_warning']) === true + && empty($module['warning_inverse']) === true + && empty((float) $module['min_critical']) === true + && empty((float) $module['max_critical']) === true + && empty($module['critical_inverse']) === true + ) { + $tresholds = false; + } + $graph_type = return_graphtype($row['module_type']); $url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false); @@ -1738,6 +1749,10 @@ $table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you 'refresh' => SECONDS_10MINUTES, ]; + if ($tresholds === true || $graph_type === 'boolean') { + $graph_params['histogram'] = 1; + } + if (is_metaconsole() && isset($row['server_id'])) { // Set the server id. $graph_params['server'] = $row['server_id']; @@ -1749,6 +1764,18 @@ $table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you $data[8] = get_module_realtime_link_graph($row); + if ($tresholds === true || $graph_type === 'boolean') { + $data[8] .= ''.html_print_image( + 'images/histograma.png', + true, + [ + 'border' => '0', + 'alt' => '', + 'class' => 'invert_filter', + ] + ).''; + } + if (!is_snapshot_data($row['datos'])) { $data[8] .= ''.html_print_image('images/chart.png', true, ['border' => '0', 'alt' => '', 'class' => 'invert_filter']).''; }