From 45e9904f11ad4987152257a2e3635be074b0a9d1 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Mon, 4 Apr 2016 10:06:34 +0200 Subject: [PATCH] Substituted lines for intervals in modules graphs TICKETS #3392 --- pandora_console/include/functions_graph.php | 2 +- pandora_console/include/graphs/fgraph.php | 14 +- .../include/graphs/flot/pandora.flot.js | 182 ++++++++++++++---- .../include/graphs/functions_flot.php | 38 +++- 4 files changed, 185 insertions(+), 51 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 38c10cf2c4..54ff45ad43 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -893,7 +893,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $config['font_size'], $unit, $ttl, $series_type, $chart_extra_data, $warning_min, $critical_min, $adapt_key, false, $series_suffix_str, $menu, - $backgroundColor, $dashboard, $vconsole); + $backgroundColor, $dashboard, $vconsole, $agent_module_id); } } elseif ($config['type_module_charts'] === 'line') { diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 12b249d036..c026abb795 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -218,7 +218,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key = '', $force_integer = false, $series_suffix_str = '', $menu = true, $backgroundColor = 'white', - $dashboard = false, $vconsole = false) { + $dashboard = false, $vconsole = false, $agent_module_id = 0) { setup_watermark($water_mark, $water_mark_file, $water_mark_url); @@ -257,7 +257,9 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $series_suffix_str, $menu, $backgroundColor, - $dashboard); + $dashboard, + false, + $agent_module_id); } else { if ($vconsole) { @@ -281,7 +283,8 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $menu, $backgroundColor, $dashboard, - $vconsole); + $vconsole, + $agent_module_id); } else { $graph = array(); @@ -316,7 +319,7 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "", $water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white', - $dashboard = false, $vconsole = false) { + $dashboard = false, $vconsole = false, $agent_module_id) { setup_watermark($water_mark, $water_mark_file, $water_mark_url); @@ -368,7 +371,8 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, true, $backgroundColor, $dashboard, - $vconsole); + $vconsole, + $agent_module_id); } else { //Stack the data diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 45283b24a2..02b41961f3 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -804,7 +804,9 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, type, serie_types, water_mark, width, max_x, homeurl, unit, font_size, menu, events, event_ids, legend_events, alerts, alert_ids, legend_alerts, yellow_threshold, red_threshold, - force_integer, separator, separator2, series_suffix_str, vconsole) { + force_integer, separator, separator2, + yellow_up, red_up, yellow_inverse, red_inverse, + series_suffix_str, vconsole) { var threshold = true; var thresholded = false; @@ -861,14 +863,8 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, for (i = 0; i < values.length; i++) { var serie = values[i].split(separator); var aux = new Array(); - var critical_min = new Array(); - var warning_min = new Array(); $.each(serie, function(i, v) { aux.push([i, v]); - if (threshold) { - critical_min.push([i,red_threshold]); - warning_min.push([i,yellow_threshold]); - } }); switch (serie_types[i]) { @@ -961,21 +957,77 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, var threshold_data = new Array(); if (threshold) { - // Warning and critical treshold - threshold_data.push({ - id: 'critical_min', - data: critical_min, - label: null, - color: critical, - lines: { show: true, fill: false, lineWidth:3} - }); - threshold_data.push({ - id: 'warning_min', - data: warning_min, - label: null, - color: warning, - lines: { show: true, fill: false, lineWidth:3} - }); + // Warning interval + if (yellow_inverse) { + threshold_data.push({ // barWidth will be correct on draw time + id: 'warning_up', + data: [[max_x, yellow_up]], + label: null, + color: warning, + bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true} + }); + threshold_data.push({ // barWidth will be correct on draw time + id: 'warning_down', + data: [[max_x, 0]], + label: null, + color: warning, + bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true} + }); + } else { + if (yellow_up == 0) { + threshold_data.push({ // barWidth will be correct on draw time + id: 'warning_up', + data: [[max_x, yellow_threshold]], + label: null, + color: warning, + bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true} + }); + } else { + threshold_data.push({ + id: 'warning_normal', + data: [[max_x, yellow_threshold]], + label: null, + color: warning, + bars: {show: true, align: "left", barWidth: (yellow_up - yellow_threshold), lineWidth: 0, horizontal: true} + }); + } + } + // Critical interval + if (red_inverse) { + threshold_data.push({ // barWidth will be correct on draw time + id: 'critical_up', + data: [[max_x, red_up]], + label: null, + color: critical, + bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true} + }); + threshold_data.push({ // barWidth will be correct on draw time + id: 'critical_down', + data: [[max_x, 0]], + label: null, + color: critical, + bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true} + }); + } else { + if (red_up == 0) { + threshold_data.push({ // barWidth will be correct on draw time + id: 'critical_up', + data: [[max_x, red_threshold]], + label: null, + color: critical, + bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true} + }); + } else { + threshold_data.push({ + id: 'critical_normal', + data: [[max_x, red_threshold]], + label: null, + color: critical, + bars: {show: true, align: "left", barWidth: (red_up - red_threshold), lineWidth: 0, horizontal: true} + }); + } + } + } // The first execution, the graph data is the base data @@ -1082,7 +1134,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, new_steps = parseInt(factor * steps); - plot = $.plot($('#' + graph_id), datas, + plot = $.plot($('#' + graph_id), data_base, $.extend(true, {}, options, { xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to}, xaxes: [ { @@ -1092,6 +1144,15 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, } ], legend: { show: false } })); + if (thresholded) { + var zoom_data_threshold = new Array (); + + zoom_data_threshold = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, + yellow_threshold, red_threshold, yellow_up, red_up); + plot.setData(zoom_data_threshold); + plot.draw(); + } + $('#menu_cancelzoom_' + graph_id) .attr('src', homeurl + '/images/zoom_cross_grey.png'); @@ -1535,23 +1596,22 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, datas = new Array(); if (thresholded) { - thresholded = false; - } - else { - $.each(threshold_data, function() { - datas.push(this); + $.each(data_base, function() { + // Prepared to turning series + //if(showed[this.id.split('_')[1]]) { + datas.push(this); + //} }); + thresholded = false; + } else { + //pocoyo + datas = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, + yellow_threshold, red_threshold, yellow_up, red_up); thresholded = true; } - $.each(data_base, function() { - // Prepared to turning series - //if(showed[this.id.split('_')[1]]) { - datas.push(this); - //} - }); - - plot = $.plot($('#' + graph_id), datas, options); + plot.setData(datas); + plot.draw(); plot.setSelection(currentRanges); }); @@ -1568,6 +1628,8 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, .attr('src', homeurl + '/images/zoom_cross.disabled.png'); overview.clearSelection(); currentRanges = null; + + thresholded = false; }); // Adjust the menu image on top of the plot @@ -1735,3 +1797,51 @@ function number_format(number, force_integer, unit) { return number + ' ' + shorts[pos] + unit; } +function add_threshold (data_base, threshold_data, y_min, y_max, yellow_threshold, + red_threshold, yellow_up, red_up) { + + var datas = new Array (); + + $.each(data_base, function() { + // Prepared to turning series + //if(showed[this.id.split('_')[1]]) { + datas.push(this); + //} + }); + + // Resize the warning and critical interval + $.each(threshold_data, function() { + if (/_up/.test(this.id)){ + this.bars.barWidth = y_max - this.data[0][1]; + } + if (/_down/.test(this.id)){ + var end; + if (/critical/.test(this.id)) { + end = red_threshold; + } else { + end = yellow_threshold; + } + this.bars.barWidth = end - y_min; + this.data[0][1] = y_min; + } + if (/_normal/.test(this.id)){ + var end; + if (/critical/.test(this.id)) { + end = red_up; + } else { + end = yellow_up; + } + if (this.data[0][1] < y_min) { + this.bars.barWidth = end - y_min; + this.data[0][1] = y_min; + end = this.bars.barWidth + this.data[0][1]; + } + if (end > y_max) { + this.bars.barWidth = y_max - this.data[0][1]; + } + } + datas.push(this); + }); + + return datas; +} diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index b3dbb11096..f618aba3b9 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -94,7 +94,7 @@ function flot_area_stacked_graph($chart_data, $width, $height, $color, $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', $force_integer = false, $series_suffix_str = '', $menu = true, - $background_color = 'white', $dashboard = false, $vconsole = false) { + $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { global $config; @@ -102,7 +102,7 @@ function flot_area_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'area_stacked', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str, - $menu, $background_color, $dashboard, $vconsole); + $menu, $background_color, $dashboard, $vconsole, $agent_module_id); } function flot_area_simple_graph($chart_data, $width, $height, $color, @@ -110,7 +110,7 @@ function flot_area_simple_graph($chart_data, $width, $height, $color, $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', $force_integer = false, $series_suffix_str = '', $menu = true, - $background_color = 'white', $dashboard = false, $vconsole = false) { + $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { global $config; @@ -118,7 +118,7 @@ function flot_area_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'area_simple', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str, - $menu, $background_color, $dashboard, $vconsole); + $menu, $background_color, $dashboard, $vconsole, $agent_module_id); } function flot_line_stacked_graph($chart_data, $width, $height, $color, @@ -126,7 +126,7 @@ function flot_line_stacked_graph($chart_data, $width, $height, $color, $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', $force_integer = false, $series_suffix_str = '', $menu = true, - $background_color = 'white', $dashboard = false, $vconsole = false) { + $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { global $config; @@ -134,7 +134,7 @@ function flot_line_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'line_stacked', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str, - $menu, $background_color, $dashboard, $vconsole); + $menu, $background_color, $dashboard, $vconsole, $agent_module_id); } function flot_line_simple_graph($chart_data, $width, $height, $color, @@ -142,7 +142,7 @@ function flot_line_simple_graph($chart_data, $width, $height, $color, $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', $force_integer = false, $series_suffix_str = '', $menu = true, - $background_color = 'white', $dashboard = false, $vconsole = false) { + $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { global $config; @@ -157,7 +157,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $type, $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str = '', $menu = true, - $background_color = 'white', $dashboard = false, $vconsole = false) { + $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { global $config; @@ -189,9 +189,25 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "

"; + + + // Get other required module datas to draw warning and critical + if ($agent_module_id == 0) { + $yellow_up = 0; + $red_up = 0; + $yellow_inverse = false; + $red_inverse = false; + } else { + $module_data = db_get_row_sql ('SELECT * FROM tagente_modulo WHERE id_agente_modulo = ' . $agent_module_id); + $yellow_up = $module_data['max_warning']; + $red_up = $module_data['max_critical']; + $yellow_inverse = !($module_data['warning_inverse'] == 0); + $red_inverse = !($module_data['critical_inverse'] == 0); + } + if ($menu) { $threshold = false; - if ($yellow_threshold != 0 || $red_threshold != 0) { + if ($yellow_threshold != $yellow_up || $red_threshold != $red_up) { $threshold = true; } @@ -426,6 +442,10 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, "$force_integer, \n" . "'$separator', \n" . "'$separator2', \n" . + "'$yellow_up', \n" . + "'$red_up', \n" . + "'$yellow_inverse', \n" . + "'$red_inverse', \n" . "'$series_suffix_str', '$vconsole');"; $return .= "\n//]]>";