From f3855ac7e927bc09aeb73f5dc5bcd84363c6c24b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 25 Jan 2018 13:14:21 +0100 Subject: [PATCH 01/33] Added flot.time plugin --- .../include/graphs/flot/jquery.flot.time.js | 432 ++++++++++++++++++ .../include/graphs/flot/pandora.flot.js | 18 +- .../include/graphs/functions_flot.php | 2 + 3 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 pandora_console/include/graphs/flot/jquery.flot.time.js diff --git a/pandora_console/include/graphs/flot/jquery.flot.time.js b/pandora_console/include/graphs/flot/jquery.flot.time.js new file mode 100644 index 0000000000..34c1d12125 --- /dev/null +++ b/pandora_console/include/graphs/flot/jquery.flot.time.js @@ -0,0 +1,432 @@ +/* Pretty handling of time axes. + +Copyright (c) 2007-2014 IOLA and Ole Laursen. +Licensed under the MIT license. + +Set axis.mode to "time" to enable. See the section "Time series data" in +API.txt for details. + +*/ + +(function($) { + + var options = { + xaxis: { + timezone: null, // "browser" for local to the client or timezone for timezone-js + timeformat: null, // format string to use + twelveHourClock: false, // 12 or 24 time in time mode + monthNames: null // list of names of months + } + }; + + // round to nearby lower multiple of base + + function floorInBase(n, base) { + return base * Math.floor(n / base); + } + + // Returns a string with the date d formatted according to fmt. + // A subset of the Open Group's strftime format is supported. + + function formatDate(d, fmt, monthNames, dayNames) { + + if (typeof d.strftime == "function") { + return d.strftime(fmt); + } + + var leftPad = function(n, pad) { + n = "" + n; + pad = "" + (pad == null ? "0" : pad); + return n.length == 1 ? pad + n : n; + }; + + var r = []; + var escape = false; + var hours = d.getHours(); + var isAM = hours < 12; + + if (monthNames == null) { + monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + } + + if (dayNames == null) { + dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + } + + var hours12; + + if (hours > 12) { + hours12 = hours - 12; + } else if (hours == 0) { + hours12 = 12; + } else { + hours12 = hours; + } + + for (var i = 0; i < fmt.length; ++i) { + + var c = fmt.charAt(i); + + if (escape) { + switch (c) { + case 'a': c = "" + dayNames[d.getDay()]; break; + case 'b': c = "" + monthNames[d.getMonth()]; break; + case 'd': c = leftPad(d.getDate()); break; + case 'e': c = leftPad(d.getDate(), " "); break; + case 'h': // For back-compat with 0.7; remove in 1.0 + case 'H': c = leftPad(hours); break; + case 'I': c = leftPad(hours12); break; + case 'l': c = leftPad(hours12, " "); break; + case 'm': c = leftPad(d.getMonth() + 1); break; + case 'M': c = leftPad(d.getMinutes()); break; + // quarters not in Open Group's strftime specification + case 'q': + c = "" + (Math.floor(d.getMonth() / 3) + 1); break; + case 'S': c = leftPad(d.getSeconds()); break; + case 'y': c = leftPad(d.getFullYear() % 100); break; + case 'Y': c = "" + d.getFullYear(); break; + case 'p': c = (isAM) ? ("" + "am") : ("" + "pm"); break; + case 'P': c = (isAM) ? ("" + "AM") : ("" + "PM"); break; + case 'w': c = "" + d.getDay(); break; + } + r.push(c); + escape = false; + } else { + if (c == "%") { + escape = true; + } else { + r.push(c); + } + } + } + + return r.join(""); + } + + // To have a consistent view of time-based data independent of which time + // zone the client happens to be in we need a date-like object independent + // of time zones. This is done through a wrapper that only calls the UTC + // versions of the accessor methods. + + function makeUtcWrapper(d) { + + function addProxyMethod(sourceObj, sourceMethod, targetObj, targetMethod) { + sourceObj[sourceMethod] = function() { + return targetObj[targetMethod].apply(targetObj, arguments); + }; + }; + + var utc = { + date: d + }; + + // support strftime, if found + + if (d.strftime != undefined) { + addProxyMethod(utc, "strftime", d, "strftime"); + } + + addProxyMethod(utc, "getTime", d, "getTime"); + addProxyMethod(utc, "setTime", d, "setTime"); + + var props = ["Date", "Day", "FullYear", "Hours", "Milliseconds", "Minutes", "Month", "Seconds"]; + + for (var p = 0; p < props.length; p++) { + addProxyMethod(utc, "get" + props[p], d, "getUTC" + props[p]); + addProxyMethod(utc, "set" + props[p], d, "setUTC" + props[p]); + } + + return utc; + }; + + // select time zone strategy. This returns a date-like object tied to the + // desired timezone + + function dateGenerator(ts, opts) { + if (opts.timezone == "browser") { + return new Date(ts); + } else if (!opts.timezone || opts.timezone == "utc") { + return makeUtcWrapper(new Date(ts)); + } else if (typeof timezoneJS != "undefined" && typeof timezoneJS.Date != "undefined") { + var d = new timezoneJS.Date(); + // timezone-js is fickle, so be sure to set the time zone before + // setting the time. + d.setTimezone(opts.timezone); + d.setTime(ts); + return d; + } else { + return makeUtcWrapper(new Date(ts)); + } + } + + // map of app. size of time units in milliseconds + + var timeUnitSize = { + "second": 1000, + "minute": 60 * 1000, + "hour": 60 * 60 * 1000, + "day": 24 * 60 * 60 * 1000, + "month": 30 * 24 * 60 * 60 * 1000, + "quarter": 3 * 30 * 24 * 60 * 60 * 1000, + "year": 365.2425 * 24 * 60 * 60 * 1000 + }; + + // the allowed tick sizes, after 1 year we use + // an integer algorithm + + var baseSpec = [ + [1, "second"], [2, "second"], [5, "second"], [10, "second"], + [30, "second"], + [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"], + [30, "minute"], + [1, "hour"], [2, "hour"], [4, "hour"], + [8, "hour"], [12, "hour"], + [1, "day"], [2, "day"], [3, "day"], + [0.25, "month"], [0.5, "month"], [1, "month"], + [2, "month"] + ]; + + // we don't know which variant(s) we'll need yet, but generating both is + // cheap + + var specMonths = baseSpec.concat([[3, "month"], [6, "month"], + [1, "year"]]); + var specQuarters = baseSpec.concat([[1, "quarter"], [2, "quarter"], + [1, "year"]]); + + function init(plot) { + plot.hooks.processOptions.push(function (plot, options) { + $.each(plot.getAxes(), function(axisName, axis) { + + var opts = axis.options; + + if (opts.mode == "time") { + axis.tickGenerator = function(axis) { + + var ticks = []; + var d = dateGenerator(axis.min, opts); + var minSize = 0; + + // make quarter use a possibility if quarters are + // mentioned in either of these options + + var spec = (opts.tickSize && opts.tickSize[1] === + "quarter") || + (opts.minTickSize && opts.minTickSize[1] === + "quarter") ? specQuarters : specMonths; + + if (opts.minTickSize != null) { + if (typeof opts.tickSize == "number") { + minSize = opts.tickSize; + } else { + minSize = opts.minTickSize[0] * timeUnitSize[opts.minTickSize[1]]; + } + } + + for (var i = 0; i < spec.length - 1; ++i) { + if (axis.delta < (spec[i][0] * timeUnitSize[spec[i][1]] + + spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2 + && spec[i][0] * timeUnitSize[spec[i][1]] >= minSize) { + break; + } + } + + var size = spec[i][0]; + var unit = spec[i][1]; + + // special-case the possibility of several years + + if (unit == "year") { + + // if given a minTickSize in years, just use it, + // ensuring that it's an integer + + if (opts.minTickSize != null && opts.minTickSize[1] == "year") { + size = Math.floor(opts.minTickSize[0]); + } else { + + var magn = Math.pow(10, Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10)); + var norm = (axis.delta / timeUnitSize.year) / magn; + + if (norm < 1.5) { + size = 1; + } else if (norm < 3) { + size = 2; + } else if (norm < 7.5) { + size = 5; + } else { + size = 10; + } + + size *= magn; + } + + // minimum size for years is 1 + + if (size < 1) { + size = 1; + } + } + + axis.tickSize = opts.tickSize || [size, unit]; + var tickSize = axis.tickSize[0]; + unit = axis.tickSize[1]; + + var step = tickSize * timeUnitSize[unit]; + + if (unit == "second") { + d.setSeconds(floorInBase(d.getSeconds(), tickSize)); + } else if (unit == "minute") { + d.setMinutes(floorInBase(d.getMinutes(), tickSize)); + } else if (unit == "hour") { + d.setHours(floorInBase(d.getHours(), tickSize)); + } else if (unit == "month") { + d.setMonth(floorInBase(d.getMonth(), tickSize)); + } else if (unit == "quarter") { + d.setMonth(3 * floorInBase(d.getMonth() / 3, + tickSize)); + } else if (unit == "year") { + d.setFullYear(floorInBase(d.getFullYear(), tickSize)); + } + + // reset smaller components + + d.setMilliseconds(0); + + if (step >= timeUnitSize.minute) { + d.setSeconds(0); + } + if (step >= timeUnitSize.hour) { + d.setMinutes(0); + } + if (step >= timeUnitSize.day) { + d.setHours(0); + } + if (step >= timeUnitSize.day * 4) { + d.setDate(1); + } + if (step >= timeUnitSize.month * 2) { + d.setMonth(floorInBase(d.getMonth(), 3)); + } + if (step >= timeUnitSize.quarter * 2) { + d.setMonth(floorInBase(d.getMonth(), 6)); + } + if (step >= timeUnitSize.year) { + d.setMonth(0); + } + + var carry = 0; + var v = Number.NaN; + var prev; + + do { + + prev = v; + v = d.getTime(); + ticks.push(v); + + if (unit == "month" || unit == "quarter") { + if (tickSize < 1) { + + // a bit complicated - we'll divide the + // month/quarter up but we need to take + // care of fractions so we don't end up in + // the middle of a day + + d.setDate(1); + var start = d.getTime(); + d.setMonth(d.getMonth() + + (unit == "quarter" ? 3 : 1)); + var end = d.getTime(); + d.setTime(v + carry * timeUnitSize.hour + (end - start) * tickSize); + carry = d.getHours(); + d.setHours(0); + } else { + d.setMonth(d.getMonth() + + tickSize * (unit == "quarter" ? 3 : 1)); + } + } else if (unit == "year") { + d.setFullYear(d.getFullYear() + tickSize); + } else { + d.setTime(v + step); + } + } while (v < axis.max && v != prev); + + return ticks; + }; + + axis.tickFormatter = function (v, axis) { + + var d = dateGenerator(v, axis.options); + + // first check global format + + if (opts.timeformat != null) { + return formatDate(d, opts.timeformat, opts.monthNames, opts.dayNames); + } + + // possibly use quarters if quarters are mentioned in + // any of these places + + var useQuarters = (axis.options.tickSize && + axis.options.tickSize[1] == "quarter") || + (axis.options.minTickSize && + axis.options.minTickSize[1] == "quarter"); + + var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]]; + var span = axis.max - axis.min; + var suffix = (opts.twelveHourClock) ? " %p" : ""; + var hourCode = (opts.twelveHourClock) ? "%I" : "%H"; + var fmt; + + if (t < timeUnitSize.minute) { + fmt = hourCode + ":%M:%S" + suffix; + } else if (t < timeUnitSize.day) { + if (span < 2 * timeUnitSize.day) { + fmt = hourCode + ":%M" + suffix; + } else { + fmt = "%b %d " + hourCode + ":%M" + suffix; + } + } else if (t < timeUnitSize.month) { + fmt = "%b %d"; + } else if ((useQuarters && t < timeUnitSize.quarter) || + (!useQuarters && t < timeUnitSize.year)) { + if (span < timeUnitSize.year) { + fmt = "%b"; + } else { + fmt = "%b %Y"; + } + } else if (useQuarters && t < timeUnitSize.year) { + if (span < timeUnitSize.year) { + fmt = "Q%q"; + } else { + fmt = "Q%q %Y"; + } + } else { + fmt = "%Y"; + } + + var rt = formatDate(d, fmt, opts.monthNames, opts.dayNames); + + return rt; + }; + } + }); + }); + } + + $.plot.plugins.push({ + init: init, + options: options, + name: 'time', + version: '1.0' + }); + + // Time-axis support used to be in Flot core, which exposed the + // formatDate function on the plot object. Various plugins depend + // on the function, so we need to re-expose it here. + + $.plot.formatDate = formatDate; + $.plot.dateGenerator = dateGenerator; + +})(jQuery); diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index cc172f82a3..4cc6f9414e 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -863,6 +863,12 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, serie_types = serie_types.split(separator); labels_long = labels_long.split(separator); labels = labels.split(separator); + // XXX 1827 + /* Translate datetime to utimestamp -> avoid convert datetime in server better... + $.each(labels, function (i,v) { + labels[i] = new Date(labels[i]).getTime(); + }); + */ legend = legend.split(separator); events = events.split(separator); event_ids = event_ids.split(separator); @@ -920,6 +926,11 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, } aux.push([i, v]); + + // XXX 1827 + /* + aux.push([labels[i], v]); + */ }); switch (serie_types[i]) { @@ -1559,7 +1570,12 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, tickFormatter: xFormatter, labelHeight: 50, color: '', - font: font + font: font, + // XXX 1827 + /* + mode: "time", + timeformat: "%Y/%m/%d %H:%M:%S", + */ }], yaxes: [{ tickFormatter: yFormatter, diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 2c77fdd812..8c27ba90a3 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -36,6 +36,8 @@ function include_javascript_dependencies_flot_graph($return = false) { + "; + + // Parent layer + $return .= ""; + + return $return; +} + +function menu_graph( + $yellow_threshold, $red_threshold, + $yellow_up, $red_up, $yellow_inverse, + $red_inverse, $dashboard, $vconsole, + $graph_id, $width, $homeurl +){ + $return = ''; + $threshold = false; + if ($yellow_threshold != $yellow_up || $red_threshold != $red_up) { + $threshold = true; + } + + $nbuttons = 3; + + if ($threshold) { + $nbuttons++; + } + $menu_width = 25 * $nbuttons + 15; + if ( $dashboard == false AND $vconsole == false) { + $return .= ""; + } + + if ($dashboard) { + $return .= ""; + } + return $return; +} + + + + + + + + + + + + + + + + + + + + + + /////////////////////////////// /////////////////////////////// From 8be776e3ea94c8db46d84671eed38055339145c9 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 19 Feb 2018 09:31:45 +0100 Subject: [PATCH 06/33] fixed errrors graphs --- .../include/graphs/flot/pandora.flot.js | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 9268216dce..f6229209bf 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1535,7 +1535,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, // The first execution, the graph data is the base data datas = data_base; - console.log(datas); + // minTickSize var count_data = datas[0].data.length; var min_tick_pixels = 80; @@ -1781,7 +1781,6 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, if (currentRanges == null || (currentRanges.xaxis.from < j && j < currentRanges.xaxis.to)) { $('#timestamp_'+graph_id).show(); // If no legend, the timestamp labels are short and with value - console.log(y); if (legend.length == 0) { $('#timestamp_'+graph_id).text(labels[j] + ' (' + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + ')'); } @@ -1907,7 +1906,6 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, }); $('#overview_'+graph_id).bind('plothover', function (event, pos, item) { - console.log('entra22222'); plot.setCrosshair({ x: pos.x, y: 0 }); currentPlot = overview; latestPosition = pos; @@ -2402,8 +2400,8 @@ function pandoraFlotAreaNew( else{ var unit = ''; } - console.log(format_graph); -//XXXX + + //XXXX var type = 'area_simple'; var xaxisname = 'xaxisname'; var labels_long = ''; @@ -2490,31 +2488,34 @@ function pandoraFlotAreaNew( } }); - max_x = date_array['final_date']; + max_x = date_array['final_date'] *1000; + console.log(max_x); -console.log(data_module_graph); - var yellow_threshold = data_module_graph.w_min; - var red_threshold = data_module_graph.c_min; - var yellow_up = data_module_graph.w_max; - var red_up = data_module_graph.c_max; - var yellow_inverse = data_module_graph.w_inv; - var red_inverse = data_module_graph.c_inv; + var yellow_threshold = parseFloat (data_module_graph.w_min); + var red_threshold = parseFloat (data_module_graph.c_min); + var yellow_up = parseFloat (data_module_graph.w_max); + var red_up = parseFloat (data_module_graph.c_max); + + var yellow_inverse = data_module_graph.w_inv; + var red_inverse = data_module_graph.c_inv; // If threshold and up are the same, that critical or warning is disabled - if (yellow_threshold == yellow_up) yellow_inverse = false; - if (red_threshold == red_up) red_inverse = false; + if (yellow_threshold == yellow_up){ + yellow_inverse = false; + } + + if (red_threshold == red_up){ + red_inverse = false; + } //Array with points to be painted var threshold_data = new Array(); //Array with some interesting points var extremes = new Array (); - - yellow_threshold = parseFloat (yellow_threshold); - yellow_up = parseFloat (yellow_up); - red_threshold = parseFloat (red_threshold); - red_up = parseFloat (red_up); + var yellow_only_min = ((yellow_up == 0) && (yellow_threshold != 0)); - red_only_min = ((red_up == 0) && (red_threshold != 0)); + var red_only_min = ((red_up == 0) && (red_threshold != 0)); + //color var normalw = '#efe'; var warningw = '#ffe'; var criticalw = '#fee'; @@ -2525,6 +2526,7 @@ console.log(data_module_graph); if (threshold) { // Warning interval. Change extremes depends on critical interval if (yellow_inverse && red_inverse) { + console.log('entra'); if (red_only_min && yellow_only_min) { // C: |-------- | // W: |········==== | @@ -3054,14 +3056,9 @@ console.log(data_module_graph); xaxes: [{ axisLabelFontSizePixels: font_size, mode: "time", - //min: date_array.start_date * 1000, - //max: date_array.final_date * 1000, - tickFormatter: xFormatter, - // timeformat: "%Y/%m/%d %H:%M:%S", + tickFormatter: xFormatter }], yaxes: [{ - //min: min_check, - //max: 5000, tickFormatter: yFormatter, color: '', alignTicksWithAxis: 1, @@ -3086,7 +3083,7 @@ console.log(data_module_graph); var stack = 0, bars = true, lines = false, steps = false; var plot = $.plot($('#' + graph_id), datas, options); - console.log(plot); + // Re-calculate the graph height with the legend height if (dashboard || vconsole) { var hDiff = $('#'+graph_id).height() - $('#legend_'+graph_id).height(); @@ -3144,8 +3141,7 @@ console.log(data_module_graph); if (menu == 0) { return; } - - //XXX + dataInSelection = ranges.xaxis.to - ranges.xaxis.from; //time_format_y = dataInSelection; dataInPlot = plot.getData()[0].data.length; @@ -3159,12 +3155,11 @@ console.log(data_module_graph); xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to}, xaxes: [ { tickFormatter: xFormatter, - //XXX - //minTickSize: new_steps, color: '' } ], - legend: { show: false } + legend: { show: true } })); + if (thresholded) { var zoom_data_threshold = new Array (); @@ -3212,7 +3207,6 @@ console.log(data_module_graph); function updateLegend() { updateLegendTimeout = null; var pos = latestPosition; - console.log(pos); var axes = currentPlot.getAxes(); if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max || @@ -3224,13 +3218,11 @@ console.log(data_module_graph); var i = 0; - console.log(dataset); for (k = 0; k < dataset.length; k++) { // k is the real series counter // i is the series counter without thresholds var series = dataset[k]; - console.log(series); if (series.label == null) { continue; } @@ -3411,7 +3403,6 @@ console.log(data_module_graph); // Format functions function xFormatter(v, axis) { - //console.log('x: '+ v); //XXX /* if ($period <= SECONDS_6HOURS) { @@ -3560,9 +3551,7 @@ console.log(data_module_graph); // cancel the zooming plot = $.plot($('#' + graph_id), data_base, $.extend(true, {}, options, { - //XXX - xaxis: {max: max_x }, - legend: { show: false } + legend: { show: true } })); $('#menu_cancelzoom_' + graph_id) From 4b654bd87df88e9d04e08b4770c4681f36cf6839 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 21 Feb 2018 11:54:24 +0100 Subject: [PATCH 07/33] fixed errors grapgh --- pandora_console/include/functions.php | 156 ++++-- pandora_console/include/functions_graph.php | 466 ++++++++++++++---- .../include/graphs/flot/pandora.flot.js | 168 ++++--- .../include/graphs/functions_flot.php | 2 +- 4 files changed, 580 insertions(+), 212 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 7f70444ec3..3b5dc766f0 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2792,65 +2792,123 @@ function validate_address($address){ return true; } -function color_graph_array($series_suffix){ +function color_graph_array($series_suffix, $compare = false){ global $config; ////////////////////////////////////////////////// // Color commented not to restrict serie colors // ////////////////////////////////////////////////// - $color['event' . $series_suffix] = - array( 'border' => '#ff0000', - 'color' => '#ff0000', - 'alpha' => CHART_DEFAULT_ALPHA - ); - - $color['alert' . $series_suffix] = - array( 'border' => '#ff7f00', - 'color' => '#ff7f00', - 'alpha' => CHART_DEFAULT_ALPHA - ); - - $color['unknown' . $series_suffix] = - array( 'border' => '#999999', - 'color' => '#999999', - 'alpha' => CHART_DEFAULT_ALPHA - ); - - $color['no_data'.$series_suffix] = - array( 'border' => '#000000', - 'color' => '#f2c40e', - 'alpha' => CHART_DEFAULT_ALPHA + if(!$compare) { + $color['event' . $series_suffix] = + array( 'border' => '#ff0000', + 'color' => '#ff0000', + 'alpha' => CHART_DEFAULT_ALPHA ); - - $color['max'.$series_suffix] = - array( 'border' => '#000000', - 'color' => $config['graph_color3'], - 'alpha' => CHART_DEFAULT_ALPHA - ); - - $color['sum'.$series_suffix] = - array( 'border' => '#000000', - 'color' => $config['graph_color2'], - 'alpha' => CHART_DEFAULT_ALPHA - ); - - $color['min'.$series_suffix] = - array( 'border' => '#000000', - 'color' => $config['graph_color1'], - 'alpha' => CHART_DEFAULT_ALPHA + + $color['alert' . $series_suffix] = + array( 'border' => '#ff7f00', + 'color' => '#ff7f00', + 'alpha' => CHART_DEFAULT_ALPHA ); - $color['unit'.$series_suffix] = - array( 'border' => null, - 'color' => '#0097BC', - 'alpha' => 10 + $color['unknown' . $series_suffix] = + array( 'border' => '#999999', + 'color' => '#999999', + 'alpha' => CHART_DEFAULT_ALPHA ); + + $color['no_data'.$series_suffix] = + array( 'border' => '#000000', + 'color' => '#f2c40e', + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['max'.$series_suffix] = + array( 'border' => '#000000', + 'color' => $config['graph_color3'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['sum'.$series_suffix] = + array( 'border' => '#000000', + 'color' => $config['graph_color2'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['min'.$series_suffix] = + array( 'border' => '#000000', + 'color' => $config['graph_color1'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['unit'.$series_suffix] = + array( 'border' => null, + 'color' => '#0097BC', + 'alpha' => 10 + ); + + $color['percentil'.$series_suffix] = + array( 'border' => '#000000', + 'color' => '#0097BC', + 'alpha' => CHART_DEFAULT_ALPHA + ); + } + else{ + $color['event' . $series_suffix] = + array( 'border' => '#ff0000', + 'color' => '#ff66cc', + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['alert' . $series_suffix] = + array( 'border' => '#ffff00', + 'color' => '#ffff00', + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['unknown' . $series_suffix] = + array( 'border' => '#999999', + 'color' => '#E1E1E1', + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['no_data'.$series_suffix] = + array( 'border' => '#000000', + 'color' => '#f2c40e', + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['max'.$series_suffix] = + array( 'border' => '#000000', + 'color' => $config['graph_color3'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['sum'.$series_suffix] = + array( 'border' => '#000000', + 'color' => '#99ffff', + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['min'.$series_suffix] = + array( 'border' => '#000000', + 'color' => $config['graph_color1'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + + $color['unit'.$series_suffix] = + array( 'border' => null, + 'color' => '#0097BC', + 'alpha' => 10 + ); + + $color['percentil'.$series_suffix] = + array( 'border' => '#000000', + 'color' => '#003333', + 'alpha' => CHART_DEFAULT_ALPHA + ); - $color['percentil'.$series_suffix] = - array( 'border' => '#000000', - 'color' => '#0097BC', - 'alpha' => CHART_DEFAULT_ALPHA - ); + } return $color; } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index fb80f34ec8..c62552f67f 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -227,6 +227,125 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { return $stats; } +function grafico_modulo_sparse_data_chart_new ( + $agent_module_id, + $date_array, + $data_module_graph, + $show_elements_graph, + $format_graph, + $series_suffix + ) { + + global $config; + + $data = db_get_all_rows_filter ('tagente_datos', + array ('id_agente_modulo' => (int)$agent_module_id, + "utimestamp > '". $date_array['start_date']. "'", + "utimestamp < '". $date_array['final_date'] . "'", + 'order' => 'utimestamp ASC'), + array ('datos', 'utimestamp'), 'AND', $data_module_graph['history_db']); + + // Get previous data + $previous_data = modules_get_previous_data ( + $agent_module_id, + $date_array['start_date'] + ); + + if ($previous_data !== false) { + $previous_data['utimestamp'] = $date_array['start_date']; + unset($previous_data['id_agente_modulo']); + array_unshift ($data, $previous_data); + } + + // Get next data + $nextData = modules_get_next_data ( + $agent_module_id, + $date_array['final_date'] + ); + + if ($nextData !== false) { + unset($nextData['id_agente_modulo']); + array_push ($data, $nextData); + } + else if (count ($data) > 0) { + // Propagate the last known data to the end of the interval + $nextData = array( + 'datos' => $data[count($data)-1]['datos'], + 'utimestamp' => $date_array['final_date'], + ); + array_push ($data, $nextData); + } + + if ($data === false) { + $data = array (); + } + + // Check available data + if (count ($data) < 1) { + //if (!$graphic_type) { + return fs_error_image (); + //} + //graphic_error (); + } + $array_data = array(); + $min_value = PHP_INT_MAX-1; + $max_value = PHP_INT_MIN+1; + $array_percentil = array(); + + foreach ($data as $k => $v) { + //convert array + if($show_elements_graph['flag_overlapped']){ + $array_data["sum" . $series_suffix]['data'][$k] = array( + ($v['utimestamp'] + $date_array['period'] )* 1000, + $v['datos'] + ); + } + else{ + $array_data["sum" . $series_suffix]['data'][$k] = array( + $v['utimestamp'] * 1000, + $v['datos'] + ); + } + + //min + if($min_value > $v['datos']){ + $min_value = $v['datos']; + } + + //max + if($max_value < $v['datos']){ + $max_value = $v['datos']; + } + + //avg + $sum_data += $v['datos']; + $count_data++; + + //percentil + if (!is_null($show_elements_graph['percentil']) && $show_elements_graph['percentil']) { + $array_percentil[] = $v['datos']; + } + } + + $array_data["sum" . $series_suffix]['min'] = $min_value; + $array_data["sum" . $series_suffix]['max'] = $max_value; + $array_data["sum" . $series_suffix]['avg'] = $sum_data/$count_data; + + if (!is_null($show_elements_graph['percentil']) && $show_elements_graph['percentil'] && !$show_elements_graph['flag_overlapped']) { + $percentil_result = get_percentile($show_elements_graph['percentil'], $array_percentil); + $array_data["percentil" . $series_suffix]['data'][0] = array( + $date_array['start_date'] * 1000, + $percentil_result + ); + $array_data["percentil" . $series_suffix]['data'][1] = array( + $date_array['final_date'] * 1000, + $percentil_result + ); + } + return $array_data; +} + + function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_index, $data, $data_i, $previous_data, $resolution, $interval, $period, $datelimit, $projection, $avg_only = false, $uncompressed_module = false, @@ -537,7 +656,8 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i function grafico_modulo_sparse_data_new( $agent_module_id, $date_array, $data_module_graph, $show_elements_graph, - $format_graph, $exception_interval_graph ) { + $format_graph, $exception_interval_graph, + $series_suffix, $str_series_suffix) { global $config; global $array_data; @@ -546,22 +666,30 @@ function grafico_modulo_sparse_data_new( global $legend; global $series_type; - $series_suffix = 1; - if($show_elements_graph['fullscale']){ $array_data = fullscale_data_new( - $agent_module_id, - $date_array, + $agent_module_id, + $date_array, $show_elements_graph['show_unknown'], - $show_elements_graph['percentil'] + $show_elements_graph['percentil'], + $series_suffix, + $str_series_suffix, + $show_elements_graph['flag_overlapped'] ); } else{ - + $array_data = grafico_modulo_sparse_data_chart_new ( + $agent_module_id, + $date_array, + $data_module_graph, + $show_elements_graph, + $format_graph, + $series_suffix + ); } if($show_elements_graph['percentil']){ - $percentil_value = $array_data['percentil' . $series_suffix]['data'][0][0]; + $percentil_value = $array_data['percentil' . $series_suffix]['data'][0][1]; } else{ $percentil_value = 0; @@ -574,71 +702,119 @@ function grafico_modulo_sparse_data_new( $avg = $array_data['sum'. $series_suffix]['avg']; } - if( $show_elements_graph['show_unknown'] && - isset($array_data['unknown' . $series_suffix]) && - is_array($array_data['unknown' . $series_suffix]['data']) ){ - foreach ($array_data['unknown' . $series_suffix]['data'] as $key => $s_date) { - if ($s_date[1] == 1) { - $array_data['unknown' . $series_suffix]['data'][$key] = array($s_date[0], $max * 1.05); - } - } - } - - if ($show_elements_graph['show_events'] || - $show_elements_graph['show_alerts'] ) { + if(!$show_elements_graph['flag_overlapped']){ - $events = db_get_all_rows_filter ( - 'tevento', - array ('id_agentmodule' => $agent_module_id, - "utimestamp > " . $date_array['start_date'], - "utimestamp < " . $date_array['final_date'], - 'order' => 'utimestamp ASC' - ), - false, - 'AND', - $data_module_graph['history_db'] - ); - - $alerts_array = array(); - $events_array = array(); - - if($events && is_array($events)){ - $i=0; - foreach ($events as $k => $v) { - if (strpos($v["event_type"], "alert") !== false){ - $alerts_array['data'][$i] = array( ($v['utimestamp']*1000) , $max * 1.10); + if($show_elements_graph['fullscale']){ + if( $show_elements_graph['show_unknown'] && + isset($array_data['unknown' . $series_suffix]) && + is_array($array_data['unknown' . $series_suffix]['data']) ){ + foreach ($array_data['unknown' . $series_suffix]['data'] as $key => $s_date) { + if ($s_date[1] == 1) { + $array_data['unknown' . $series_suffix]['data'][$key] = array($s_date[0], $max * 1.05); + } } - else{ - $events_array['data'][$i] = array( ($v['utimestamp']*1000) , $max * 1.2); - } - $i++; } } + else{ + if( $show_elements_graph['show_unknown'] ) { + $unknown_events = db_get_module_ranges_unknown( + $agent_module_id, + $date_array['start_date'], + $date_array['final_date'], + $data_module_graph['history_db'] + ); + if($unknown_events !== false){ + foreach ($unknown_events as $key => $s_date) { + if( isset($s_date['time_from']) ){ + $array_data['unknown' . $series_suffix]['data'][] = array( + ($s_date['time_from'] - 1) * 1000, + 0 + ); + + $array_data['unknown' . $series_suffix]['data'][] = array( + $s_date['time_from'] * 1000, + $max * 1.05 + ); + } + else{ + $array_data['unknown' . $series_suffix]['data'][] = array( + $date_array['start_date'] * 1000, + $max * 1.05 + ); + } + + if( isset($s_date['time_to']) ){ + $array_data['unknown' . $series_suffix]['data'][] = array( + $s_date['time_to'] * 1000, + $max * 1.05 + ); + + $array_data['unknown' . $series_suffix]['data'][] = array( + ($s_date['time_to'] + 1) * 1000, + 0 + ); + } + else{ + $array_data['unknown' . $series_suffix]['data'][] = array( + $date_array['final_date'] * 1000, + $max * 1.05 + ); + } + } + } + } + } + + if ($show_elements_graph['show_events'] || + $show_elements_graph['show_alerts'] ) { + + $events = db_get_all_rows_filter ( + 'tevento', + array ('id_agentmodule' => $agent_module_id, + "utimestamp > " . $date_array['start_date'], + "utimestamp < " . $date_array['final_date'], + 'order' => 'utimestamp ASC' + ), + false, + 'AND', + $data_module_graph['history_db'] + ); - /* - // Get the last event after inverval to know if graph start on unknown - $prev_event = db_get_row_filter ( - 'tevento', - array ('id_agentmodule' => $agent_module_id, - "utimestamp <= $datelimit", - 'order' => 'utimestamp DESC' - ), - false, - 'AND', - $search_in_history_db - ); - */ - } + $alerts_array = array(); + $events_array = array(); - - - if($show_elements_graph['show_events']){ - $array_data['event' . $series_suffix] = $events_array; - } + if($events && is_array($events)){ + $i=0; + foreach ($events as $k => $v) { + if (strpos($v["event_type"], "alert") !== false){ + if($show_elements_graph['flag_overlapped']){ + $alerts_array['data'][$i] = array( ($v['utimestamp'] + $date_array['period'] *1000) , $max * 1.10); + } + else{ + $alerts_array['data'][$i] = array( ($v['utimestamp']*1000) , $max * 1.10); + } + } + else{ + if($show_elements_graph['flag_overlapped']){ + $events_array['data'][$i] = array( ($v['utimestamp'] + $date_array['period'] *1000) , $max * 1.2); + } + else{ + $events_array['data'][$i] = array( ($v['utimestamp']*1000) , $max * 1.2); + } + } + $i++; + } + } + } + + if($show_elements_graph['show_events']){ + $array_data['event' . $series_suffix] = $events_array; + } - if($show_elements_graph['show_alerts']){ - $array_data['alert' . $series_suffix] = $alerts_array; + if($show_elements_graph['show_alerts']){ + $array_data['alert' . $series_suffix] = $alerts_array; + } } if ($show_elements_graph['return_data'] == 1) { @@ -658,11 +834,9 @@ function grafico_modulo_sparse_data_new( $caption = array(); } + //XXX //$graph_stats = get_statwin_graph_statistics($chart, $series_suffix); - - - - $color = color_graph_array($series_suffix); + $color = color_graph_array($series_suffix, $show_elements_graph['flag_overlapped']); foreach ($color as $k => $v) { if(is_array($array_data[$k])){ @@ -1157,23 +1331,101 @@ if($flash_chart && $entra_por){ $exception_interval_graph['max_only'] = $max_only; $exception_interval_graph['min_only'] = $min_only; - $series_suffix =1; - $$series_suffix_str = ''; + if ($show_elements_graph['compare'] !== false) { + $series_suffix = 2; + $series_suffix_str = ' (' . __('Previous') . ')'; + + $date_array_prev['final_date'] = $date_array['start_date']; + $date_array_prev['start_date'] = $date_array['start_date'] - $date_array['period']; + $date_array_prev['period'] = $date_array['period']; + + if ($show_elements_graph['compare'] === 'overlapped') { + $show_elements_graph['flag_overlapped'] = 1; + } + else{ + $show_elements_graph['flag_overlapped'] = 0; + } + + grafico_modulo_sparse_data_new( + $agent_module_id, $date_array_prev, + $data_module_graph, $show_elements_graph, + $format_graph, $exception_interval_graph, + $series_suffix, $series_suffix_str + ); + + switch ($show_elements_graph['compare']) { + case 'separated': + case 'overlapped': + // Store the chart calculated + $array_data_prev = $array_data; + $legend_prev = $legend; + $series_type_prev = $series_type; + $color_prev = $color; + $caption_prev = $caption; + break; + } + } + + $series_suffix = 1; + $series_suffix_str = ''; + $show_elements_graph['flag_overlapped'] = 0; grafico_modulo_sparse_data_new( - $agent_module_id, $date_array, $data_module_graph, - $show_elements_graph, $format_graph, - $exception_interval_graph + $agent_module_id, $date_array, + $data_module_graph, $show_elements_graph, + $format_graph, $exception_interval_graph, + $series_suffix, $str_series_suffix ); - + + if($show_elements_graph['compare']){ + if ($show_elements_graph['compare'] === 'overlapped') { + $array_data = array_merge($array_data, $array_data_prev); + $legend = array_merge($legend, $legend_prev); + $color = array_merge($color, $color_prev); + } + } + if (empty($array_data)) { + //XXXX return graph_nodata_image($width, $height); return ''; } + //XXX setup_watermark($water_mark, $water_mark_file, $water_mark_url); - return flot_area_graph_new( + if ($show_elements_graph['compare'] === 'separated') { + return flot_area_graph_new( + $agent_module_id, + $array_data, + $color, + $legend, + $series_type, + $date_array, + $data_module_graph, + $show_elements_graph, + $format_graph, + $water_mark, + $series_suffix_str + ) . + '
' + . + flot_area_graph_new( + $agent_module_id, + $array_data_prev, + $color, + $legend, + $series_type, + $date_array, + $data_module_graph, + $show_elements_graph, + $format_graph, + $water_mark, + $series_suffix_str + ); + } + else{ + return flot_area_graph_new( $agent_module_id, $array_data, $color, @@ -1186,7 +1438,7 @@ if($flash_chart && $entra_por){ $water_mark, $series_suffix_str ); - + } die(); } @@ -4898,8 +5150,10 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, function fullscale_data_new ( $agent_module_id, $date_array, - $show_unknown = 0, $show_percentil = 0 ){ - + $show_unknown = 0, $show_percentil = 0, + $series_suffix, $str_series_suffix = '', + $compare = false){ + global $config; $data_uncompress = db_uncompress_module_data( @@ -4910,7 +5164,6 @@ function fullscale_data_new ( $data = array(); $previous_data = 0; - $series_suffix = 1; $min_value = PHP_INT_MAX-1; $max_value = PHP_INT_MIN+1; $flag_unknown = 0; @@ -4920,17 +5173,24 @@ function fullscale_data_new ( if (isset($v["type"]) && $v["type"] == 1) { # skip unnecesary virtual data continue; } - $real_date = $v['utimestamp'] * 1000; // * 1000 need js utimestam mlsecond + if($compare){ // * 1000 need js utimestam mlsecond + $real_date = ($v['utimestamp'] + $date_array['period']) * 1000; + } + else{ + $real_date = $v['utimestamp'] * 1000; + } if ($v["datos"] === NULL) { // Unknown - if($flag_unknown){ - $data["unknown" . $series_suffix]['data'][] = array($real_date , 1); - } - else{ - $data["unknown" . $series_suffix]['data'][] = array( ($real_date - 1) , 0); - $data["unknown" . $series_suffix]['data'][] = array($real_date , 1); - $flag_unknown = 1; + if(!$compare){ + if($flag_unknown){ + $data["unknown" . $series_suffix]['data'][] = array($real_date , 1); + } + else{ + $data["unknown" . $series_suffix]['data'][] = array( ($real_date - 1) , 0); + $data["unknown" . $series_suffix]['data'][] = array($real_date , 1); + $flag_unknown = 1; + } } $data["sum" . $series_suffix]['data'][] = array($real_date , $previous_data); @@ -4946,9 +5206,11 @@ function fullscale_data_new ( //normal $previous_data = $v["datos"]; $data["sum" . $series_suffix]['data'][] = array($real_date , $v["datos"]); - if($flag_unknown){ - $data["unknown" . $series_suffix]['data'][] = array($real_date , 0); - $flag_unknown = 0; + if(!$compare){ + if($flag_unknown){ + $data["unknown" . $series_suffix]['data'][] = array($real_date , 0); + $flag_unknown = 0; + } } } @@ -4967,7 +5229,7 @@ function fullscale_data_new ( //avg count $count_data++; - if($show_percentil){ + if($show_percentil && !$compare){ $array_percentil[] = $v["datos"]; } @@ -4975,13 +5237,25 @@ function fullscale_data_new ( } } - if($show_percentil){ + if($show_percentil && !$compare){ $percentil_result = get_percentile($show_percentil, $array_percentil); - $data["percentil" . $series_suffix]['data'][] = array($date_array['start_date'] * 1000 , $percentil_result); - $data["percentil" . $series_suffix]['data'][] = array($date_array['final_date'] * 1000 , $percentil_result); + if($compare){ + $data["percentil" . $series_suffix]['data'][] = array( ($date_array['start_date'] + $date_array['period']) * 1000 , $percentil_result); + $data["percentil" . $series_suffix]['data'][] = array( ($date_array['final_date'] + $date_array['period']) * 1000 , $percentil_result); + } + else{ + $data["percentil" . $series_suffix]['data'][] = array($date_array['start_date'] * 1000 , $percentil_result); + $data["percentil" . $series_suffix]['data'][] = array($date_array['final_date'] * 1000 , $percentil_result); + } } // Add missed last data - $data["sum" . $series_suffix]['data'][] = array($date_array['final_date'] * 1000 , $last_data); + if($compare){ + $data["sum" . $series_suffix]['data'][] = array( ($date_array['final_date'] + $date_array['period']) * 1000 , $last_data); + } + else{ + $data["sum" . $series_suffix]['data'][] = array($date_array['final_date'] * 1000 , $last_data); + } + $data["sum" . $series_suffix]['min'] = $min_value; $data["sum" . $series_suffix]['max'] = $max_value; $data["sum" . $series_suffix]['avg'] = $sum_data/$count_data; diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index f6229209bf..83f459a3ca 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -869,6 +869,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, yellow_up, red_up, yellow_inverse, red_inverse, series_suffix_str, dashboard, vconsole, xaxisname,background_color,legend_color, short_data) { +console.log(legend_events); var threshold = true; var thresholded = false; @@ -2282,6 +2283,7 @@ function axis_thresholded (threshold_data, y_min, y_max, red_threshold, extremes normal_down: 0, down: null }; + // Resize the y axis to display all intervals $.each(threshold_data, function() { if (/_up/.test(this.id)){ @@ -2322,14 +2324,12 @@ function axis_thresholded (threshold_data, y_min, y_max, red_threshold, extremes ? yaxis_resize['up'] + margin_up_or_down : y_min; } - return y; } function add_threshold (data_base, threshold_data, y_min, y_max, red_threshold, extremes, red_up) { - + var datas = new Array (); - $.each(data_base, function() { // Prepared to turning series //if(showed[this.id.split('_')[1]]) { @@ -2370,9 +2370,7 @@ function add_threshold (data_base, threshold_data, y_min, y_max, } datas.push(this); }); - return datas; - } function reduceText (text, maxLength) { @@ -2382,8 +2380,6 @@ function reduceText (text, maxLength) { return str_cut + '...' + text.substr(-firstSlideEnd - 3); } - - function pandoraFlotAreaNew( graph_id, values, legend, agent_module_id, series_type, watermark, date_array, @@ -2391,23 +2387,10 @@ function pandoraFlotAreaNew( format_graph, force_integer, series_suffix_str, background_color, legend_color, short_data ) { - - var threshold = true; - var thresholded = false; - if(format_graph.unit){ - var unit = format_graph.unit; - } - else{ - var unit = ''; - } - - //XXXX - var type = 'area_simple'; - var xaxisname = 'xaxisname'; - var labels_long = ''; - var min_check = 0; - var water_mark = ''; - + console.log(series_suffix_str); + console.log('asdasdasdas'); + //vars + var unit = format_graph.unit ? format_graph.unit : ''; var homeurl = format_graph.homeurl; var font_size = format_graph.font_size; var font = format_graph.font; @@ -2416,6 +2399,27 @@ function pandoraFlotAreaNew( var vconsole = show_elements_graph.vconsole; var dashboard = show_elements_graph.dashboard; var menu = show_elements_graph.menu; + var max_x = date_array['final_date'] *1000; + + //for threshold + var threshold = true; + var thresholded = false; + var yellow_threshold = parseFloat (data_module_graph.w_min); + var red_threshold = parseFloat (data_module_graph.c_min); + var yellow_up = parseFloat (data_module_graph.w_max); + var red_up = parseFloat (data_module_graph.c_max); + var yellow_inverse = parseInt(data_module_graph.w_inv); + var red_inverse = parseInt(data_module_graph.c_inv); + + + //XXXX + var type = 'area_simple'; + var xaxisname = 'xaxisname'; + var labels_long = ''; + var min_check = 0; + var water_mark = ''; + var legend_events = null; + var legend_alerts = null; switch (type) { case 'line_simple': @@ -2474,7 +2478,7 @@ function pandoraFlotAreaNew( data_base.push({ id: 'serie_' + i, data: value.data, - label: index, + label: index + series_suffix_str, color: value.color, lines: { show: line_show, @@ -2487,17 +2491,7 @@ function pandoraFlotAreaNew( i++; } }); - - max_x = date_array['final_date'] *1000; - console.log(max_x); - - var yellow_threshold = parseFloat (data_module_graph.w_min); - var red_threshold = parseFloat (data_module_graph.c_min); - var yellow_up = parseFloat (data_module_graph.w_max); - var red_up = parseFloat (data_module_graph.c_max); - - var yellow_inverse = data_module_graph.w_inv; - var red_inverse = data_module_graph.c_inv; + console.log(series_suffix_str); // If threshold and up are the same, that critical or warning is disabled if (yellow_threshold == yellow_up){ yellow_inverse = false; @@ -2526,7 +2520,6 @@ function pandoraFlotAreaNew( if (threshold) { // Warning interval. Change extremes depends on critical interval if (yellow_inverse && red_inverse) { - console.log('entra'); if (red_only_min && yellow_only_min) { // C: |-------- | // W: |········==== | @@ -3032,7 +3025,8 @@ function pandoraFlotAreaNew( if (unit != "") { xaxisname = xaxisname + " (" + unit + ")" } - + + var maxticks = date_array['period'] / 3600 /6; var options = { series: { stack: stacked, @@ -3056,7 +3050,9 @@ function pandoraFlotAreaNew( xaxes: [{ axisLabelFontSizePixels: font_size, mode: "time", - tickFormatter: xFormatter + tickFormatter: xFormatter, + tickSize: [maxticks, 'hour'], + labelWidth: 70 }], yaxes: [{ tickFormatter: yFormatter, @@ -3149,22 +3145,54 @@ function pandoraFlotAreaNew( factor = dataInSelection / dataInPlot; new_steps = parseInt(factor * steps); - - plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to}, - xaxes: [ { - tickFormatter: xFormatter, - color: '' - } ], - legend: { show: true } - })); + var maxticks_zoom = dataInSelection / 3600000 / 6; + flag_caca = 0; + if(maxticks_zoom < 0.005){ + flag_caca = 1; + maxticks_zoom = dataInSelection / 60000 / 6; + if(maxticks_zoom < 0.005){ + maxticks_zoom = 1; + } + } + + console.log(maxticks_zoom); + if(flag_caca == 0){ + plot = $.plot($('#' + graph_id), data_base, + $.extend(true, {}, options, { + grid: { borderWidth: 1, hoverable: true, autoHighlight: false}, + xaxis: { min: ranges.xaxis.from, + max: ranges.xaxis.to + }, + xaxes: [ { + mode: "time", + tickFormatter: xFormatter, + tickSize: [maxticks_zoom, 'hour'] + } ], + legend: { show: true } + })); + } + else{ + plot = $.plot($('#' + graph_id), data_base, + $.extend(true, {}, options, { + grid: { borderWidth: 1, hoverable: true, autoHighlight: false}, + xaxis: { min: ranges.xaxis.from, + max: ranges.xaxis.to + }, + xaxes: [ { + mode: "time", + tickFormatter: xFormatter, + tickSize: [maxticks_zoom, 'minute'] + } ], + legend: { show: true } + })); + } if (thresholded) { var zoom_data_threshold = new Array (); var y_recal = axis_thresholded(threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, red_threshold, extremes, red_up); + plot = $.plot($('#' + graph_id), data_base, $.extend(true, {}, options, { yaxis: { @@ -3299,7 +3327,7 @@ function pandoraFlotAreaNew( $('#timestamp_'+graph_id).hide(); } - var label_aux = series.label; + var label_aux = series.label + series_suffix_str; // The graphs of points type and unknown graphs will dont be updated @@ -3393,7 +3421,7 @@ function pandoraFlotAreaNew( dataset = plot.getData(); for (i = 0; i < dataset.length; ++i) { var series = dataset[i]; - var label_aux = series.label; + var label_aux = series.label + series_suffix_str; $('#legend_' + graph_id + ' .legendLabel') .eq(i).html(label_aux); } @@ -3429,10 +3457,17 @@ function pandoraFlotAreaNew( var result_date_format = 0; // if(time_format_y > 86400000){ //DAY - + var monthNames = [ + "Jan", "Feb", "Mar", + "Apr", "May", "Jun", + "Jul", "Aug", "Sep", + "Oct", "Nov", "Dec" + ]; + result_date_format = - (d.getDate() <10?'0':'') + d.getDate() + "/" + - (d.getMonth()<9?'0':'') + (d.getMonth() + 1) + "/" + + (d.getDate() <10?'0':'') + d.getDate() + " " + + //(d.getMonth()<9?'0':'') + (d.getMonth() + 1) + "/" + + monthNames[d.getMonth()] + " " + d.getFullYear() + "\n" + (d.getHours()<10?'0':'') + d.getHours() + ":" + (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + @@ -3446,7 +3481,7 @@ function pandoraFlotAreaNew( } */ //extra_css = ''; - return '
'+result_date_format+'
'; + return '
'+result_date_format+'
'; } function yFormatter(v, axis) { @@ -3462,6 +3497,7 @@ function pandoraFlotAreaNew( } function lFormatter(v, item) { + console.log(v); return '
'+v+'
'; // Prepared to turn series with a checkbox //return '
'+v+'
'; @@ -3522,17 +3558,17 @@ function pandoraFlotAreaNew( red_threshold, extremes, red_up); plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - yaxis: { - max: y_recal.max, - min: y_recal.min - }, - xaxis: { - mode:"time", - min: plot.getAxes().xaxis.min, - max: plot.getAxes().xaxis.max - } - })); + $.extend(true, {}, options, { + yaxis: { + max: y_recal.max, + min: y_recal.min + }, + xaxis: { + //mode:"time", + //min: plot.getAxes().xaxis.min, + //max: plot.getAxes().xaxis.max + } + })); datas = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, red_threshold, extremes, red_up); diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 1ccaf388b3..38e5f5ff4a 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -586,7 +586,7 @@ function flot_area_graph_new ( html_debug_print($water_mark); html_debug_print($series_suffix_str); */ - + //html_debug_print($series_suffix_str); $background_style = ''; switch ($format_graph['background']) { default: From 688acb8a4b1f3dcc1460253da071598ab2e96984 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 23 Feb 2018 14:31:00 +0100 Subject: [PATCH 08/33] fixed error graphs --- pandora_console/include/functions.php | 256 ++--------- pandora_console/include/functions_graph.php | 11 +- .../include/graphs/flot/pandora.flot.js | 435 +++++++++--------- .../include/graphs/functions_flot.php | 12 +- 4 files changed, 263 insertions(+), 451 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 3b5dc766f0..b2b3d532ac 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2919,225 +2919,53 @@ function legend_graph_array( $series_suffix_str, $format_graph, $show_elements_graph, - $percentil_value){ - + $percentil_value, + $data_module_graph){ + + global $config; + global $legend; $unit = $format_graph['unit']; - if ($show_elements_graph['show_events']) { - $legend['event'.$series_suffix_str] = __('Events').$series_suffix_str; + $legend['sum'.$series_suffix] = + $data_module_graph['module_name'] . ' ' . + __('Min:') . remove_right_zeros( + number_format( + $min, + $config['graph_precision'] + ) + ) . ' ' . + __('Max:') . remove_right_zeros( + number_format( + $max, + $config['graph_precision'] + ) + ) . ' ' . + _('Avg:') . remove_right_zeros( + number_format( + $max, + $config['graph_precision'] + ) + ) . ' ' . $series_suffix_str; + + if($show_elements_graph['show_unknown']){ + $legend['unknown'.$series_suffix] = __('Unknown') . ' ' . $series_suffix_str; } - if ($show_elements_graph['show_alerts']) { - $legend['alert'.$series_suffix] = __('Alerts').$series_suffix_str; + if($show_elements_graph['show_events']){ + $legend['event'.$series_suffix] = __('Events') . ' ' . $series_suffix_str; + } + if($show_elements_graph['show_alerts']){ + $legend['alert'.$series_suffix] = __('Alert') . ' ' . $series_suffix_str; + } + if($show_elements_graph['percentil']){ + $legend['percentil'.$series_suffix] = __('Percentil') . ' Value: ' . + remove_right_zeros( + number_format( + $percentil_value, + $config['graph_precision'] + ) + ) . ' ' . $series_suffix_str; } - if ($show_elements_graph['vconsole']) { - $legend['sum'.$series_suffix] = - __('Last') . ': ' . - remove_right_zeros( - number_format( - $graph_stats['sum']['last'], - $config['graph_precision'] - ) - ) . ($unit ? ' ' . $unit : '') . ' ; '. - __('Avg') . ': ' . - remove_right_zeros( - number_format( - $graph_stats['sum']['avg'], - $config['graph_precision'] - ) - ) . ($unit ? ' ' . $unit : '' - ); - } - else if ( $show_elements_graph['dashboard'] && - !$show_elements_graph['avg_only'] ) { - - $legend['max'.$series_suffix] = - __('Max').$series_suffix_str.': '.__('Avg').': '. - remove_right_zeros( - number_format( - $graph_stats['max']['avg'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Max').': '. - remove_right_zeros( - number_format( - $graph_stats['max']['max'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Min').': '. - remove_right_zeros( - number_format( - $graph_stats['max']['min'], - $config['graph_precision'] - ) - ).' '.$unit; - - $legend['sum'.$series_suffix] = - __('Avg').$series_suffix_str.': '.__('Avg').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['avg'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Max').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['max'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Min').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['min'], - $config['graph_precision'] - ) - ).' '.$unit; - - $legend['min'.$series_suffix] = - __('Min').$series_suffix_str.': '.__('Avg').': '. - remove_right_zeros( - number_format( - $graph_stats['min']['avg'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Max').': '. - remove_right_zeros( - number_format( - $graph_stats['min']['max'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Min').': '. - remove_right_zeros( - number_format( - $graph_stats['min']['min'], - $config['graph_precision'] - ) - ).' '.$unit; - } - else if ($show_elements_graph['dashboard']) { - $legend['sum'.$series_suffix] = - __('Last') . ': ' . - remove_right_zeros( - number_format( - $graph_stats['sum']['last'], - $config['graph_precision'] - ) - ) . ($unit ? ' ' . $unit : '') . ' ; '. - __('Avg') . ': ' . - remove_right_zeros( - number_format( - $graph_stats['sum']['avg'], - $config['graph_precision'] - ) - ) . ($unit ? ' ' . $unit : ''); - } - else if (!$show_elements_graph['avg_only'] && - !$show_elements_graph['fullscale']) { - - $legend['max'.$series_suffix] = - __('Max').$series_suffix_str.': '.__('Avg').': '. - remove_right_zeros( - number_format( - $graph_stats['max']['avg'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Max').': '. - remove_right_zeros( - number_format( - $graph_stats['max']['max'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Min').': '. - remove_right_zeros( - number_format( - $graph_stats['max']['min'], - $config['graph_precision'] - ) - ).' '.$unit; - - $legend['sum'.$series_suffix] = - __('Avg').$series_suffix_str.': '. - __('Avg').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['avg'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Max').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['max'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Min').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['min'], - $config['graph_precision'] - ) - ).' '.$unit; - - $legend['min'.$series_suffix] = - __('Min').$series_suffix_str.': '. - __('Avg').': '. - remove_right_zeros( - number_format( - $graph_stats['min']['avg'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Max').': '. - remove_right_zeros( - number_format( - $graph_stats['min']['max'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Min').': '. - remove_right_zeros( - number_format( - $graph_stats['min']['min'], - $config['graph_precision'] - ) - ).' '.$unit; - } - else if ($show_elements_graph['fullscale']){ - $legend['sum'.$series_suffix] = - __('Data').$series_suffix_str.': '; - } - else { - $legend['sum'.$series_suffix] = - __('Avg').$series_suffix_str.': '. - __('Avg').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['avg'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '. - __('Max').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['max'], - $config['graph_precision'] - ) - ).' '.$unit.' ; '.__('Min').': '. - remove_right_zeros( - number_format( - $graph_stats['sum']['min'], - $config['graph_precision'] - ) - ).' '.$unit; - } - - if ($show_elements_graph['show_unknown']) { - $legend['unknown'.$series_suffix] = - __('Unknown').$series_suffix_str; - } - - if (!is_null($show_elements_graph['percentil']) && - $show_elements_graph['percentil']) { - $legend['percentil'.$series_suffix] = - __('Percentile %dº', $percentil) . $series_suffix_str . " (" . $percentil_value . " " . $unit . ") "; - } return $legend; } ?> diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index c62552f67f..012196c8ad 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -844,13 +844,14 @@ function grafico_modulo_sparse_data_new( } } - $legend = legend_graph_array( + legend_graph_array( $max, $min, $avg, $series_suffix, - $series_suffix_str, + $str_series_suffix, $format_graph, $show_elements_graph, - $percentil_value + $percentil_value, + $data_module_graph ); $series_type['event'.$series_suffix] = 'points'; @@ -862,8 +863,7 @@ function grafico_modulo_sparse_data_new( else{ $series_type['sum'.$series_suffix] = 'area'; } - $series_type['percentil' . $series_suffix] = 'line'; - + $series_type['percentil' . $series_suffix] = 'percentil'; } function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, @@ -1034,7 +1034,6 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, graphic_error (); } - // Data iterator $data_i = 0; diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 83f459a3ca..968c0d7600 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -869,7 +869,6 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, yellow_up, red_up, yellow_inverse, red_inverse, series_suffix_str, dashboard, vconsole, xaxisname,background_color,legend_color, short_data) { -console.log(legend_events); var threshold = true; var thresholded = false; @@ -2121,23 +2120,26 @@ console.log(legend_events); } function adjust_menu(graph_id, plot, parent_height, width) { + /* if ($('#'+graph_id+' .xAxis .tickLabel').eq(0).css('width') != undefined) { left_ticks_width = $('#'+graph_id+' .xAxis .tickLabel').eq(0).css('width').split('px')[0]; } else { left_ticks_width = 0; } - + */ var parent_height_new = 0; var legend_height = parseInt($('#legend_'+graph_id).css('height').split('px')[0]) + parseInt($('#legend_'+graph_id).css('margin-top').split('px')[0]); + + /* if ($('#overview_'+graph_id).css('display') == 'none') { overview_height = 0; } else { overview_height = parseInt($('#overview_'+graph_id).css('height').split('px')[0]) + parseInt($('#overview_'+graph_id).css('margin-top').split('px')[0]); } - + */ var menu_height = '25'; if ($('#menu_'+graph_id).height() != undefined && $('#menu_'+graph_id).height() > 20) { @@ -2223,7 +2225,7 @@ function adjust_left_width_canvas(adapter_id, adapted_id) { function update_left_width_canvas(graph_id) { - $('#overview_'+graph_id).width($('#'+graph_id).width() - 30); + $('#overview_'+graph_id).width($('#'+graph_id).width()); $('#overview_'+graph_id).css('margin-left', $('#'+graph_id+' .yAxis .tickLabel').width()); } @@ -2387,19 +2389,18 @@ function pandoraFlotAreaNew( format_graph, force_integer, series_suffix_str, background_color, legend_color, short_data ) { - console.log(series_suffix_str); - console.log('asdasdasdas'); - //vars - var unit = format_graph.unit ? format_graph.unit : ''; - var homeurl = format_graph.homeurl; - var font_size = format_graph.font_size; - var font = format_graph.font; - var width = format_graph.width; - var height = format_graph.height; - var vconsole = show_elements_graph.vconsole; - var dashboard = show_elements_graph.dashboard; - var menu = show_elements_graph.menu; - var max_x = date_array['final_date'] *1000; + console.log(legend); + //diferents vars + var unit = format_graph.unit ? format_graph.unit : ''; + var homeurl = format_graph.homeurl; + var font_size = format_graph.font_size; + var font = format_graph.font; + var width = format_graph.width; + var height = format_graph.height; + var vconsole = show_elements_graph.vconsole; + var dashboard = show_elements_graph.dashboard; + var menu = show_elements_graph.menu; + var max_x = date_array['final_date'] *1000; //for threshold var threshold = true; @@ -2408,70 +2409,73 @@ function pandoraFlotAreaNew( var red_threshold = parseFloat (data_module_graph.c_min); var yellow_up = parseFloat (data_module_graph.w_max); var red_up = parseFloat (data_module_graph.c_max); - var yellow_inverse = parseInt(data_module_graph.w_inv); - var red_inverse = parseInt(data_module_graph.c_inv); + var yellow_inverse = parseInt (data_module_graph.w_inv); + var red_inverse = parseInt (data_module_graph.c_inv); - //XXXX - var type = 'area_simple'; - var xaxisname = 'xaxisname'; - var labels_long = ''; - var min_check = 0; - var water_mark = ''; + //XXXX ver que hay que hacer + var type = 'area_simple'; + //var xaxisname = 'xaxisname'; + + var labels_long = ''; + var min_check = 0; + var water_mark = ''; + var legend_events = null; var legend_alerts = null; switch (type) { case 'line_simple': stacked = null; - filled = false; + filled = false; break; case 'line_stacked': stacked = 'stack'; - filled = false; + filled = false; break; case 'area_simple': stacked = null; - filled = true; + filled = true; break; case 'area_stacked': stacked = 'stack'; - filled = true; + filled = true; break; } - var datas = new Array(); + var datas = new Array(); var data_base = new Array(); - var data2 = new Array(); - i=0; var lineWidth = $('#hidden-line_width_graph').val() || 1; + + i=0; $.each(values, function (index, value) { if (typeof value.data !== "undefined") { switch (series_type[index]) { case 'area': - line_show = true; + line_show = true; points_show = false; // XXX - false - filled = 0.2; + filled = 0.2; steps_chart = false; break; + case 'percentil': case 'line': default: - line_show = true; + line_show = true; points_show = false; - filled = false; + filled = false; steps_chart = false; break; case 'points': - line_show = false; + line_show = false; points_show = true; - filled = false; + filled = false; steps_chart = false break; case 'unknown': case 'boolean': - line_show = true; + line_show = true; points_show = false; - filled = true; + filled = true; steps_chart = true; break; } @@ -2491,7 +2495,7 @@ function pandoraFlotAreaNew( i++; } }); - console.log(series_suffix_str); + // If threshold and up are the same, that critical or warning is disabled if (yellow_threshold == yellow_up){ yellow_inverse = false; @@ -2510,12 +2514,12 @@ function pandoraFlotAreaNew( var red_only_min = ((red_up == 0) && (red_threshold != 0)); //color - var normalw = '#efe'; - var warningw = '#ffe'; + var normalw = '#efe'; + var warningw = '#ffe'; var criticalw = '#fee'; - var normal = '#0f0'; - var warning = '#ff0'; - var critical = '#f00'; + var normal = '#0f0'; + var warning = '#ff0'; + var critical = '#f00'; if (threshold) { // Warning interval. Change extremes depends on critical interval @@ -3022,18 +3026,19 @@ function pandoraFlotAreaNew( var count_data = datas[0].data.length; var min_tick_pixels = 80; - if (unit != "") { - xaxisname = xaxisname + " (" + unit + ")" - } - var maxticks = date_array['period'] / 3600 /6; var options = { series: { stack: stacked, shadowSize: 0.1 }, - crosshair: { mode: 'xy' }, - selection: { mode: 'x', color: '#777' }, + crosshair: { + mode: 'xy' + }, + selection: { + mode: 'x', + color: '#777' + }, export: { export_data: true, labels_long: labels_long, @@ -3062,7 +3067,6 @@ function pandoraFlotAreaNew( position: 'left', font: font, reserveSpace: true, - }], legend: { position: 'se', @@ -3077,7 +3081,11 @@ function pandoraFlotAreaNew( options.selection = false; } - var stack = 0, bars = true, lines = false, steps = false; + var stack = 0, + bars = true, + lines = false, + steps = false; + var plot = $.plot($('#' + graph_id), datas, options); // Re-calculate the graph height with the legend height @@ -3114,20 +3122,39 @@ function pandoraFlotAreaNew( var overview = $.plot($('#overview_'+graph_id),datas, { series: { stack: stacked, - lines: { show: true, lineWidth: 1 }, + lines: { + show: true, + lineWidth: 1 + }, shadowSize: 0 }, - grid: { borderWidth: 1, hoverable: true, autoHighlight: false}, - xaxis: { }, - xaxes: [ { - tickFormatter: xFormatter, - minTickSize: steps, - color: '' - } ], - yaxis: {ticks: [], autoscaleMargin: 0.1 }, - selection: {mode: 'x', color: '#777' }, - legend: {show: false}, - crosshair: {mode: 'x'} + grid: { + borderWidth: 1, + borderColor: '#C1C1C1', + hoverable: true, + autoHighlight: false + }, + xaxes: [ { + axisLabelFontSizePixels: font_size, + mode: "time", + tickFormatter: xFormatter, + tickSize: [maxticks, 'hour'], + labelWidth: 70, + } ], + yaxis: { + ticks: [], + autoscaleMargin: 0.1 + }, + selection: { + mode: 'x', + color: '#777' + }, + legend: { + show: false + }, + crosshair: { + mode: 'x' + } }); } // Connection between plot and miniplot @@ -3139,53 +3166,35 @@ function pandoraFlotAreaNew( } dataInSelection = ranges.xaxis.to - ranges.xaxis.from; - //time_format_y = dataInSelection; - dataInPlot = plot.getData()[0].data.length; - factor = dataInSelection / dataInPlot; - - new_steps = parseInt(factor * steps); var maxticks_zoom = dataInSelection / 3600000 / 6; - flag_caca = 0; - if(maxticks_zoom < 0.005){ - flag_caca = 1; + if(maxticks_zoom < 0.001){ maxticks_zoom = dataInSelection / 60000 / 6; - if(maxticks_zoom < 0.005){ - maxticks_zoom = 1; + if(maxticks_zoom < 0.001){ + maxticks_zoom = 0; } } - - console.log(maxticks_zoom); - if(flag_caca == 0){ - plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - grid: { borderWidth: 1, hoverable: true, autoHighlight: false}, - xaxis: { min: ranges.xaxis.from, - max: ranges.xaxis.to - }, - xaxes: [ { - mode: "time", - tickFormatter: xFormatter, - tickSize: [maxticks_zoom, 'hour'] - } ], - legend: { show: true } - })); - } - else{ - plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - grid: { borderWidth: 1, hoverable: true, autoHighlight: false}, - xaxis: { min: ranges.xaxis.from, - max: ranges.xaxis.to - }, - xaxes: [ { - mode: "time", - tickFormatter: xFormatter, - tickSize: [maxticks_zoom, 'minute'] - } ], - legend: { show: true } - })); - } + + plot = $.plot($('#' + graph_id), data_base, + $.extend(true, {}, options, { + grid: { + borderWidth: 1, + hoverable: true, + autoHighlight: true + }, + xaxis: { + min: ranges.xaxis.from, + max: ranges.xaxis.to + }, + xaxes: [{ + mode: "time", + tickFormatter: xFormatter, + tickSize: [maxticks_zoom, 'hour'] + }], + legend: { + show: true + } + })); if (thresholded) { var zoom_data_threshold = new Array (); @@ -3204,8 +3213,10 @@ function pandoraFlotAreaNew( max: plot.getAxes().xaxis.max } })); + zoom_data_threshold = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, red_threshold, extremes, red_up); + plot.setData(zoom_data_threshold); plot.draw(); } @@ -3224,47 +3235,79 @@ function pandoraFlotAreaNew( plot.setSelection(ranges); }); - var legends = $('#legend_' + graph_id + ' .legendLabel'); - var updateLegendTimeout = null; - var latestPosition = null; - var currentPlot = null; - var currentRanges = null; + var latestPosition = null; + var currentPlot = null; + var currentRanges = null; // Update legend with the data of the plot in the mouse position function updateLegend() { + console.log(currentPlot); updateLegendTimeout = null; var pos = latestPosition; - var axes = currentPlot.getAxes(); if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max || pos.y < axes.yaxis.min || pos.y > axes.yaxis.max) { return; } - var j, dataset = currentPlot.getData(); + $('#timestamp_'+graph_id).show(); + + var d = new Date(pos.x); + var monthNames = [ + "Jan", "Feb", "Mar", + "Apr", "May", "Jun", + "Jul", "Aug", "Sep", + "Oct", "Nov", "Dec" + ]; + + date_format = (d.getDate() <10?'0':'') + d.getDate() + " " + + monthNames[d.getMonth()] + " " + + d.getFullYear() + "\n" + + (d.getHours()<10?'0':'') + d.getHours() + ":" + + (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + + (d.getSeconds()<10?'0':'') + d.getSeconds(); + $('#timestamp_'+graph_id).text(date_format); + + var timesize = $('#timestamp_'+graph_id).width(); + + dataset = currentPlot.getData(); + + var timenewpos = dataset[0].xaxis.p2c(pos.x)+$('.yAxis>div').eq(0).width(); + var canvaslimit = $('#'+graph_id).width(); + + + $('#timestamp_'+graph_id).css('top', currentPlot.offset().top - $('#timestamp_'+graph_id).height()*2.5); + + + if (timesize+timenewpos > canvaslimit) { + $('#timestamp_'+graph_id).css('left', timenewpos - timesize); + } + else { + $('#timestamp_'+graph_id).css('left', timenewpos); + } + + var dataset = currentPlot.getData(); var i = 0; - for (k = 0; k < dataset.length; k++) { - // k is the real series counter // i is the series counter without thresholds var series = dataset[k]; if (series.label == null) { continue; } - + // find the nearest points, x-wise - for (j = 0; j < series.data.length; ++j) + for (j = 0; j < series.data.length; ++j){ if (series.data[j][0] > pos.x) { break; } - if(series.data[j]){ - var x = series.data[j][0]; - var y = series.data[j][1]; + + if(series.data[j]){ + var y = series.data[j][1]; + } } - var how_bigger = ""; if (y > 1000000) { @@ -3284,57 +3327,18 @@ function pandoraFlotAreaNew( y = y / 1000; } - if (currentRanges == null || (currentRanges.xaxis.from < j && j < currentRanges.xaxis.to)) { - $('#timestamp_'+graph_id).show(); - // If no legend, the timestamp labels are short and with value - if (legend.length == 0) { - $('#timestamp_'+graph_id).text(labels[j] + ' (' + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + ')'); - } - else { - var d = new Date(x); - - date_format = (d.getDate() <10?'0':'') + d.getDate() + "/" + - (d.getMonth()<9?'0':'') + (d.getMonth() + 1) + "/" + - d.getFullYear() + "\n" + - (d.getHours()<10?'0':'') + d.getHours() + ":" + - (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + - (d.getSeconds()<10?'0':'') + d.getSeconds(); - - $('#timestamp_'+graph_id).text(date_format); - } - //$('#timestamp_'+graph_id).css('top', plot.offset().top-$('#timestamp_'+graph_id).height()*1.5); - - var timesize = $('#timestamp_'+graph_id).width(); - - if (currentRanges != null) { - dataset = plot.getData(); - } - - var timenewpos = dataset[0].xaxis.p2c(pos.x)+$('.yAxis>div').eq(0).width(); - - var canvaslimit = plot.width(); - - if (timesize+timenewpos > canvaslimit) { - $('#timestamp_'+graph_id).css('left', timenewpos - timesize); - $('#timestamp_'+graph_id).css('top', 50); - } - else { - $('#timestamp_'+graph_id).css('left', timenewpos); - $('#timestamp_'+graph_id).css('top', 50); - } - } - else { - $('#timestamp_'+graph_id).hide(); - } - - var label_aux = series.label + series_suffix_str; + var label_aux = legend[series.label] + series_suffix_str; // The graphs of points type and unknown graphs will dont be updated - - serie_types = new Array(); - if (serie_types[i] != 'points' && series.label != $('#hidden-unknown_text').val()) { + if (series_type[dataset[k]["label"]] != 'points' && + series_type[dataset[k]["label"]] != 'unknown' && + series_type[dataset[k]["label"]] != 'percentil' + ) { $('#legend_' + graph_id + ' .legendLabel') - .eq(i).html(label_aux + '= ' + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + how_bigger + ' ' + unit); + .eq(i).html(label_aux + ' value = ' + + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + + how_bigger + ' ' + unit + ); } $('#legend_' + graph_id + ' .legendLabel') @@ -3345,20 +3349,30 @@ function pandoraFlotAreaNew( $('#legend_' + graph_id + ' .legendLabel') .eq(i).css('font-family',font+'Font'); - + i++; } } // Events + $('#overview_' + graph_id).bind('plothover', function (event, pos, item) { + plot.setCrosshair({ x: pos.x, y: 0 }); + currentPlot = plot; + latestPosition = pos; + console.log('entra'); + if (!updateLegendTimeout) { + updateLegendTimeout = setTimeout(updateLegend, 50); + } + }); + $('#' + graph_id).bind('plothover', function (event, pos, item) { overview.setCrosshair({ x: pos.x, y: 0 }); currentPlot = plot; latestPosition = pos; + console.log('entra 2'); if (!updateLegendTimeout) { updateLegendTimeout = setTimeout(updateLegend, 50); } - }); $('#' + graph_id).bind("plotclick", function (event, pos, item) { @@ -3415,13 +3429,13 @@ function pandoraFlotAreaNew( $('#'+graph_id).bind('mouseout',resetInteractivity); $('#overview_'+graph_id).bind('mouseout',resetInteractivity); - //~ // Reset interactivity styles + // Reset interactivity styles function resetInteractivity() { $('#timestamp_'+graph_id).hide(); dataset = plot.getData(); for (i = 0; i < dataset.length; ++i) { var series = dataset[i]; - var label_aux = series.label + series_suffix_str; + var label_aux = legend[series.label] + ' ' + series_suffix_str; $('#legend_' + graph_id + ' .legendLabel') .eq(i).html(label_aux); } @@ -3431,56 +3445,23 @@ function pandoraFlotAreaNew( // Format functions function xFormatter(v, axis) { - //XXX - /* - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = "M \nd H:i"; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = "M \nd H\h"; - } - elseif ($period < SECONDS_6MONTHS) { - $time_format = "M \nd H\h"; - } - else { - $time_format = "Y M \nd H\h"; - } - */ - var d = new Date(v); var result_date_format = 0; + + var monthNames = [ + "Jan", "Feb", "Mar", + "Apr", "May", "Jun", + "Jul", "Aug", "Sep", + "Oct", "Nov", "Dec" + ]; - // if(time_format_y > 86400000){ //DAY - var monthNames = [ - "Jan", "Feb", "Mar", - "Apr", "May", "Jun", - "Jul", "Aug", "Sep", - "Oct", "Nov", "Dec" - ]; - - result_date_format = - (d.getDate() <10?'0':'') + d.getDate() + " " + - //(d.getMonth()<9?'0':'') + (d.getMonth() + 1) + "/" + - monthNames[d.getMonth()] + " " + - d.getFullYear() + "\n" + - (d.getHours()<10?'0':'') + d.getHours() + ":" + - (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + - (d.getSeconds()<10?'0':'') + d.getSeconds(); //+ ":" + d.getMilliseconds(); - /* } - else{ - result_date_format = - d.getHours() + ":" + - d.getMinutes() + ":" + - d.getSeconds(); //+ ":" + d.getMilliseconds(); - } - */ - //extra_css = ''; + result_date_format = (d.getDate() <10?'0':'') + d.getDate() + " " + + monthNames[d.getMonth()] + " " + + d.getFullYear() + "\n" + + (d.getHours()<10?'0':'') + d.getHours() + ":" + + (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + + (d.getSeconds()<10?'0':'') + d.getSeconds(); + return '
'+result_date_format+'
'; } @@ -3492,15 +3473,12 @@ function pandoraFlotAreaNew( else { var formatted = v; } - return '
'+formatted+'
'; } function lFormatter(v, item) { console.log(v); - return '
'+v+'
'; - // Prepared to turn series with a checkbox - //return '
'+v+'
'; + return '
'+legend[v]+'
'; } if (menu) { @@ -3609,10 +3587,9 @@ function pandoraFlotAreaNew( // Estimated height of 24 (works fine with this data in all browsers) menu_height = 24; var legend_margin_bottom = parseInt( - $('#legend_'+graph_id).css('margin-bottom').split('px')[0]); + $('#legend_'+graph_id).css('margin-bottom').split('px')[0]); $('#legend_'+graph_id).css('margin-bottom', '10px'); - parent_height = parseInt( - $('#menu_'+graph_id).parent().css('height').split('px')[0]); + parent_height = parseInt($('#menu_'+graph_id).parent().css('height').split('px')[0]); adjust_menu(graph_id, plot, parent_height, width); } diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 38e5f5ff4a..5356dd57b3 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -187,7 +187,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, global $config; include_javascript_dependencies_flot_graph(); - + $menu = (int)$menu; // Get a unique identifier to graph $graph_id = uniqid('graph_'); @@ -666,13 +666,15 @@ function flot_area_graph_new ( else { $format_graph['height'] = 1; } - if (!$vconsole) + + if (!$vconsole){ $return .= "
"; + } //XXXXTODO $water_mark = ''; if ($water_mark != '') { @@ -765,6 +767,12 @@ function flot_area_graph_new ( return $return; } + + + + + + function menu_graph( $yellow_threshold, $red_threshold, $yellow_up, $red_up, $yellow_inverse, From d2390528acf2b3302f97be63073d14d4cdf18372 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 27 Feb 2018 16:28:00 +0100 Subject: [PATCH 09/33] fixed errors in graphs --- pandora_console/include/functions.php | 54 +- pandora_console/include/functions_db.php | 119 +- pandora_console/include/functions_graph.php | 2840 ++++------------- pandora_console/include/functions_modules.php | 21 +- pandora_console/include/graphs/fgraph.php | 301 +- .../include/graphs/flot/pandora.flot.js | 1393 +------- .../include/graphs/functions_flot.php | 559 +--- .../mobile/operation/module_graph.php | 149 +- .../operation/agentes/stat_win.php | 137 +- 9 files changed, 1010 insertions(+), 4563 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index b2b3d532ac..c3b10f03d6 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2766,12 +2766,12 @@ function register_pass_change_try ($id_user, $success) { } function isJson($string) { - json_decode($string); - return (json_last_error() == JSON_ERROR_NONE); + json_decode($string); + return (json_last_error() == JSON_ERROR_NONE); } /** - * returns true or false if it is a valid ip + * returns true or false if it is a valid ip * checking ipv4 and ipv6 or resolves the name dns * @param string address * @@ -2804,7 +2804,7 @@ function color_graph_array($series_suffix, $compare = false){ 'color' => '#ff0000', 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['alert' . $series_suffix] = array( 'border' => '#ff7f00', 'color' => '#ff7f00', @@ -2816,25 +2816,25 @@ function color_graph_array($series_suffix, $compare = false){ 'color' => '#999999', 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['no_data'.$series_suffix] = array( 'border' => '#000000', 'color' => '#f2c40e', 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['max'.$series_suffix] = array( 'border' => '#000000', 'color' => $config['graph_color3'], 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['sum'.$series_suffix] = array( 'border' => '#000000', 'color' => $config['graph_color2'], 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['min'.$series_suffix] = array( 'border' => '#000000', 'color' => $config['graph_color1'], @@ -2846,7 +2846,7 @@ function color_graph_array($series_suffix, $compare = false){ 'color' => '#0097BC', 'alpha' => 10 ); - + $color['percentil'.$series_suffix] = array( 'border' => '#000000', 'color' => '#0097BC', @@ -2859,7 +2859,7 @@ function color_graph_array($series_suffix, $compare = false){ 'color' => '#ff66cc', 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['alert' . $series_suffix] = array( 'border' => '#ffff00', 'color' => '#ffff00', @@ -2871,25 +2871,25 @@ function color_graph_array($series_suffix, $compare = false){ 'color' => '#E1E1E1', 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['no_data'.$series_suffix] = array( 'border' => '#000000', 'color' => '#f2c40e', 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['max'.$series_suffix] = array( 'border' => '#000000', 'color' => $config['graph_color3'], 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['sum'.$series_suffix] = array( 'border' => '#000000', - 'color' => '#99ffff', + 'color' => '#b781c1', 'alpha' => CHART_DEFAULT_ALPHA ); - + $color['min'.$series_suffix] = array( 'border' => '#000000', 'color' => $config['graph_color1'], @@ -2901,15 +2901,15 @@ function color_graph_array($series_suffix, $compare = false){ 'color' => '#0097BC', 'alpha' => 10 ); - + $color['percentil'.$series_suffix] = array( 'border' => '#000000', 'color' => '#003333', 'alpha' => CHART_DEFAULT_ALPHA ); - + } - + return $color; } @@ -2921,28 +2921,28 @@ function legend_graph_array( $show_elements_graph, $percentil_value, $data_module_graph){ - + global $config; global $legend; $unit = $format_graph['unit']; - $legend['sum'.$series_suffix] = + $legend['sum'.$series_suffix] = $data_module_graph['module_name'] . ' ' . __('Min:') . remove_right_zeros( number_format( - $min, + $min, $config['graph_precision'] ) - ) . ' ' . + ) . ' ' . __('Max:') . remove_right_zeros( number_format( - $max, + $max, $config['graph_precision'] ) - ) . ' ' . + ) . ' ' . _('Avg:') . remove_right_zeros( number_format( - $max, + $max, $config['graph_precision'] ) ) . ' ' . $series_suffix_str; @@ -2957,10 +2957,10 @@ function legend_graph_array( $legend['alert'.$series_suffix] = __('Alert') . ' ' . $series_suffix_str; } if($show_elements_graph['percentil']){ - $legend['percentil'.$series_suffix] = __('Percentil') . ' Value: ' . + $legend['percentil'.$series_suffix] = __('Percentil') . ' Value: ' . remove_right_zeros( number_format( - $percentil_value, + $percentil_value, $config['graph_precision'] ) ) . ' ' . $series_suffix_str; diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index b92a9fbcc5..1f5a26f7e9 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -418,7 +418,7 @@ function db_get_row ($table, $field_search, $condition, $fields = false) { */ function db_get_row_filter($table, $filter, $fields = false, $where_join = 'AND', $historydb = false) { global $config; - + switch ($config["dbtype"]) { case "mysql": return mysql_db_get_row_filter($table, $filter, $fields, $where_join, $historydb); @@ -443,10 +443,10 @@ function db_get_row_filter($table, $filter, $fields = false, $where_join = 'AND' function db_get_sql ($sql, $field = 0, $search_history_db = false) { $result = db_get_all_rows_sql ($sql, $search_history_db); - + if ($result === false) return false; - + $ax = 0; foreach ($result[0] as $f) { if ($field == $ax) @@ -467,7 +467,7 @@ function db_get_sql ($sql, $field = 0, $search_history_db = false) { */ function db_get_all_rows_sql($sql, $search_history_db = false, $cache = true, $dbconnection = false) { global $config; - + switch ($config["dbtype"]) { case "mysql": return mysql_db_get_all_rows_sql($sql, $search_history_db, $cache, $dbconnection); @@ -482,15 +482,12 @@ function db_get_all_rows_sql($sql, $search_history_db = false, $cache = true, $d } /** - * * Returns the time the module is in unknown status (by events) - * * @param int $id_agente_modulo module to check * @param int $tstart begin of search * @param int $tend end of search - * */ -function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend = false, $historydb = false) { +function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend = false, $historydb = false, $fix_to_range = 0) { global $config; if (!isset($id_agente_modulo)) { @@ -512,18 +509,39 @@ function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend } // Retrieve going unknown events in range - $query = "SELECT utimestamp,event_type FROM tevento WHERE id_agentmodule = " . $id_agente_modulo; - $query .= " AND event_type like 'going_%' "; - $query .= " AND utimestamp >= $tstart AND utimestamp <= $tend "; - $query .= " ORDER BY utimestamp ASC"; - + $query = "SELECT * FROM tevento WHERE id_agentmodule = " . $id_agente_modulo + . " AND event_type like 'going_%' " + . " AND utimestamp >= $tstart AND utimestamp <= $tend " + . " ORDER BY utimestamp ASC"; $events = db_get_all_rows_sql($query, $historydb); - if (! is_array($events)){ + $query = "SELECT * FROM tevento WHERE id_agentmodule = " . $id_agente_modulo + . " AND event_type like 'going_%' " + . " AND utimestamp < $tstart " + . " ORDER BY utimestamp DESC LIMIT 1;"; + $previous_event = db_get_all_rows_sql($query, $historydb); + + if ($previous_event !== false) { + $last_status = $previous_event[0]["event_type"] == "going_unknown" ? 1:0; + } + else { + $last_status = 0; + } + + if ((! is_array($events)) && (! is_array($previous_event))) { return false; } - $last_status = $events[0]["event_type"] != "going_unknown" ? 1:0; + if (! is_array($events)) { + if ($previous_event[0]["event_type"] == "going_unknown") { + return array( + array( + "time_from" => (($fix_to_range == 1)?$tstart:$previous_event[0]["utimestamp"]), + ) + ); + } + } + $return = array(); $i=0; foreach ($events as $event) { @@ -558,23 +576,22 @@ function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend return $return; } - /** * Uncompresses and returns the data of a given id_agent_module - * + * * @param int $id_agente_modulo id_agente_modulo * @param utimestamp $tstart Begin of the catch * @param utimestamp $tend End of the catch * @param int $interval Size of slice (default-> module_interval) - * + * * @return hash with the data uncompressed in blocks of module_interval * false in case of empty result - * + * * Note: All "unknown" data are marked as NULL * Warning: Be careful with the amount of data, check your RAM size available * We'll return a bidimensional array * Structure returned: schema: - * + * * uncompressed_data => * pool_id (int) * utimestamp (start of current slice) @@ -582,7 +599,7 @@ function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend * array * datos * utimestamp - * + * */ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = false) { global $config; @@ -602,7 +619,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f $search_historydb = false; $table = "tagente_datos"; - + $module = modules_get_agentmodule($id_agente_modulo); if ($module === false){ // module not exists @@ -610,11 +627,11 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f } $module_type = $module['id_tipo_modulo']; $module_type_str = modules_get_type_name ($module_type); - + if (strstr ($module_type_str, 'string') !== false) { $table = "tagente_datos_string"; } - + $flag_async = false; if(strstr ($module_type_str, 'async_data') !== false) { $flag_async = true; @@ -634,7 +651,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f else { $query = "SELECT datos,utimestamp FROM $table "; $query .= " WHERE id_agente_modulo=$id_agente_modulo "; - $query .= " AND utimestamp=" . $first_utimestamp; + $query .= " AND utimestamp = " . $first_utimestamp; $data = db_get_all_rows_sql($query,$search_historydb); @@ -652,7 +669,6 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f else { $first_data["utimestamp"] = $data[0]["utimestamp"]; $first_data["datos"] = $data[0]["datos"]; - } } @@ -670,27 +686,11 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f } // Retrieve going unknown events in range - $unknown_events = db_get_module_ranges_unknown($id_agente_modulo, $tstart, $tend, $search_historydb); - - // Get the last event after inverval to know if graph start on unknown - $previous_unknown_events = db_get_row_filter ( - 'tevento', - array ('id_agentmodule' => $id_agente_modulo, - "utimestamp <= $tstart", - 'order' => 'utimestamp DESC' - ), - false, - 'AND', - $search_historydb + $unknown_events = db_get_module_ranges_unknown( + $id_agente_modulo, $tstart, + $tend, $search_historydb, 1 ); - //show graph if graph is inside unknown - if( $previous_unknown_events && $previous_unknown_events['event_type'] == 'going_unknown' && - $unknown_events === false){ - $last_inserted_value = $first_data["datos"]; - $unknown_events[0]['time_from'] = $tstart; - } - //if time to is missing in last event force time to outside range time if( $unknown_events && !isset($unknown_events[count($unknown_events) -1]['time_to']) ){ $unknown_events[count($unknown_events) -1]['time_to'] = $tend; @@ -699,8 +699,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f //if time to is missing in first event force time to outside range time if ($first_data["datos"] === false && !$flag_async) { $last_inserted_value = false; - }elseif(($unknown_events && !isset($unknown_events[0]['time_from']) && - $previous_unknown_events && $previous_unknown_events['event_type'] == 'going_unknown' && !$flag_async) || + }elseif(($unknown_events && !isset($unknown_events[0]['time_from']) && !$flag_async) || ($first_utimestamp < $tstart - (SECONDS_1DAY + 2*$module_interval) && !$flag_async) ){ $last_inserted_value = $first_data["datos"]; $unknown_events[0]['time_from'] = $tstart; @@ -734,7 +733,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f else{ $current_unknown = null; } - + if(is_array($raw_data)) { $current_raw_data = array_pop($raw_data); } @@ -751,15 +750,15 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f || (($current_timestamp - $last_timestamp) > (SECONDS_1DAY + 2 * $module_interval)) ) { $tmp_data["utimestamp"] = $current_timestamp; - + //check not init $tmp_data["datos"] = $last_value === false ? false : null; - + //async not unknown if($flag_async && $tmp_data["datos"] === null){ $tmp_data["datos"] = $last_inserted_value; } - + // debug purpose //$tmp_data["obs"] = "unknown extra"; array_push($return[$pool_id]["data"], $tmp_data); @@ -767,9 +766,9 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f //insert raw data while ( ($current_raw_data != null) && - ( ($current_timestamp_end > $current_raw_data['utimestamp']) && + ( ($current_timestamp_end > $current_raw_data['utimestamp']) && ($current_timestamp <= $current_raw_data['utimestamp']) ) ) { - + // Add real data detected if (count($return[$pool_id]['data']) == 0) { //insert first slice data @@ -802,16 +801,16 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f $current_raw_data = null; } } - + //unknown $data_slices = $return[$pool_id]["data"]; if(!$flag_async){ while ( ($current_unknown != null) && ( ( ($current_unknown['time_from'] != null) && - ($current_timestamp_end >= $current_unknown['time_from']) ) || + ($current_timestamp_end >= $current_unknown['time_from']) ) || ($current_timestamp_end >= $current_unknown['time_to']) ) ) { - if( ( $current_timestamp <= $current_unknown['time_from']) && + if( ( $current_timestamp <= $current_unknown['time_from']) && ( $current_timestamp_end >= $current_unknown['time_from'] ) ){ if (count($return[$pool_id]['data']) == 0) { //insert first slice data @@ -835,7 +834,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f array_push($return[$pool_id]["data"], $tmp_data); $current_unknown["time_from"] = null; } - elseif( ($current_timestamp <= $current_unknown['time_to']) && + elseif( ($current_timestamp <= $current_unknown['time_to']) && ($current_timestamp_end > $current_unknown['time_to'] ) ){ if (count($return[$pool_id]['data']) == 0) { @@ -864,7 +863,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f } $i--; } - + // debug purpose //$tmp_data["obs"] = "event data unknown to"; array_push($return[$pool_id]["data"], $tmp_data); @@ -904,7 +903,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f //put the last slice data like first element of next slice $last_inserted_value = end($return[$pool_id]['data']); $last_inserted_value = $last_inserted_value['datos']; - + //increment $pool_id++; $current_timestamp = $current_timestamp_end; @@ -950,7 +949,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f */ function db_get_all_rows_filter($table, $filter = array(), $fields = false, $where_join = 'AND', $search_history_db = false, $returnSQL = false) { global $config; - + switch ($config["dbtype"]) { case "mysql": return mysql_db_get_all_rows_filter($table, $filter, $fields, $where_join, $search_history_db, $returnSQL); diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 012196c8ad..1925a836d7 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -22,27 +22,27 @@ include_once($config['homedir'] . "/include/functions_users.php"); function get_graph_statistics ($chart_array) { global $config; - + /// IMPORTANT! /// /// The calculus for AVG, MIN and MAX values are in this function - /// because it must be done based on graph array data not using reporting + /// because it must be done based on graph array data not using reporting /// function to get coherent data between stats and graph visualization - + $stats = array (); - + $count = 0; - + $size = sizeof($chart_array); - + //Initialize stats array $stats = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - + foreach ($chart_array as $item) { - + //Sum all values later divide by the number of elements $stats['avg'] = $stats['avg'] + $item; - + //Get minimum if ($stats['min'] == null) { $stats['min'] = $item; @@ -50,7 +50,7 @@ function get_graph_statistics ($chart_array) { else if ($item < $stats['min']) { $stats['min'] = $item; } - + //Get maximum if ($stats['max'] == null) { $stats['max'] = $item; @@ -58,49 +58,49 @@ function get_graph_statistics ($chart_array) { else if ($item > $stats['max']) { $stats['max'] = $item; } - + $count++; - + //Get last data if ($count == $size) { $stats['last'] = $item; } } - + //End the calculus for average if ($count > 0) { - + $stats['avg'] = $stats['avg'] / $count; } - + //Format stat data to display properly $stats['last'] = remove_right_zeros(number_format($stats['last'], $config['graph_precision'])); $stats['avg'] = remove_right_zeros(number_format($stats['avg'], $config['graph_precision'])); $stats['min'] = remove_right_zeros(number_format($stats['min'], $config['graph_precision'])); $stats['max'] = remove_right_zeros(number_format($stats['max'], $config['graph_precision'])); - + return $stats; } function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { - + /// IMPORTANT! /// /// The calculus for AVG, MIN and MAX values are in this function - /// because it must be done based on graph array data not using reporting + /// because it must be done based on graph array data not using reporting /// function to get coherent data between stats and graph visualization - + $stats = array (); - + $count = 0; - + $size = sizeof($chart_array); - + //Initialize stats array $stats['sum'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); $stats['min'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); $stats['max'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - + foreach ($chart_array as $item) { if ($series_suffix != '') { if (isset($item['sum' . $series_suffix])) @@ -110,13 +110,13 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { if (isset($item['max' . $series_suffix])) $item['max'] = $item['max' . $series_suffix]; } - + //Get stats for normal graph if (isset($item['sum']) && $item['sum']) { - + //Sum all values later divide by the number of elements $stats['sum']['avg'] = $stats['sum']['avg'] + $item['sum']; - + //Get minimum if ($stats['sum']['min'] == null) { $stats['sum']['min'] = $item['sum']; @@ -124,7 +124,7 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { else if ($item['sum'] < $stats['sum']['min']) { $stats['sum']['min'] = $item['sum']; } - + //Get maximum if ($stats['sum']['max'] == null) { $stats['sum']['max'] = $item['sum']; @@ -132,14 +132,13 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { else if ($item['sum'] > $stats['sum']['max']) { $stats['sum']['max'] = $item['sum']; } - } - + //Get stats for min graph if (isset($item['min']) && $item['min']) { //Sum all values later divide by the number of elements $stats['min']['avg'] = $stats['min']['avg'] + $item['min']; - + //Get minimum if ($stats['min']['min'] == null) { $stats['min']['min'] = $item['min']; @@ -147,7 +146,7 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { else if ($item['min'] < $stats['min']['min']) { $stats['min']['min'] = $item['min']; } - + //Get maximum if ($stats['min']['max'] == null) { $stats['min']['max'] = $item['min']; @@ -155,14 +154,13 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { else if ($item['min'] > $stats['min']['max']) { $stats['min']['max'] = $item['min']; } - } - + //Get stats for max graph if (isset($item['max']) && $item['max']) { //Sum all values later divide by the number of elements $stats['max']['avg'] = $stats['max']['avg'] + $item['max']; - + //Get minimum if ($stats['max']['min'] == null) { $stats['max']['min'] = $item['max']; @@ -170,7 +168,7 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { else if ($item['max'] < $stats['max']['min']) { $stats['max']['min'] = $item['max']; } - + //Get maximum if ($stats['max']['max'] == null) { $stats['max']['max'] = $item['max']; @@ -179,55 +177,54 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { $stats['max']['max'] = $item['max']; } } - - + //Count elements $count++; - + //Get last data if ($count == $size) { if (isset($item['sum']) && $item['sum']) { $stats['sum']['last'] = $item['sum']; } - + if (isset($item['min']) && $item['min']) { $stats['min']['last'] = $item['min']; } - + if (isset($item['max']) && $item['max']) { $stats['max']['last'] = $item['max']; } } } - + //End the calculus for average if ($count > 0) { - + $stats['sum']['avg'] = $stats['sum']['avg'] / $count; $stats['min']['avg'] = $stats['min']['avg'] / $count; $stats['max']['avg'] = $stats['max']['avg'] / $count; } - + //Format stat data to display properly $stats['sum']['last'] = round($stats['sum']['last'], 2); $stats['sum']['avg'] = round($stats['sum']['avg'], 2); $stats['sum']['min'] = round($stats['sum']['min'], 2); $stats['sum']['max'] = round($stats['sum']['max'], 2); - + $stats['min']['last'] = round($stats['min']['last'], 2); $stats['min']['avg'] = round($stats['min']['avg'], 2); $stats['min']['min'] = round($stats['min']['min'], 2); $stats['min']['max'] = round($stats['min']['max'], 2); - + $stats['max']['last'] = round($stats['max']['last'], 2); $stats['max']['avg'] = round($stats['max']['avg'], 2); $stats['max']['min'] = round($stats['max']['min'], 2); $stats['max']['max'] = round($stats['max']['max'], 2); - + return $stats; } -function grafico_modulo_sparse_data_chart_new ( +function grafico_modulo_sparse_data_chart ( $agent_module_id, $date_array, $data_module_graph, @@ -238,18 +235,26 @@ function grafico_modulo_sparse_data_chart_new ( global $config; - $data = db_get_all_rows_filter ('tagente_datos', - array ('id_agente_modulo' => (int)$agent_module_id, - "utimestamp > '". $date_array['start_date']. "'", - "utimestamp < '". $date_array['final_date'] . "'", - 'order' => 'utimestamp ASC'), - array ('datos', 'utimestamp'), 'AND', $data_module_graph['history_db']); + $data = db_get_all_rows_filter ( + 'tagente_datos', + array ('id_agente_modulo' => (int)$agent_module_id, + "utimestamp > '". $date_array['start_date']. "'", + "utimestamp < '". $date_array['final_date'] . "'", + 'order' => 'utimestamp ASC'), + array ('datos', 'utimestamp'), + 'AND', + $data_module_graph['history_db'] + ); + + if($data === false){ + $data = array(); + } // Get previous data $previous_data = modules_get_previous_data ( - $agent_module_id, - $date_array['start_date'] - ); + $agent_module_id, + $date_array['start_date'] + ); if ($previous_data !== false) { $previous_data['utimestamp'] = $date_array['start_date']; @@ -259,9 +264,9 @@ function grafico_modulo_sparse_data_chart_new ( // Get next data $nextData = modules_get_next_data ( - $agent_module_id, - $date_array['final_date'] - ); + $agent_module_id, + $date_array['final_date'] + ); if ($nextData !== false) { unset($nextData['id_agente_modulo']); @@ -271,22 +276,17 @@ function grafico_modulo_sparse_data_chart_new ( // Propagate the last known data to the end of the interval $nextData = array( 'datos' => $data[count($data)-1]['datos'], - 'utimestamp' => $date_array['final_date'], + 'utimestamp' => $date_array['final_date'], ); array_push ($data, $nextData); } - - if ($data === false) { - $data = array (); - } - + // Check available data if (count ($data) < 1) { - //if (!$graphic_type) { - return fs_error_image (); - //} - //graphic_error (); + //return fs_error_image (); + return false; } + $array_data = array(); $min_value = PHP_INT_MAX-1; $max_value = PHP_INT_MIN+1; @@ -306,12 +306,12 @@ function grafico_modulo_sparse_data_chart_new ( $v['datos'] ); } - + //min if($min_value > $v['datos']){ $min_value = $v['datos']; } - + //max if($max_value < $v['datos']){ $max_value = $v['datos']; @@ -331,331 +331,25 @@ function grafico_modulo_sparse_data_chart_new ( $array_data["sum" . $series_suffix]['max'] = $max_value; $array_data["sum" . $series_suffix]['avg'] = $sum_data/$count_data; - if (!is_null($show_elements_graph['percentil']) && $show_elements_graph['percentil'] && !$show_elements_graph['flag_overlapped']) { + if (!is_null($show_elements_graph['percentil']) && + $show_elements_graph['percentil'] && + !$show_elements_graph['flag_overlapped']) { $percentil_result = get_percentile($show_elements_graph['percentil'], $array_percentil); $array_data["percentil" . $series_suffix]['data'][0] = array( - $date_array['start_date'] * 1000, + $date_array['start_date'] * 1000, $percentil_result ); $array_data["percentil" . $series_suffix]['data'][1] = array( - $date_array['final_date'] * 1000, + $date_array['final_date'] * 1000, $percentil_result ); } return $array_data; } - -function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_index, - $data, $data_i, $previous_data, $resolution, $interval, $period, $datelimit, - $projection, $avg_only = false, $uncompressed_module = false, - $show_events = false, $show_alerts = false, $show_unknown = false, $baseline = false, - $baseline_data = array(), $events = array(), $series_suffix = '', $start_unknown = false, - $percentil = null, $fullscale = false, $force_interval = false,$time_interval = 300, - $max_only = 0, $min_only = 0) { - global $config; - global $chart_extra_data; - global $series_type; - global $max_value; - global $min_value; - - $max_value = 0; - $min_value = null; - $flash_chart = $config['flash_charts']; - - // Event iterator - $event_i = 0; - - // Calculate chart data - $last_known = $previous_data; - - $first_events_unknown = $start_unknown; - - for ($i = 0; $i <= $resolution; $i++) { - $timestamp = $datelimit + ($interval * $i); - - $total = 0; - $count = 0; - - // Read data that falls in the current interval - $interval_min = false; - $interval_max = false; - - while (isset ($data[$data_i]) && $data[$data_i]['utimestamp'] >= $timestamp - && $data[$data_i]['utimestamp'] < ($timestamp + $interval)) { - if ($interval_min === false) { - $interval_min = $data[$data_i]['datos']; - } - if ($interval_max === false) { - $interval_max = $data[$data_i]['datos']; - } - - if ($data[$data_i]['datos'] > $interval_max) { - $interval_max = $data[$data_i]['datos']; - } - else if ($data[$data_i]['datos'] < $interval_min) { - $interval_min = $data[$data_i]['datos']; - } - - $total += $data[$data_i]['datos']; - $last_known = $data[$data_i]['datos']; - $count++; - $data_i++; - } - - if ($max_value < $interval_max) { - $max_value = $interval_max; - } - - if ($min_value > $interval_max || $min_value == null) { - $min_value = $interval_max; - } - - // Data in the interval - if ($count > 0) { - $total /= $count; - // If detect data, unknown period finishes - $is_unknown = false; - } - - // Read events and alerts that fall in the current interval - $event_value = 0; - $alert_value = 0; - $unknown_value = 0; - // Is the first point of a unknown interval - $check_unknown = false; - $first_unknown = false; - if($first_events_unknown){ - $is_unknown = true; - } - - $event_ids = array(); - $alert_ids = array(); - - while (isset ($events[$event_i]) && $events[$event_i]['utimestamp'] >= $timestamp - && $events[$event_i]['utimestamp'] <= ($timestamp + $interval)) { - if ($show_events == 1) { - $event_value++; - $event_ids[] = $events[$event_i]['id_evento']; - } - if ($show_alerts == 1 && substr ($events[$event_i]['event_type'], 0, 5) == 'alert') { - $alert_value++; - $alert_ids[] = $events[$event_i]['id_evento']; - } - if ($show_unknown) { - if ($events[$event_i]['event_type'] == 'going_unknown') { - if ($is_unknown == false) { - $first_unknown = true; - } - $is_unknown = true; - $check_unknown = true; - } - else if (substr ($events[$event_i]['event_type'], 0, 5) == 'going') { - $first_events_unknown = false; - $first_unknown = false; - $is_unknown = false; - } - } - $event_i++; - } - - // In some cases, can be marked as known because a recovery event - // was found in same interval. For this cases first_unknown is - // checked too - if ($is_unknown || $first_unknown) { - $unknown_value++; - } - - if (!$flash_chart) { - // Set the title and time format - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = "M \nd H:i"; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = "M \nd H\h"; - } - elseif ($period < SECONDS_6MONTHS) { - $time_format = "M \nd H\h"; - } - else { - $time_format = "Y M \nd H\h"; - } - } - else { - // Set the title and time format - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = "M d H:i"; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = "M d H\h"; - } - elseif ($period < SECONDS_6MONTHS) { - $time_format = "M d H\h"; - } - else { - $time_format = "Y M d H\h"; - } - } - - $timestamp_short = date($time_format, $timestamp); - $long_index[$timestamp_short] = date( - html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp); - if (!$projection) { - if (!$fullscale) { - //XXXXXX - //$timestamp = $timestamp_short; - } - } - - // Data - if ($show_events) { - if (!isset($chart[$timestamp]['event'.$series_suffix])) { - $chart[$timestamp]['event'.$series_suffix] = 0; - } - - $chart[$timestamp]['event'.$series_suffix] += $event_value; - $series_type['event'.$series_suffix] = 'points'; - } - if ($show_alerts) { - if (!isset($chart[$timestamp]['alert'.$series_suffix])) { - $chart[$timestamp]['alert'.$series_suffix] = 0; - } - - $chart[$timestamp]['alert'.$series_suffix] += $alert_value; - $series_type['alert'.$series_suffix] = 'points'; - } - - if ($count > 0) { - - if ($avg_only) { - $chart[$timestamp]['sum'.$series_suffix] = $total; - } - else if($max_only){ - $chart[$timestamp]['max'.$series_suffix] = $interval_max; - } - else if($min_only){ - $chart[$timestamp]['min'.$series_suffix] = $interval_min; - } - else{ - $chart[$timestamp]['max'.$series_suffix] = $interval_max; - $chart[$timestamp]['sum'.$series_suffix] = $total; - $chart[$timestamp]['min'.$series_suffix] = $interval_min; - } - // Compressed data - } - else { - if ($uncompressed_module || ($timestamp > time ())) { - if ($avg_only) { - $chart[$timestamp]['sum'.$series_suffix] = 0; - } - else if($max_only){ - $chart[$timestamp]['max'.$series_suffix] = 0; - } - else if($min_only){ - $chart[$timestamp]['min'.$series_suffix] = 0; - } - else{ - $chart[$timestamp]['max'.$series_suffix] = 0; - $chart[$timestamp]['sum'.$series_suffix] = 0; - $chart[$timestamp]['min'.$series_suffix] = 0; - } - } - else { - if ($avg_only) { - $chart[$timestamp]['sum'.$series_suffix] = $last_known; - } - else if ($max_only) { - $chart[$timestamp]['max'.$series_suffix] = $last_known; - } - else if ($min_only) { - $chart[$timestamp]['min'.$series_suffix] = $last_known; - } - else { - $chart[$timestamp]['max'.$series_suffix] = $last_known; - $chart[$timestamp]['sum'.$series_suffix] = $last_known; - $chart[$timestamp]['min'.$series_suffix] = $last_known; - } - } - } - - if ($uncompressed_module || ($timestamp > time ())) { - if (!isset($chart[$timestamp]['no_data'.$series_suffix])) { - $chart[$timestamp]['no_data'.$series_suffix] = 0; - } - if ($chart[$timestamp]['sum'.$series_suffix] == $last_known) { - $chart[$timestamp]['no_data'.$series_suffix] = 0; - $series_type['no_data'.$series_suffix] = 'area'; - } - else { - if($uncompressed_module){ - $chart[$timestamp]['sum'.$series_suffix] = $last_known; - $series_type['sum'.$series_suffix] = 'area'; - } - else{ - $chart[$timestamp]['no_data'.$series_suffix] = $last_known; - $series_type['no_data'.$series_suffix] = 'area'; - } - } - } - - if ($show_unknown) { - if (!isset($chart[$timestamp]['unknown'.$series_suffix])) { - $chart[$timestamp]['unknown'.$series_suffix] = 0; - } - $chart[$timestamp]['unknown'.$series_suffix] = $unknown_value; - - if($unknown_value == 0 && $check_unknown == true){ - $chart[$timestamp]['unknown'.$series_suffix] = 1; - $check_unknown = false; - } - - $series_type['unknown'.$series_suffix] = 'unknown'; - } - - if (!empty($event_ids)) { - $chart_extra_data[count($chart)-1]['events'] = implode(',',$event_ids); - } - if (!empty($alert_ids)) { - $chart_extra_data[count($chart)-1]['alerts'] = implode(',',$alert_ids); - } - } - - //min paint graph 2 elements - if(count($chart) == 1){ - $timestamp_short = date($time_format, $date_limit); - foreach($chart as $key => $value){ - $chart[$timestamp_short] = $value; - } - } - - if (!is_null($percentil) && $percentil) { - $avg = array_map(function($item) { return $item['sum'];}, $chart); - - $percentil_result = get_percentile($percentil, $avg); - - //Fill the data of chart - array_walk($chart, function(&$item) use ($percentil_result, $series_suffix) { - $item['percentil' . $series_suffix] = $percentil_result; }); - $series_type['percentil' . $series_suffix] = 'line'; - } -} - - -function grafico_modulo_sparse_data_new( - $agent_module_id, $date_array, - $data_module_graph, $show_elements_graph, +function grafico_modulo_sparse_data( + $agent_module_id, $date_array, + $data_module_graph, $show_elements_graph, $format_graph, $exception_interval_graph, $series_suffix, $str_series_suffix) { @@ -667,7 +361,7 @@ function grafico_modulo_sparse_data_new( global $series_type; if($show_elements_graph['fullscale']){ - $array_data = fullscale_data_new( + $array_data = fullscale_data( $agent_module_id, $date_array, $show_elements_graph['show_unknown'], @@ -678,16 +372,20 @@ function grafico_modulo_sparse_data_new( ); } else{ - $array_data = grafico_modulo_sparse_data_chart_new ( + $array_data = grafico_modulo_sparse_data_chart ( $agent_module_id, $date_array, $data_module_graph, $show_elements_graph, - $format_graph, + $format_graph, $series_suffix ); } + if($array_data === false){ + return false; + } + if($show_elements_graph['percentil']){ $percentil_value = $array_data['percentil' . $series_suffix]['data'][0][1]; } @@ -703,7 +401,6 @@ function grafico_modulo_sparse_data_new( } if(!$show_elements_graph['flag_overlapped']){ - if($show_elements_graph['fullscale']){ if( $show_elements_graph['show_unknown'] && isset($array_data['unknown' . $series_suffix]) && @@ -718,45 +415,46 @@ function grafico_modulo_sparse_data_new( else{ if( $show_elements_graph['show_unknown'] ) { $unknown_events = db_get_module_ranges_unknown( - $agent_module_id, - $date_array['start_date'], - $date_array['final_date'], - $data_module_graph['history_db'] + $agent_module_id, + $date_array['start_date'], + $date_array['final_date'], + $data_module_graph['history_db'], + 1 // fix the time ranges to start_date - final_date ); if($unknown_events !== false){ foreach ($unknown_events as $key => $s_date) { - if( isset($s_date['time_from']) ){ - $array_data['unknown' . $series_suffix]['data'][] = array( + if( isset($s_date['time_from'])) { + $array_data['unknown' . $series_suffix]['data'][] = array( ($s_date['time_from'] - 1) * 1000, 0 ); - - $array_data['unknown' . $series_suffix]['data'][] = array( + + $array_data['unknown' . $series_suffix]['data'][] = array( $s_date['time_from'] * 1000, $max * 1.05 ); } else{ - $array_data['unknown' . $series_suffix]['data'][] = array( + $array_data['unknown' . $series_suffix]['data'][] = array( $date_array['start_date'] * 1000, $max * 1.05 ); } - + if( isset($s_date['time_to']) ){ $array_data['unknown' . $series_suffix]['data'][] = array( $s_date['time_to'] * 1000, $max * 1.05 ); - - $array_data['unknown' . $series_suffix]['data'][] = array( + + $array_data['unknown' . $series_suffix]['data'][] = array( ($s_date['time_to'] + 1) * 1000, 0 ); } else{ - $array_data['unknown' . $series_suffix]['data'][] = array( + $array_data['unknown' . $series_suffix]['data'][] = array( $date_array['final_date'] * 1000, $max * 1.05 ); @@ -765,10 +463,10 @@ function grafico_modulo_sparse_data_new( } } } - - if ($show_elements_graph['show_events'] || + + if ($show_elements_graph['show_events'] || $show_elements_graph['show_alerts'] ) { - + $events = db_get_all_rows_filter ( 'tevento', array ('id_agentmodule' => $agent_module_id, @@ -776,7 +474,7 @@ function grafico_modulo_sparse_data_new( "utimestamp < " . $date_array['final_date'], 'order' => 'utimestamp ASC' ), - false, + false, 'AND', $data_module_graph['history_db'] ); @@ -807,7 +505,7 @@ function grafico_modulo_sparse_data_new( } } } - + if($show_elements_graph['show_events']){ $array_data['event' . $series_suffix] = $events_array; } @@ -820,7 +518,7 @@ function grafico_modulo_sparse_data_new( if ($show_elements_graph['return_data'] == 1) { return $array_data; } - + // Only show caption if graph is not small if ($width > MIN_WIDTH_CAPTION && $height > MIN_HEIGHT){ //Flash chart @@ -857,355 +555,18 @@ function grafico_modulo_sparse_data_new( $series_type['event'.$series_suffix] = 'points'; $series_type['alert'.$series_suffix] = 'points'; $series_type['unknown'.$series_suffix] = 'unknown'; - if($boolean_graph){ - $series_type['sum'.$series_suffix] = 'boolean'; - } - else{ - $series_type['sum'.$series_suffix] = 'area'; + switch ($data_module_graph['id_module_type']) { + case 21: case 2: case 6: + case 18: case 9: case 31: + $series_type['sum'.$series_suffix] = 'boolean'; + break; + default: + $series_type['sum'.$series_suffix] = 'area'; + break; } $series_type['percentil' . $series_suffix] = 'percentil'; } -function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, - $width, $height , $title = '', $unit_name = null, - $show_alerts = false, $avg_only = 0, $date = 0, $unit = '', - $baseline = 0, $return_data = 0, $show_title = true, $projection = false, - $adapt_key = '', $compare = false, $series_suffix = '', $series_suffix_str = '', - $show_unknown = false, $percentil = null, $dashboard = false, $vconsole = false, - $type_graph='area', $fullscale = false, $flash_chart = false, $force_interval = false,$time_interval = 300, - $max_only = 0, $min_only = 0) { - - global $config; - global $chart; - global $color; - global $legend; - global $long_index; - global $series_type; - global $chart_extra_data; - global $warning_min; - global $critical_min; - global $graphic_type; - global $max_value; - global $min_value; - - $chart = array(); - $color = array(); - $legend = array(); - $long_index = array(); - $warning_min = 0; - $critical_min = 0; - $start_unknown = false; - - // Set variables - if ($date == 0) { - $date = get_system_time(); - } - - $datelimit = $date - $period; - - - $search_in_history_db = db_search_in_history_db($datelimit); - - if($force_interval){ - $resolution = $period/$time_interval; - } - else{ - $resolution = $config['graph_res'] * 50; //Number of points of the graph - } - - if($force_interval){ - $interval = $time_interval; - } - else{ - $interval = (int) ($period / $resolution); - - } - - $agent_name = modules_get_agentmodule_agent_name ($agent_module_id); - $agent_id = agents_get_agent_id ($agent_name); - $module_name = modules_get_agentmodule_name ($agent_module_id); - $id_module_type = modules_get_agentmodule_type ($agent_module_id); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - if ($uncompressed_module) { - $avg_only = 1; - } - - $flash_chart = $config['flash_charts']; - - - // Get event data (contains alert data too) - $events = array(); - if ($show_unknown == 1 || $show_events == 1 || $show_alerts == 1) { - $events = db_get_all_rows_filter ( - 'tevento', - array ('id_agentmodule' => $agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('id_evento', 'evento', 'utimestamp', 'event_type'), - 'AND', - $search_in_history_db - ); - - // Get the last event after inverval to know if graph start on unknown - $prev_event = db_get_row_filter ( - 'tevento', - array ('id_agentmodule' => $agent_module_id, - "utimestamp <= $datelimit", - 'order' => 'utimestamp DESC' - ), - false, - 'AND', - $search_in_history_db - ); - - if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { - $start_unknown = true; - } - - if ($events === false) { - $events = array (); - } - } - - // Get module data - if ($fullscale) { - fullscale_data( $chart, $chart_data_extra, $long_index, $series_type, - $agent_module_id, $datelimit, $date, $events, - $show_events, $show_unknown, $show_alerts, - $series_suffix, $percentil, $flash_chart, false); - if (count($chart) > $resolution) { - $resolution = count($chart); //Number of points of the graph - $interval = (int) ($period / $resolution); - } - } - else { - $data = db_get_all_rows_filter ('tagente_datos', - array ('id_agente_modulo' => (int)$agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('datos', 'utimestamp'), 'AND', $search_in_history_db); - - if ($data === false) { - $data = array (); - } - - if ($uncompressed_module) { - // Uncompressed module data - $min_necessary = 1; - } - else { - // Compressed module data - - // Get previous data - $previous_data = modules_get_previous_data ($agent_module_id, $datelimit); - if ($previous_data !== false) { - $previous_data['utimestamp'] = $datelimit; - array_unshift ($data, $previous_data); - } - - // Get next data - $nextData = modules_get_next_data ($agent_module_id, $date); - if ($nextData !== false) { - array_push ($data, $nextData); - } - else if (count ($data) > 0) { - // Propagate the last known data to the end of the interval - $nextData = array_pop ($data); - array_push ($data, $nextData); - $nextData['utimestamp'] = $date; - array_push ($data, $nextData); - } - $min_necessary = 2; - } - - // Check available data - if (count ($data) < $min_necessary) { - if (!$graphic_type) { - if (!$projection) { - return fs_error_image (); - } - else { - return fs_error_image (); - } - } - graphic_error (); - } - - // Data iterator - $data_i = 0; - - // Set initial conditions - if ($data[0]['utimestamp'] == $datelimit) { - $previous_data = $data[0]['datos']; - $data_i++; - } - else { - $previous_data = 0; - } - } - // Get baseline data - $baseline_data = array(); - if ($baseline) { - $baseline_data = array (); - if ($baseline == 1) { - $baseline_data = enterprise_hook( - 'reporting_enterprise_get_baseline', - array ($agent_module_id, $period, $width, $height , $title, $unit_name, $date)); - if ($baseline_data === ENTERPRISE_NOT_HOOK) { - $baseline_data = array (); - } - } - } - - if (empty($unit)) { - $unit = modules_get_unit($agent_module_id); - if(modules_is_unit_macro($unit)){ - $unit = ""; - } - } - - // Get module warning_min and critical_min - $warning_min = db_get_value('min_warning','tagente_modulo','id_agente_modulo',$agent_module_id); - $critical_min = db_get_value('min_critical','tagente_modulo','id_agente_modulo',$agent_module_id); - - // Calculate chart data - if($fullscale){ - $avg_only = 1; - - //Percentil - if (!is_null($percentil) && $percentil) { - $avg = array_map(function($item) { return $item['sum'];}, $chart); - - $percentil_result = get_percentile($percentil, $avg); - - //Fill the data of chart - array_walk($chart, function(&$item) use ($percentil_result, $series_suffix) { - $item['percentil' . $series_suffix] = $percentil_result; }); - $series_type['percentil' . $series_suffix] = 'line'; - } - } - else{ - grafico_modulo_sparse_data_chart ($chart, $chart_data_extra, $long_index, - $data, $data_i, $previous_data, $resolution, $interval, $period, $datelimit, - $projection, $avg_only, $uncompressed_module, - $show_events, $show_alerts, $show_unknown, $baseline, - $baseline_data, $events, $series_suffix, $start_unknown, - $percentil, $fullscale, $force_interval, $time_interval, - $max_only, $min_only); - } - - // Return chart data and don't draw - if ($return_data == 1) { - return $chart; - } - - $graph_stats = get_statwin_graph_statistics($chart, $series_suffix); - - // Fix event and alert scale - if ($max_value > 0) { - $event_max = 2 + (float)$max_value * 1.05; - } - else { - $event_max = abs(($max_value+$min_value)/2); - if ($event_max < 5) { - $event_max = 5; - } - } - - foreach ($chart as $timestamp => $chart_data) { - if($chart_data['max'] > $event_max){ - $event_max = $chart_data['max']; - } - if ($show_events && $chart_data['event' . $series_suffix] > 0) { - $chart[$timestamp]['event' . $series_suffix] = $event_max * 1.2; - } - if ($show_alerts && $chart_data['alert' . $series_suffix] > 0) { - $chart[$timestamp]['alert' . $series_suffix] = $event_max * 1.10; - } - if ($show_unknown && $chart_data['unknown' . $series_suffix] > 0) { - $chart[$timestamp]['unknown' . $series_suffix] = $event_max * 1.05; - } - } - - // Only show caption if graph is not small - if ($width > MIN_WIDTH_CAPTION && $height > MIN_HEIGHT) - //Flash chart - $caption = - __('Max. Value') . $series_suffix_str . ': ' . $graph_stats['sum']['max'] . ' ' . - __('Avg. Value') . $series_suffix_str . ': ' . $graph_stats['sum']['avg'] . ' ' . - __('Min. Value') . $series_suffix_str . ': ' . $graph_stats['sum']['min'] . ' ' . - __('Units. Value') . $series_suffix_str . ': ' . $unit; - else - $caption = array(); - - $color = color_graph_array($series_suffix); - - if ($show_events) { - $legend['event'.$series_suffix_str] = __('Events').$series_suffix_str; - $chart_extra_data['legend_events'] = $legend['event'.$series_suffix_str]; - } - if ($show_alerts) { - $legend['alert'.$series_suffix] = __('Alerts').$series_suffix_str; - $chart_extra_data['legend_alerts'] = $legend['alert'.$series_suffix_str]; - } - - if ($vconsole) { - $legend['sum'.$series_suffix] = - __('Last') . ': ' . remove_right_zeros(number_format($graph_stats['sum']['last'], $config['graph_precision'])) . ($unit ? ' ' . $unit : '') . ' ; ' - . __('Avg') . ': ' . remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])) . ($unit ? ' ' . $unit : ''); - } - else if ($dashboard && !$avg_only) { - $legend['max'.$series_suffix] = __('Max').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['max']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['max']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['max']['min'], $config['graph_precision'])).' '.$unit; - $legend['sum'.$series_suffix] = __('Avg').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['sum']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['sum']['min'], $config['graph_precision'])).' '.$unit; - $legend['min'.$series_suffix] = __('Min').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['min']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['min']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['min']['min'], $config['graph_precision'])).' '.$unit; - } - else if ($dashboard) { - $legend['sum'.$series_suffix] = - __('Last') . ': ' . remove_right_zeros(number_format($graph_stats['sum']['last'], $config['graph_precision'])) . ($unit ? ' ' . $unit : '') . ' ; ' - . __('Avg') . ': ' . remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])) . ($unit ? ' ' . $unit : ''); - } - else if (!$avg_only && !$fullscale) { - $legend['max'.$series_suffix] = __('Max').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['max']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['max']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['max']['min'], $config['graph_precision'])).' '.$unit; - $legend['sum'.$series_suffix] = __('Avg').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['sum']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['sum']['min'], $config['graph_precision'])).' '.$unit; - $legend['min'.$series_suffix] = __('Min').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['min']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['min']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['min']['min'], $config['graph_precision'])).' '.$unit; - } - else if ($fullscale){ - $legend['sum'.$series_suffix] = __('Data').$series_suffix_str.': '; - } - else { - $legend['sum'.$series_suffix] = __('Avg').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['sum']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['sum']['min'], $config['graph_precision'])).' '.$unit; - } - - if ($show_unknown) { - $legend['unknown'.$series_suffix] = __('Unknown').$series_suffix_str; - $chart_extra_data['legend_unknown'] = $legend['unknown'.$series_suffix_str]; - } - - if (!is_null($percentil) && $percentil) { - $first_data = reset($chart); - $percentil_value = format_for_graph($first_data['percentil'], 2); - - $legend['percentil'.$series_suffix] = __('Percentile %dº', $percentil) .$series_suffix_str . " (" . $percentil_value . " " . $unit . ") "; - $chart_extra_data['legend_percentil'] = $legend['percentil'.$series_suffix_str]; - } - - if($force_interval){ - $legend = array(); - if($avg_only){ - $legend['sum'.$series_suffix] = __('Avg'); - } - elseif ($max_only) { - $legend['min'.$series_suffix] = __('Max'); - } - elseif ($min_only) { - $legend['max'.$series_suffix] = __('Min'); - } - } -} - function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $width, $height , $title = '', $unit_name = null, $show_alerts = false, $avg_only = 0, $pure = false, $date = 0, @@ -1216,16 +577,9 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $dashboard = false, $vconsole = false, $type_graph = 'area', $fullscale = false, $id_widget_dashboard = false,$force_interval = 0,$time_interval = 300, $max_only = 0, $min_only = 0) { - + global $config; global $graphic_type; - - $flash_chart = $config['flash_charts']; - -//XXXX -$entra_por = 1; -if($flash_chart && $entra_por){ - global $array_data; global $caption; global $color; @@ -1237,9 +591,6 @@ if($flash_chart && $entra_por){ $color = array(); $legend = array(); $series_type = array(); - - //XXX aqui empieza la obtencion de datos: - //Es infernal la cantidad de parametros que se le mandan pasamos a un array para simplificar este proceso: //date start final period if($date == 0){ @@ -1251,18 +602,21 @@ if($flash_chart && $entra_por){ $date_array["final_date"] = $date; $date_array["start_date"] = $date - $period; - - $module_data = db_get_row_sql ('SELECT * FROM tagente_modulo WHERE id_agente_modulo = ' . $agent_module_id); + $module_data = db_get_row_sql ( + 'SELECT * FROM tagente_modulo + WHERE id_agente_modulo = ' . + $agent_module_id + ); $data_module_graph = array(); $data_module_graph['history_db'] = db_search_in_history_db($date_array["start_date"]); $data_module_graph['agent_name'] = modules_get_agentmodule_agent_name ($agent_module_id); - $data_module_graph['agent_id'] = $module_data['id_agente']; + $data_module_graph['agent_id'] = $module_data['id_agente']; $data_module_graph['module_name'] = $module_data['nombre']; - $data_module_graph['id_module_type'] = $module_data['id_tipo_modulo']; + $data_module_graph['id_module_type'] = $module_data['id_tipo_modulo']; $data_module_graph['module_type'] = modules_get_moduletype_name ($data_module_graph['id_module_type']); $data_module_graph['uncompressed'] = is_module_uncompressed ($data_module_graph['module_type']); - $data_module_graph['w_min'] = $module_data['min_warning']; + $data_module_graph['w_min'] = $module_data['min_warning']; $data_module_graph['w_max'] = $module_data['max_warning']; $data_module_graph['w_inv'] = $module_data['warning_inverse']; $data_module_graph['c_min'] = $module_data['min_critical']; @@ -1329,7 +683,9 @@ if($flash_chart && $entra_por){ $exception_interval_graph['time_interval'] = $time_interval; $exception_interval_graph['max_only'] = $max_only; $exception_interval_graph['min_only'] = $min_only; - + + $type_graph = $config['type_module_charts']; + if ($show_elements_graph['compare'] !== false) { $series_suffix = 2; $series_suffix_str = ' (' . __('Previous') . ')'; @@ -1337,15 +693,15 @@ if($flash_chart && $entra_por){ $date_array_prev['final_date'] = $date_array['start_date']; $date_array_prev['start_date'] = $date_array['start_date'] - $date_array['period']; $date_array_prev['period'] = $date_array['period']; - + if ($show_elements_graph['compare'] === 'overlapped') { $show_elements_graph['flag_overlapped'] = 1; } else{ $show_elements_graph['flag_overlapped'] = 0; } - - grafico_modulo_sparse_data_new( + + grafico_modulo_sparse_data( $agent_module_id, $date_array_prev, $data_module_graph, $show_elements_graph, $format_graph, $exception_interval_graph, @@ -1369,7 +725,7 @@ if($flash_chart && $entra_por){ $series_suffix_str = ''; $show_elements_graph['flag_overlapped'] = 0; - grafico_modulo_sparse_data_new( + grafico_modulo_sparse_data( $agent_module_id, $date_array, $data_module_graph, $show_elements_graph, $format_graph, $exception_interval_graph, @@ -1384,47 +740,23 @@ if($flash_chart && $entra_por){ } } - if (empty($array_data)) { - //XXXX - return graph_nodata_image($width, $height); - return ''; - } - //XXX - setup_watermark($water_mark, $water_mark_file, $water_mark_url); - + //esto lo tenia la bool + $water_mark = array( + 'file' => $config['homedir'] . "/images/logo_vertical_water.png", + 'url' => ui_get_full_url( + "/images/logo_vertical_water.png", + false, + false, + false + ) + ); + //esto la sparse + //setup_watermark($water_mark, $water_mark_file, $water_mark_url); + // Check available data if ($show_elements_graph['compare'] === 'separated') { - return flot_area_graph_new( - $agent_module_id, - $array_data, - $color, - $legend, - $series_type, - $date_array, - $data_module_graph, - $show_elements_graph, - $format_graph, - $water_mark, - $series_suffix_str - ) . - '
' - . - flot_area_graph_new( - $agent_module_id, - $array_data_prev, - $color, - $legend, - $series_type, - $date_array, - $data_module_graph, - $show_elements_graph, - $format_graph, - $water_mark, - $series_suffix_str - ); - } - else{ - return flot_area_graph_new( + if (!empty($array_data)) { + $return = area_graph( $agent_module_id, $array_data, $color, @@ -1437,11 +769,54 @@ if($flash_chart && $entra_por){ $water_mark, $series_suffix_str ); + } + else{ + $return = graph_nodata_image($width, $height); + } + $return .= '
'; + if (!empty($array_data_prev)) { + $return .= area_graph( + $agent_module_id, + $array_data_prev, + $color, + $legend, + $series_type, + $date_array, + $data_module_graph, + $show_elements_graph, + $format_graph, + $water_mark, + $series_suffix_str + ); + } + else{ + $return .= graph_nodata_image($width, $height); + } + } + else{ + if (!empty($array_data)) { + $return = area_graph( + $agent_module_id, + $array_data, + $color, + $legend, + $series_type, + $date_array, + $data_module_graph, + $show_elements_graph, + $format_graph, + $water_mark, + $series_suffix_str + ); + } + else{ + $return = graph_nodata_image($width, $height); + } } - -die(); -} +return $return; + +//de aki al final eliminar; enterprise_include_once("include/functions_reporting.php"); @@ -1460,7 +835,7 @@ die(); $series_suffix = '2'; $series_suffix_str = ' (' . __('Previous') . ')'; // Build the data of the previous period - + grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, $width, $height, $title, $unit_name, $show_alerts, $avg_only, $date-$period, $unit, $baseline, @@ -1615,7 +990,7 @@ die(); function graph_get_formatted_date($timestamp, $format1, $format2) { global $config; - + if ($config['flash_charts']) { $date = date("$format1 $format2", $timestamp); } @@ -1625,7 +1000,7 @@ function graph_get_formatted_date($timestamp, $format1, $format2) { $date .= "\n".date($format2, $timestamp); } } - + return $date; } @@ -2964,16 +2339,16 @@ function fullscale_data_combined($module_list, $period, $date, $flash_charts, $p foreach ($data_uncompress as $key_data => $value_data) { foreach ($value_data['data'] as $k => $v) { $real_date = $v['utimestamp']; - + if(!isset($v['datos'])){ - $v['datos'] = $previous_data; + $v['datos'] = $previous_data; } else{ - $previous_data = $v['datos']; + $previous_data = $v['datos']; } if (!is_null($percentil) && $percentil) { - $array_percentil[] = $v['datos']; + $array_percentil[] = $v['datos']; } $data_all[$real_date][$key_module] = $v['datos']; @@ -2981,11 +2356,11 @@ function fullscale_data_combined($module_list, $period, $date, $flash_charts, $p } if (!is_null($percentil) && $percentil) { - $percentil_value = get_percentile($config['percentil'], $array_percentil); - $percentil_result[$key_module] = array_fill (0, count($data_all), $percentil_value); - if(count($data_all) > $count_data_all){ - $count_data_all = count($data_all); - } + $percentil_value = get_percentile($config['percentil'], $array_percentil); + $percentil_result[$key_module] = array_fill (0, count($data_all), $percentil_value); + if(count($data_all) > $count_data_all){ + $count_data_all = count($data_all); + } } } @@ -3039,19 +2414,18 @@ function fullscale_data_combined($module_list, $period, $date, $flash_charts, $p function graphic_agentaccess ($id_agent, $width, $height, $period = 0, $return = false) { global $config; global $graphic_type; - - + $data = array (); - + $resolution = $config["graph_res"] * ($period * 2 / $width); // Number of "slices" we want in graph - + $interval = (int) ($period / $resolution); - $date = get_system_time (); + $date = get_system_time(); $datelimit = $date - $period; $periodtime = floor ($period / $interval); $time = array (); $data = array (); - + $empty_data = true; for ($i = 0; $i < $interval; $i++) { $bottom = $datelimit + ($periodtime * $i); @@ -3061,31 +2435,20 @@ function graphic_agentaccess ($id_agent, $width, $height, $period = 0, $return = else { $name = $bottom; } - + $top = $datelimit + ($periodtime * ($i + 1)); - switch ($config["dbtype"]) { - case "mysql": - case "postgresql": - $data[$name]['data'] = (int) db_get_value_filter ('COUNT(*)', - 'tagent_access', - array ('id_agent' => $id_agent, - 'utimestamp > '.$bottom, - 'utimestamp < '.$top)); - break; - case "oracle": - $data[$name]['data'] = (int) db_get_value_filter ('count(*)', - 'tagent_access', - array ('id_agent' => $id_agent, - 'utimestamp > '.$bottom, - 'utimestamp < '.$top)); - break; - } - + + $data[$name]['data'] = (int) db_get_value_filter ('COUNT(*)', + 'tagent_access', + array ('id_agent' => $id_agent, + 'utimestamp > '.$bottom, + 'utimestamp < '.$top)); + if ($data[$name]['data'] != 0) { $empty_data = false; } } - + if($config["fixed_graph"] == false){ $water_mark = array('file' => $config['homedir'] . "/images/logo_vertical_water.png", @@ -3096,12 +2459,13 @@ function graphic_agentaccess ($id_agent, $width, $height, $period = 0, $return = $out = graph_nodata_image($width, $height); } else { - $out = area_graph($config['flash_charts'], $data, $width, $height, null, null, null, + $out = area_graph( + $config['flash_charts'], $data, $width, $height, null, null, null, ui_get_full_url("images/image_problem_area_small.png", false, false, false), "", "", ui_get_full_url(false, false, false, false), $water_mark, $config['fontpath'], $config['font_size'], "", 1, array(), array(), 0, 0, '', false, '', false); } - + if ($return) { return $out; } @@ -3904,7 +3268,6 @@ function graphic_incident_group () { /** * Print a graph with access data of agents - * * @param integer id_agent Agent ID * @param integer width pie graph width * @param integer height pie graph height @@ -4706,7 +4069,7 @@ function graph_graphic_moduleevents ($id_agent, $id_module, $width, $height, $pe $out .= " "; } } - + if ($return) { return $out; } @@ -4718,446 +4081,20 @@ function graph_graphic_moduleevents ($id_agent, $id_module, $width, $height, $pe // Prints an error image function fs_error_image ($width = 300, $height = 110) { global $config; - return graph_nodata_image($width, $height, 'area'); } -function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, - $unit_name, $show_alerts, $avg_only = 0, - $date = 0, $series_suffix = '', $series_suffix_str = '', $show_unknown = false, - $fullscale = false, $flash_chart = true) { - - global $config; - global $chart; - global $color; - global $legend; - global $long_index; - global $series_type; - global $chart_extra_data; - - $chart = array(); - $color = array(); - $legend = array(); - $long_index = array(); - $start_unknown = false; - - // Set variables - if ($date == 0) $date = get_system_time(); - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - $resolution = $config['graph_res'] * 50; //Number of points of the graph - $interval = (float) ($period / $resolution); - $agent_name = modules_get_agentmodule_agent_name ($agent_module_id); - $agent_id = agents_get_agent_id ($agent_name); - $module_name = modules_get_agentmodule_name ($agent_module_id); - $id_module_type = modules_get_agentmodule_type ($agent_module_id); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - if ($uncompressed_module) { - $avg_only = 1; - } - - // Get event data (contains alert data too) - if ($show_unknown == 1 || $show_events == 1 || $show_alerts == 1) { - $events = db_get_all_rows_filter( - 'tevento', - array ('id_agentmodule' => $agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC' - ), - array ('evento', 'utimestamp', 'event_type', 'id_evento'), - 'AND', - $search_in_history_db - ); - - // Get the last event after inverval to know if graph start on unknown - $prev_event = db_get_row_filter ( - 'tevento', - array ('id_agentmodule' => $agent_module_id, - "utimestamp <= $datelimit", - 'order' => 'utimestamp DESC' - ), - false, - 'AND', - $search_in_history_db - ); - - if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { - $start_unknown = true; - } - - if ($events === false) { - $events = array (); - } - } - - if ($fullscale) { - fullscale_data( $chart, $chart_data_extra, $long_index, $series_type, - $agent_module_id, $datelimit, $date, $events, - $show_events, $show_unknown, $show_alerts, - $series_suffix, $percentil, $flash_chart,true); - if (count($chart) > $resolution) { - $resolution = count($chart); //Number of points of the graph - $interval = (int) ($period / $resolution); - } - $max_value=1; - } - else { - // Get module data - $data = db_get_all_rows_filter ('tagente_datos', - array ('id_agente_modulo' => $agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('datos', 'utimestamp'), 'AND', $search_in_history_db); - - - if ($data === false) { - $data = array (); - } - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($agent_module_id, $datelimit); - if ($previous_data !== false) { - $previous_data['utimestamp'] = $datelimit; - array_unshift ($data, $previous_data); - } - - // Get next data - $nextData = modules_get_next_data ($agent_module_id, $date); - if ($nextData !== false) { - array_push ($data, $nextData); - } - else if (count ($data) > 0) { - // Propagate the last known data to the end of the interval - $nextData = array_pop ($data); - array_push ($data, $nextData); - $nextData['utimestamp'] = $date; - array_push ($data, $nextData); - } - - $min_necessary = 2; - } - - // Check available data - if (count ($data) < $min_necessary) { - if (!$graphic_type) { - return fs_error_image (); - } - graphic_error (); - } - - // Data iterator - $j = 0; - - // Event iterator - $k = 0; - - // Set initial conditions - if ($data[0]['utimestamp'] == $datelimit) { - $previous_data = $data[0]['datos']; - $j++; - } - else { - $previous_data = 0; - } - - $max_value = 0; - // Calculate chart data - $last_known = $previous_data; - $first_events_unknown = $start_unknown; - - for ($i = 0; $i <= $resolution; $i++) { - $timestamp = $datelimit + ($interval * $i); - - - $zero = 0; - $total = 0; - $count = 0; - - // Read data that falls in the current interval - while (isset ($data[$j]) && - $data[$j]['utimestamp'] >= $timestamp && - $data[$j]['utimestamp'] <= ($timestamp + $interval)) { - if ($data[$j]['datos'] == 0) { - $zero = 1; - } - else { - $total += $data[$j]['datos']; - $count++; - } - - $last_known = $data[$j]['datos']; - - if ($show_unknown && $data[$j]['unknown']){ - $is_unknown = true; - } - $j++; - } - - // Average - if ($count > 0) { - $total /= $count; - } - - // Read events and alerts that fall in the current interval - $event_value = 0; - $alert_value = 0; - $unknown_value = 0; - // Is the first point of a unknown interval - $check_unknown = false; - $first_unknown = false; - if($first_events_unknown){ - $is_unknown = true; - } - - $event_ids = array(); - $alert_ids = array(); - while (isset ($events[$k]) && - $events[$k]['utimestamp'] >= $timestamp && - $events[$k]['utimestamp'] < ($timestamp + $interval)) { - if ($show_events == 1) { - $event_value++; - $event_ids[] = $events[$k]['id_evento']; - } - if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') { - $alert_value++; - $alert_ids[] = $events[$k]['id_evento']; - } - if ($show_unknown) { - if ($events[$k]['event_type'] == 'going_unknown') { - if ($is_unknown == false) { - $first_unknown = true; - } - $is_unknown = true; - $check_unknown = true; - } - else if (substr ($events[$k]['event_type'], 0, 5) == 'going') { - $first_events_unknown = false; - $first_unknown = false; - $is_unknown = false; - } - } - $k++; - } - - // In some cases, can be marked as known because a recovery event - // was found in same interval. For this cases first_unknown is - // checked too - if ($is_unknown || $first_unknown) { - $unknown_value++; - } - - // Set the title and time format - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = 'M d H:i'; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = 'M d H\h'; - } - else { - $time_format = 'M d H\h'; - } - - $timestamp_short = date($time_format, $timestamp); - $long_index[$timestamp_short] = date( - html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp); - if (!$fullscale) { - $timestamp = $timestamp_short; - } - ///////////////////////////////////////////////////////////////// - - if ($total > $max_value) { - $max_value = $total; - } - // Data - if ($show_events) { - if (!isset($chart[$timestamp]['event'.$series_suffix])) { - $chart[$timestamp]['event'.$series_suffix] = 0; - } - - $chart[$timestamp]['event'.$series_suffix] += $event_value; - $series_type['event'.$series_suffix] = 'points'; - } - if ($show_alerts) { - if (!isset($chart[$timestamp]['alert'.$series_suffix])) { - $chart[$timestamp]['alert'.$series_suffix] = 0; - } - - $chart[$timestamp]['alert'.$series_suffix] += $alert_value; - $series_type['alert'.$series_suffix] = 'points'; - } - - // Data and zeroes (draw a step) - if ($zero == 1 && $count > 0) { - $chart[$timestamp]['sum'.$series_suffix] = 0; - } - else if ($zero == 1) { // Just zeros - $chart[$timestamp]['sum'.$series_suffix] = 0; - } - else if ($count > 0) { // No zeros - $chart[$timestamp]['sum'.$series_suffix] = $total; - } - else { // Compressed data - if ($uncompressed_module || ($timestamp > time ()) || $is_unknown) { - $chart[$timestamp]['sum'.$series_suffix] = 0; - } - else { - $chart[$timestamp]['sum'.$series_suffix] = $last_known; - } - } - - $series_type['sum' . $series_suffix] = 'boolean'; - - if ($show_unknown) { - if (!isset($chart[$timestamp]['unknown'.$series_suffix])) { - $chart[$timestamp]['unknown'.$series_suffix] = 0; - } - $chart[$timestamp]['unknown'.$series_suffix] = $unknown_value; - - if($unknown_value == 0 && $check_unknown == true){ - $chart[$timestamp]['unknown'.$series_suffix] = 1; - $check_unknown = false; - } - - $series_type['unknown'.$series_suffix] = 'unknown'; - } - - if (!empty($event_ids)) { - $chart_extra_data[count($chart)-1]['events'] = implode(',',$event_ids); - } - if (!empty($alert_ids)) { - $chart_extra_data[count($chart)-1]['alerts'] = implode(',',$alert_ids); - } - } - } - - if (empty($unit_name)) { - $unit = modules_get_unit($agent_module_id); - } - else - $unit = $unit_name; - - // Get min, max and avg (less efficient but centralized for all modules and reports) - $graph_stats = get_statwin_graph_statistics($chart, $series_suffix); - - // Fix event and alert scale - $max_value = 1; - foreach ($chart as $timestamp => $chart_data) { - if ($show_events) { - if ($chart_data['event'.$series_suffix] > 0) { - $chart[$timestamp]['event'.$series_suffix] = $max_value * 1.2; - } - } - if ($show_alerts) { - if ($chart_data['alert'.$series_suffix] > 0) { - $chart[$timestamp]['alert'.$series_suffix] = $max_value * 1.10; - } - } - if ($show_unknown) { - if ($chart_data['unknown'.$series_suffix] > 0) { - $chart[$timestamp]['unknown'.$series_suffix] = $max_value * 1.05; - } - } - } - /////////////////////////////////////////////////// - if(!$fullscale){ - // Set the title and time format - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = 'M d H:i'; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = 'M d H\h'; - } - elseif ($period < SECONDS_6MONTHS) { - $time_format = "M d H\h"; - } - else { - $time_format = 'M d H\h'; - } - } - // Flash chart - $caption = __('Max. Value').$series_suffix_str . ': ' . $graph_stats['sum']['max'] . ' ' . __('Avg. Value').$series_suffix_str . - ': ' . $graph_stats['sum']['avg'] . ' ' . __('Min. Value').$series_suffix_str . ': ' . $graph_stats['sum']['min'] . ' ' . __('Units').$series_suffix_str . ': ' . $unit; - - ///////////////////////////////////////////////////////////////////////////////////////// - if ($show_events) { - $legend['event'.$series_suffix] = __('Events').$series_suffix_str; - $chart_extra_data['legend_events'] = $legend['event'.$series_suffix]; - } - if ($show_alerts) { - $legend['alert'.$series_suffix] = __('Alerts').$series_suffix_str; - $chart_extra_data['legend_alerts'] = $legend['alert'.$series_suffix]; - } - - if(!$fullscale){ - $legend['sum'.$series_suffix] = __('Avg').$series_suffix_str.': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['sum']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['sum']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['sum']['min'], $config['graph_precision'])).' '.$unit; - } - else{ - $legend['sum'.$series_suffix] = __('Data'); - } - - if ($show_unknown) { - $legend['unknown'.$series_suffix] = __('Unknown').$series_suffix_str; - $chart_extra_data['legend_unknown'] = $legend['unknown'.$series_suffix]; - } - //$legend['baseline'.$series_suffix] = __('Baseline').$series_suffix_str; - ///////////////////////////////////////////////////////////////////////////////////////// - if ($show_events) { - $color['event'.$series_suffix] = - array('border' => '#ff0000', 'color' => '#ff0000', - 'alpha' => CHART_DEFAULT_ALPHA); - } - if ($show_alerts) { - $color['alert'.$series_suffix] = - array('border' => '#ff7f00', 'color' => '#ff7f00', - 'alpha' => CHART_DEFAULT_ALPHA); - } - $color['max'.$series_suffix] = - array('border' => '#000000', 'color' => $config['graph_color3'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color['sum'.$series_suffix] = - array('border' => '#000000', 'color' => $config['graph_color2'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color['min'.$series_suffix] = - array('border' => '#000000', 'color' => $config['graph_color1'], - 'alpha' => CHART_DEFAULT_ALPHA); - if ($show_unknown) { - $color['unknown'.$series_suffix] = - array('border' => '#999999', 'color' => '#999999', - 'alpha' => CHART_DEFAULT_ALPHA); - } -} - -function fullscale_data_new ( - $agent_module_id, $date_array, - $show_unknown = 0, $show_percentil = 0, +function fullscale_data ( + $agent_module_id, $date_array, + $show_unknown = 0, $show_percentil = 0, $series_suffix, $str_series_suffix = '', $compare = false){ global $config; - $data_uncompress = + $data_uncompress = db_uncompress_module_data( - $agent_module_id, - $date_array['start_date'], + $agent_module_id, + $date_array['start_date'], $date_array['final_date'] ); @@ -5176,7 +4113,7 @@ function fullscale_data_new ( $real_date = ($v['utimestamp'] + $date_array['period']) * 1000; } else{ - $real_date = $v['utimestamp'] * 1000; + $real_date = $v['utimestamp'] * 1000; } if ($v["datos"] === NULL) { @@ -5194,13 +4131,6 @@ function fullscale_data_new ( $data["sum" . $series_suffix]['data'][] = array($real_date , $previous_data); } - /* - elseif($v["datos"] === false) { - // Not Init - $previous_data = $v["datos"]; - $data[$real_date]["sum" . $series_suffix] = $v["datos"]; - } - */ else { //normal $previous_data = $v["datos"]; @@ -5229,7 +4159,7 @@ function fullscale_data_new ( $count_data++; if($show_percentil && !$compare){ - $array_percentil[] = $v["datos"]; + $array_percentil[] = $v["datos"]; } $last_data = $v["datos"]; @@ -5239,22 +4169,40 @@ function fullscale_data_new ( if($show_percentil && !$compare){ $percentil_result = get_percentile($show_percentil, $array_percentil); if($compare){ - $data["percentil" . $series_suffix]['data'][] = array( ($date_array['start_date'] + $date_array['period']) * 1000 , $percentil_result); - $data["percentil" . $series_suffix]['data'][] = array( ($date_array['final_date'] + $date_array['period']) * 1000 , $percentil_result); + $data["percentil" . $series_suffix]['data'][] = array( + ($date_array['start_date'] + $date_array['period']) * 1000, + $percentil_result + ); + $data["percentil" . $series_suffix]['data'][] = array( + ($date_array['final_date'] + $date_array['period']) * 1000, + $percentil_result + ); } else{ - $data["percentil" . $series_suffix]['data'][] = array($date_array['start_date'] * 1000 , $percentil_result); - $data["percentil" . $series_suffix]['data'][] = array($date_array['final_date'] * 1000 , $percentil_result); + $data["percentil" . $series_suffix]['data'][] = array( + $date_array['start_date'] * 1000, + $percentil_result + ); + $data["percentil" . $series_suffix]['data'][] = array( + $date_array['final_date'] * 1000, + $percentil_result + ); } } // Add missed last data if($compare){ - $data["sum" . $series_suffix]['data'][] = array( ($date_array['final_date'] + $date_array['period']) * 1000 , $last_data); + $data["sum" . $series_suffix]['data'][] = array( + ($date_array['final_date'] + $date_array['period']) * 1000, + $last_data + ); } else{ - $data["sum" . $series_suffix]['data'][] = array($date_array['final_date'] * 1000 , $last_data); + $data["sum" . $series_suffix]['data'][] = array( + $date_array['final_date'] * 1000, + $last_data + ); } - + $data["sum" . $series_suffix]['min'] = $min_value; $data["sum" . $series_suffix]['max'] = $max_value; $data["sum" . $series_suffix]['avg'] = $sum_data/$count_data; @@ -5262,316 +4210,18 @@ function fullscale_data_new ( return $data; } -function fullscale_data ( &$chart_data, &$chart_extra_data, &$long_index, - $series_type, $agent_module_id, $datelimit, $date, - $events = false, $show_events = false, - $show_unknown = false, $show_alerts = false, - $series_suffix = '', $percentil = false, - $flash_chart = true, $boolean_graph = false){ - - global $config; - global $max_value; - global $min_value; - global $series_type; - global $chart_extra_data; - - $first_data = 0; - - $data_uncompress = db_uncompress_module_data($agent_module_id, $datelimit, $date); - - $chart_data = array(); - $flag_unknown = 0; - - $min_value = PHP_INT_MAX-1; - $max_value = PHP_INT_MIN+1; - $previous_data = $first_data; - $previous_unknown = 0; - - $i=0; - $current_event = $events[0]; - - foreach ($data_uncompress as $k) { - foreach ($k["data"] as $v) { - if (isset($v["type"]) && $v["type"] == 1) { # skip unnecesary virtual data - continue; - } - $real_date = $v['utimestamp']; - - if(!$flash_chart){ - $real_date = date("Y/M/d", $v['utimestamp']); - $real_date .= "\n"; - $real_date .= date(" H:i:s", $v['utimestamp']); - } - - $event_ids = array(); - $alert_ids = array(); - while (isset($current_event) && ($v['utimestamp'] >= $current_event["utimestamp"]) ) { - $event_date = $current_event['utimestamp']; - if(!$flash_chart){ - $event_date = date("Y/M/d", $current_event['utimestamp']); - $event_date .= "\n"; - $event_date .= date(" H:i:s", $current_event['utimestamp']); - } - - if ($show_events && (strpos($current_event["event_type"], "going") !== false)) { - $event_ids[$event_date][] = $current_event["id_evento"]; - - $chart_data[$event_date]["event" . $series_suffix] = 1; - $chart_data[$event_date]["alert" . $series_suffix] = NULL; - $chart_extra_data[count($chart_data)-1]['events'] = implode (',', $event_ids[$event_date]); - } - elseif ($show_alerts && (strpos($current_event["event_type"], "alert") !== false)) { - $alert_ids[$event_date][] = $current_event["id_evento"]; - - $chart_data[$event_date]["event" . $series_suffix] = NULL; - $chart_data[$event_date]["alert" . $series_suffix] = 1; - $chart_extra_data[count($chart_data)-1]['alerts'] = implode (',', $alert_ids[$event_date]); - } - else{ - $chart_data[$event_date]["event" . $series_suffix] = NULL; - $chart_data[$event_date]["alert" . $series_suffix] = NULL; - } - - $chart_data[$event_date]["sum" . $series_suffix] = $previous_data; - if($show_unknown) { - $chart_data[$event_date]["unknown" . $series_suffix] = $previous_unknown; - } - $current_event = $events[$i++]; - } - - if ($v["datos"] === NULL) { - // Unknown - if (!isset($chart_data[$real_date]["event" . $series_suffix])) { - if($show_events) { - $chart_data[$real_date]["event" . $series_suffix] = NULL; - } - if($show_alerts) { - $chart_data[$real_date]["alert" . $series_suffix] = NULL; - } - } - - $chart_data[$real_date]["sum" . $series_suffix] = $previous_data; - if($show_unknown) { - $chart_data[$real_date]["unknown" . $series_suffix] = "1"; - } - $previous_unknown = "1"; - } - elseif($v["datos"] === false) { - // Not Init - $previous_data = $v["datos"]; - if (!isset($chart_data[$real_date]["event" . $series_suffix])) { - if ($show_events) { - $chart_data[$real_date]["event" . $series_suffix] = NULL; - } - if ($show_alerts) { - $chart_data[$real_date]["alert" . $series_suffix] = NULL; - } - } - - $chart_data[$real_date]["sum" . $series_suffix] = $v["datos"]; - - if($v['datos'] >= $max_value){ - $max_value = $v['datos']; - } - - if($v['datos'] <= $min_value){ - $min_value = $v['datos']; - } - - if($show_unknown) { - $chart_data[$real_date]["unknown" . $series_suffix] = NULL; - $previous_unknown = NULL; - } - } - else { - $previous_data = $v["datos"]; - if (!isset($chart_data[$real_date]["event" . $series_suffix])) { - if ($show_events) { - $chart_data[$real_date]["event" . $series_suffix] = NULL; - } - if ($show_alerts) { - $chart_data[$real_date]["alert" . $series_suffix] = NULL; - } - } - - $chart_data[$real_date]["sum" . $series_suffix] = $v["datos"]; - - if($v['datos'] >= $max_value){ - $max_value = $v['datos']; - } - - if($v['datos'] <= $min_value){ - $min_value = $v['datos']; - } - - if($show_unknown) { - $chart_data[$real_date]["unknown" . $series_suffix] = NULL; - $previous_unknown = NULL; - } - } - $last_data = $v["datos"]; - } - } - $series_type['event'.$series_suffix] = 'points'; - $series_type['alert'.$series_suffix] = 'points'; - $series_type['unknown'.$series_suffix] = 'unknown'; - - // Add missed last data - $chart_data[$date]["sum" . $series_suffix] = $last_data; - - if($boolean_graph){ - $series_type['sum'.$series_suffix] = 'boolean'; - } - else{ - $series_type['sum'.$series_suffix] = 'area'; - } -} - -function grafico_modulo_boolean ($agent_module_id, $period, $show_events, - $width, $height , $title='', $unit_name, $show_alerts, $avg_only = 0, $pure=0, - $date = 0, $only_image = false, $homeurl = '', $adapt_key = '', $compare = false, - $show_unknown = false, $menu = true, $fullscale = false) { - - global $config; - global $graphic_type; - - $flash_chart = $config['flash_charts']; - - global $chart; - global $color; - global $color_prev; - global $legend; - global $long_index; - global $series_type; - global $chart_extra_data; - - if (empty($unit_name)) { - $unit = modules_get_unit($agent_module_id); - } - else - $unit = $unit_name; - - $series_suffix_str = ''; - if ($compare !== false) { - $series_suffix = '2'; - $series_suffix_str = ' (' . __('Previous') . ')'; - // Build the data of the previous period - grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, - $unit_name, $show_alerts, $avg_only, $date-$period, $series_suffix, - $series_suffix_str, $show_unknown, $fullscale, $flash_chart); - switch ($compare) { - case 'separated': - // Store the chart calculated - $chart_prev = $chart; - $legend_prev = $legend; - $long_index_prev = $long_index; - $series_type_prev = $series_type; - $chart_extra_data_prev = $chart_extra_data; - $chart_extra_data = array(); - $color_prev = $color; - break; - case 'overlapped': - // Store the chart calculated deleting index, because will be over the current period - $chart_prev = array_values($chart); - $legend_prev = $legend; - $series_type_prev = $series_type; - $color_prev = $color; - foreach ($color_prev as $k => $col) { - $color_prev[$k]['color'] = '#' . get_complementary_rgb($color_prev[$k]['color']); - } - break; - } - } - - grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, - $unit_name, $show_alerts, $avg_only, $date, '', '', $show_unknown, $fullscale, $flash_chart); - - - if ($compare === 'overlapped') { - $i = 0; - foreach($chart as $k => $v) { - $chart[$k] = array_merge($v, $chart_prev[$i]); - $i++; - } - - $legend = array_merge($legend, $legend_prev); - $color = array_merge($color, $color_prev); - } - - if ($only_image) { - $flash_chart = false; - } - - $water_mark = array( - 'file' => $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("/images/logo_vertical_water.png", - false, false, false)); - $type_graph = $config['type_module_charts']; - - if ($type_graph === 'area') { - if ($compare === 'separated') { - return area_graph($flash_chart, $chart, $width, $height/2, $color, $legend, - $long_index, ui_get_full_url("images/image_problem_area_small.png", false, false, false), - "", $unit, $homeurl, $water_mark, - $config['fontpath'], $config['font_size'], $unit, 1, $series_type, - $chart_extra_data, 0, 0, $adapt_key, false, $series_suffix_str, $menu). - '
'. - area_graph($flash_chart, $chart_prev, $width, $height/2, $color_prev, $legend_prev, - $long_index_prev, ui_get_full_url("images/image_problem_area_small.png", false, false, false), - "", $unit, $homeurl, $water_mark, - $config['fontpath'], $config['font_size'], $unit, 1, $series_type_prev, - $chart_extra_data_prev, 0, 0, $adapt_key, false, $series_suffix_str, $menu); - } - else { - return area_graph($flash_chart, $chart, $width, $height, $color, $legend, - $long_index, ui_get_full_url("images/image_problem_area_small.png", false, false, false), - $title, $unit, $homeurl, $water_mark, - $config['fontpath'], $config['font_size'], $unit, 1, $series_type, - $chart_extra_data, 0, 0, $adapt_key, false, $series_suffix_str, $menu); - } - } - elseif ($type_graph === 'line') { - if ($compare === 'separated') { - return - line_graph($flash_chart, $chart, $width, $height/2, $color, - $legend, $long_index, - ui_get_full_url("images/image_problem_area_small.png", false, false, false), - "", $unit, $water_mark, $config['fontpath'], - $config['font_size'], $unit, $ttl, $homeurl, $backgroundColor). - '
'. - line_graph($flash_chart, $chart_prev, $width, $height/2, $color, - $legend, $long_index, - ui_get_full_url("images/image_problem_area_small.png", false, false, false), - "", $unit, $water_mark, $config['fontpath'], - $config['font_size'], $unit, $ttl, $homeurl, $backgroundColor); - } - else { - // Color commented not to restrict serie colors - return - line_graph($flash_chart, $chart, $width, $height, $color, - $legend, $long_index, - ui_get_full_url("images/image_problem_area_small.png", false, false, false), - $title, $unit, $water_mark, $config['fontpath'], - $config['font_size'], $unit, $ttl, $homeurl, $backgroundColor); - } - } -} - - /** * Print an area graph with netflow aggregated */ - function graph_netflow_aggregate_area ($data, $period, $width, $height, $unit = '', $ttl = 1, $only_image = false) { global $config; global $graphic_type; - + if (empty ($data)) { echo fs_error_image (); return; } - - + if ($period <= SECONDS_6HOURS) { $chart_time_format = 'H:i:s'; } @@ -5678,17 +4328,14 @@ function graph_netflow_aggregate_area ($data, $period, $width, $height, $unit = $color[15] = array('border' => '#000000', 'color' => COL_GRAPH13, 'alpha' => CHART_DEFAULT_ALPHA); - - - return area_graph($flash_chart, $chart, $width, $height, $color, + + return area_graph($flash_chart, $chart, $width, $height, $color, $sources, array (), ui_get_full_url("images/image_problem_area_small.png", false, false, false), "", $unit, $homeurl, $config['homedir'] . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], $unit, $ttl); } - - /** * Print an area graph with netflow total */ @@ -5842,312 +4489,6 @@ function graph_netflow_host_traffic ($data, $unit, $width = 700, $height = 700) return d3_tree_map_graph ($data, $width, $height, true); } -/** - * Draw a graph of Module string data of agent - * - * @param integer id_agent_modulo Agent Module ID - * @param integer show_event show event (1 or 0) - * @param integer height graph height - * @param integer width graph width - * @param string title graph title - * @param string unit_name String of unit name - * @param integer show alerts (1 or 0) - * @param integer avg_only calcules avg only (1 or 0) - * @param integer pure Fullscreen (1 or 0) - * @param integer date date - */ -function grafico_modulo_string ($agent_module_id, $period, $show_events, - $width, $height, $title, $unit_name, $show_alerts, $avg_only = 0, $pure = 0, - $date = 0, $only_image = false, $homeurl = '', $adapt_key = '', $ttl = 1, $menu = true) { - global $config; - global $graphic_type; - global $max_value; - - - // Set variables - if ($date == 0) - $date = get_system_time(); - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - $resolution = $config['graph_res'] * 50; //Number of points of the graph - $interval = (int) ($period / $resolution); - $agent_name = modules_get_agentmodule_agent_name ($agent_module_id); - $agent_id = agents_get_agent_id ($agent_name); - $module_name = modules_get_agentmodule_name ($agent_module_id); - $id_module_type = modules_get_agentmodule_type ($agent_module_id); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - if ($uncompressed_module) { - $avg_only = 1; - } - $search_in_history_db = db_search_in_history_db($datelimit); - - // Get event data (contains alert data too) - if ($show_events == 1 || $show_alerts == 1) { - $events = db_get_all_rows_filter ('tevento', - array ('id_agentmodule' => $agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('evento', 'utimestamp', 'event_type')); - if ($events === false) { - $events = array (); - } - } - - // Get module data - $data = db_get_all_rows_filter ('tagente_datos_string', - array ('id_agente_modulo' => $agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('datos', 'utimestamp'), 'AND', $search_in_history_db); - if ($data === false) { - $data = array (); - } - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - } - else { - // Compressed module data - - // Get previous data - $previous_data = modules_get_previous_data ($agent_module_id, $datelimit, 1); - if ($previous_data !== false) { - $previous_data['utimestamp'] = $datelimit; - array_unshift ($data, $previous_data); - } - - // Get next data - $nextData = modules_get_next_data ($agent_module_id, $date, 1); - if ($nextData !== false) { - array_push ($data, $nextData); - } - else if (count ($data) > 0) { - // Propagate the last known data to the end of the interval - $nextData = array_pop ($data); - array_push ($data, $nextData); - $nextData['utimestamp'] = $date; - array_push ($data, $nextData); - } - - $min_necessary = 2; - } - - // Check available data - if (count ($data) < $min_necessary) { - if (!$graphic_type) { - return fs_error_image ($width, $height); - } - graphic_error (); - } - - // Data iterator - $j = 0; - - // Event iterator - $k = 0; - - // Set initial conditions - $chart = array(); - if ($data[0]['utimestamp'] == $datelimit) { - $previous_data = 1; - $j++; - } - else { - $previous_data = 0; - } - - // Calculate chart data - $last_known = $previous_data; - for ($i = 0; $i < $resolution; $i++) { - $timestamp = $datelimit + ($interval * $i); - - $count = 0; - $total = 0; - // Read data that falls in the current interval - while (isset($data[$j]) && - isset ($data[$j]) !== null && - $data[$j]['utimestamp'] >= $timestamp && - $data[$j]['utimestamp'] <= ($timestamp + $interval)) { - - // --------------------------------------------------------- - // FIX TICKET #1749 - $last_known = $count; - // --------------------------------------------------------- - $count++; - $j++; - } - - if ($max_value < $count) { - $max_value = $count; - } - - // Read events and alerts that fall in the current interval - $event_value = 0; - $alert_value = 0; - while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] <= ($timestamp + $interval)) { - if ($show_events == 1) { - $event_value++; - } - if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') { - $alert_value++; - } - $k++; - } - - ///////////////////////////////////////////////////////////////// - // Set the title and time format - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = 'M d H:i'; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = 'M d H\h'; - } - elseif ($period < SECONDS_6MONTHS) { - $time_format = "M d H\h"; - } - else { - $time_format = "Y M d H\h"; - } - - $timestamp_short = date($time_format, $timestamp); - $long_index[$timestamp_short] = date( - html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp); - $timestamp = $timestamp_short; - ///////////////////////////////////////////////////////////////// - - // Data in the interval - //The order in chart array is very important!!!! - if ($show_events) { - $chart[$timestamp]['event'] = $event_value; - } - - if ($show_alerts) { - $chart[$timestamp]['alert'] = $alert_value; - } - - if (!$avg_only) { - $chart[$timestamp]['max'] = 0; - } - - if ($count > 0) { - $chart[$timestamp]['sum'] = $count; - } - else { - // Compressed data - $chart[$timestamp]['sum'] = $last_known; - } - - if (!$avg_only) { - $chart[$timestamp]['min'] = 0; - } - } - - $graph_stats = get_statwin_graph_statistics($chart); - - // Fix event and alert scale - $event_max = 2 + (float)$max_value * 1.05; - foreach ($chart as $timestamp => $chart_data) { - if (!empty($chart_data['event']) && $chart_data['event'] > 0) { - $chart[$timestamp]['event'] = $event_max; - } - if (!empty($chart_data['alert']) && $chart_data['alert'] > 0) { - $chart[$timestamp]['alert'] = $event_max; - } - } - - if (empty($unit_name)) { - $unit = modules_get_unit($agent_module_id); - } - else - $unit = $unit_name; - - ///////////////////////////////////////////////////////////////////////////////////////// - $color = array(); - - if ($show_events) { - $color['event'] = array('border' => '#ff0000', - 'color' => '#ff0000', 'alpha' => CHART_DEFAULT_ALPHA); - } - if ($show_alerts) { - $color['alert'] = array('border' => '#ff7f00', - 'color' => '#ff7f00', 'alpha' => CHART_DEFAULT_ALPHA); - } - - if (!$avg_only) { - $color['max'] = array('border' => '#000000', - 'color' => $config['graph_color3'], - 'alpha' => CHART_DEFAULT_ALPHA); - } - $color['sum'] = array('border' => '#000000', - 'color' => $config['graph_color2'], - 'alpha' => CHART_DEFAULT_ALPHA); - - if (!$avg_only) { - $color['min'] = array('border' => '#000000', - 'color' => $config['graph_color1'], - 'alpha' => CHART_DEFAULT_ALPHA); - } - - //$color['baseline'] = array('border' => null, 'color' => '#0097BD', 'alpha' => 10); - ///////////////////////////////////////////////////////////////////////////////////////// - - $flash_chart = $config['flash_charts']; - if ($only_image) { - $flash_chart = false; - } - - $legend = array(); - - if ($show_events) { - $legend['event'] = __('Events'); - } - - if ($show_alerts) { - $legend['alert'] = __('Alerts'); - } - - if (!$avg_only) { - $legend['max'] = __('Max').': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['max']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['max']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['max']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['max']['min'], $config['graph_precision'])).' '.$unit; - } - - $legend['sum'] = __('Avg').': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['sum']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['sum']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['sum']['min'], $config['graph_precision'])).' '.$unit; - - if (!$avg_only) { - $legend['min'] = __('Min').': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['min']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['min']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['min']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['min']['min'], $config['graph_precision'])).' '.$unit; - } - - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - if ($type_graph === 'area') { - return area_graph($flash_chart, $chart, $width, $height, $color, - $legend, array(), '', $title, $unit, $homeurl, - $water_mark, $config['fontpath'], $config['font_size'], $unit, - 1, array(), array(), 0, 0, $adapt_key, true, '', $menu); - } - else { - return - line_graph($flash_chart, $chart, $width, $height, $color, - $legend, $long_index, - ui_get_full_url("images/image_problem_area_small.png", false, false, false), - $title, $unit, $water_mark, $config['fontpath'], - $config['font_size'], $unit, $ttl, $homeurl, $backgroundColor); - } -} - /** * Print a graph with event data of module * @@ -6298,360 +4639,6 @@ function graphic_module_events ($id_module, $width, $height, $period = 0, $homeu } } -///Functions for the LOG4X graphs -function grafico_modulo_log4x ($id_agente_modulo, $periodo, $show_event, - $width, $height , $title, $unit_name, $show_alert, $avg_only = 0, $pure=0, - $date = 0) { - - grafico_modulo_log4x_trace("
");
-	
-	if ($date == "")
-		$now = time ();
-	else
-		$now = $date;
-	
-	$fechatope = $now - $periodo; // limit date
-	
-	$nombre_agente = modules_get_agentmodule_agent_name ($id_agente_modulo);
-	$nombre_modulo = modules_get_agentmodule_name ($id_agente_modulo);
-	$id_agente = agents_get_agent_id ($nombre_agente);
-	
-	$adjust_time = SECONDS_1MINUTE;
-	
-
-	if ($periodo == SECONDS_1DAY)
-		$adjust_time = SECONDS_1HOUR;
-	elseif ($periodo == SECONDS_1WEEK)
-		$adjust_time = SECONDS_1DAY;
-	elseif ($periodo == SECONDS_1HOUR)
-		$adjust_time = SECONDS_10MINUTES;
-	elseif ($periodo == SECONDS_1MONTH)
-		$adjust_time = SECONDS_1WEEK;
-	else
-		$adjust_time = $periodo / 12.0;
-	
-	$num_slices = $periodo / $adjust_time;
-	
-	$fechatope_index = grafico_modulo_log4x_index($fechatope, $adjust_time);
-	
-	$sql1="SELECT utimestamp, SEVERITY " .
-			" FROM tagente_datos_log4x " .
-			" WHERE id_agente_modulo = $id_agente_modulo AND utimestamp > $fechatope and utimestamp < $now";
-	
-	$valores = array();
-	
-	$max_count = -1;
-	$min_count = 9999999;
-	
-	grafico_modulo_log4x_trace("$sql1");
-	
-	$rows = 0;
-	
-	$first = true;
-	while ($row = get_db_all_row_by_steps_sql($first, $result, $sql1)) {
-		$first = false;
-		
-		$rows++;
-		$utimestamp = $row[0];
-		$severity = $row[1];
-		$severity_num = $row[2];
-		
-		if (!isset($valores[$severity]))
-			$valores[$severity] = array();
-		
-		$dest = grafico_modulo_log4x_index($utimestamp, $adjust_time);
-		
-		$index = (($dest - $fechatope_index) / $adjust_time) - 1;
-		
-		if (!isset($valores[$severity][$index])) {
-			$valores[$severity][$index] = array();
-			$valores[$severity][$index]['pivot'] = $dest;
-			$valores[$severity][$index]['count'] = 0;
-			$valores[$severity][$index]['alerts'] = 0;
-		}
-		
-		$valores[$severity][$index]['count']++;
-		
-		$max_count = max($max_count, $valores[$severity][$index]['count']);
-		$min_count = min($min_count, $valores[$severity][$index]['count']);
-	}
-	
-	grafico_modulo_log4x_trace("$rows rows");
-	
-	// Create graph
-	// *************
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	
-	//set_error_handler("myErrorHandler");
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	$ds = DIRECTORY_SEPARATOR;
-	set_include_path(get_include_path() . PATH_SEPARATOR . getcwd() . $ds."..".$ds."..".$ds."include");
-	
-	require_once 'Image/Graph.php';
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	
-	$Graph =& Image_Graph::factory('graph', array($width, $height));
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	
-	// add a TrueType font
-	$Font =& $Graph->addNew('font', $config['fontpath']); // C:\WINNT\Fonts\ARIAL.TTF
-	$Font->setSize(7);
-	
-	$Graph->setFont($Font);
-	
-	if ($periodo == SECONDS_1DAY)
-		$title_period = $lang_label["last_day"];
-	elseif ($periodo == SECONDS_1WEEK)
-		$title_period = $lang_label["last_week"];
-	elseif ($periodo == SECONDS_1HOUR)
-		$title_period = $lang_label["last_hour"];
-	elseif ($periodo == SECONDS_1MONTH)
-		$title_period = $lang_label["last_month"];
-	else {
-		$suffix = $lang_label["days"];
-		$graph_extension = $periodo / SECONDS_1DAY;
-		
-		if ($graph_extension < 1) {
-			$graph_extension = $periodo / SECONDS_1HOUR;
-			$suffix = $lang_label["hours"];
-		}
-		//$title_period = "Last ";
-		$title_period = format_numeric($graph_extension,2)." $suffix";
-	}
-	
-	$title_period = html_entity_decode($title_period);
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	
-	if ($pure == 0) {
-		$Graph->add(
-			Image_Graph::horizontal(
-				Image_Graph::vertical(
-					Image_Graph::vertical(
-						$Title = Image_Graph::factory('title', array('   Pandora FMS Graph - '.strtoupper($nombre_agente)." - " .$title_period, 10)),
-						$Subtitle = Image_Graph::factory('title', array('     '.$title, 7)),
-						90
-					),
-					$Plotarea = Image_Graph::factory('plotarea', array('Image_Graph_Axis', 'Image_Graph_Axis')),
-					15 // If you change this, change the 0.85 below
-				),
-				Image_Graph::vertical(
-					$Legend = Image_Graph::factory('legend'),
-					$PlotareaMinMax = Image_Graph::factory('plotarea'),
-					65
-				),
-				85 // If you change this, change the 0.85 below
-			)
-		);
-		
-		$Legend->setPlotarea($Plotarea);
-		$Title->setAlignment(IMAGE_GRAPH_ALIGN_LEFT);
-		$Subtitle->setAlignment(IMAGE_GRAPH_ALIGN_LEFT);
-	}
-	else { // Pure, without title and legends
-		$Graph->add($Plotarea = Image_Graph::factory('plotarea', array('Image_Graph_Axis', 'Image_Graph_Axis')));
-	}
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	
-	$dataset = array();
-	
-	$severities = array("FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE");
-	$colors = array("black", "red", "orange", "yellow", "#3300ff", 'magenta');
-	
-	$max_bubble_radius = $height * 0.6 / (count($severities) + 1); // this is the size for the max_count
-	$y = count($severities) - 1;
-	$i = 0;
-	
-	foreach($severities as $severity) {
-		$dataset[$i] = Image_Graph::factory('dataset');
-		$dataset[$i]->setName($severity);
-		
-		if (isset($valores[$severity])) {
-			$data =& $valores[$severity];
-			while (list($index, $data2) = each($data)) {
-				$count = $data2['count'];
-				$pivot = $data2['pivot'];
-				
-				//$x = $scale * $index;
-				$x = 100.0 * ($pivot - $fechatope) / ($now - $fechatope);
-				if ($x > 100) $x = 100;
-				
-				$size = grafico_modulo_log4x_bubble_size($count, $max_count, $max_bubble_radius);
-				
-				// pivot is the value in the X axis
-				// y is the number of steps (from the bottom of the graphics) (zero based)
-				// x is the position of the bubble, in % from the left (0% = full left, 100% = full right)
-				// size is the radius of the bubble
-				// value is the value associated with the bubble (needed to calculate the leyend)
-				//
-				$dataset[$i]->addPoint($pivot, $y, array("x" => $x, "size" => $size, "value" => $count));
-			}
-		}
-		else {
-			// There's a problem when we have no data ...
-			// This was the first try.. didnt work
-			//$dataset[$i]->addPoint($now, -1, array("x" => 0, "size" => 0));
-		}
-		
-		$y--;
-		$i++;
-	}
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	
-	// create the 1st plot as smoothed area chart using the 1st dataset
-	$Plot =& $Plotarea->addNew('bubble', array(&$dataset));
-	$Plot->setFont($Font);
-	
-	$AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
-	$AxisX->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'grafico_modulo_log4x_format_x_axis'));
-	$AxisX->forceMinimum($fechatope);
-	$AxisX->forceMaximum($now);
-	
-	$minIntervalWidth = $Plot->getTextWidth("88/88/8888");
-	$interval_x = $adjust_time;
-	
-	while (true) {
-		$intervalWidth = $width * 0.85 * $interval_x/ $periodo;
-		if ($intervalWidth >= $minIntervalWidth)
-			break;
-		
-		$interval_x *= 2;
-	}
-	
-	$AxisX->setLabelInterval($interval_x);
-	$AxisX->setLabelOption("showtext",true);
-	
-	//*
-	$GridY2 =& $Plotarea->addNew('line_grid');
-	$GridY2->setLineColor('gray');
-	$GridY2->setFillColor('lightgray@0.05');
-	$GridY2->_setPrimaryAxis($AxisX);
-	//$GridY2->setLineStyle(Image_Graph::factory('Image_Graph_Line_Dotted', array("white", "gray", "gray", "gray")));
-	$GridY2->setLineStyle(Image_Graph::factory('Image_Graph_Line_Formatted', array(array("transparent", "transparent", "transparent", "gray"))));
-	//*/
-	//grafico_modulo_log4x_trace(print_r($AxisX, true));
-	
-	$AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
-	$AxisY->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'grafico_modulo_log4x_format_y_axis'));
-	$AxisY->setLabelOption("showtext",true);
-	//$AxisY->setLabelInterval(0);
-	//$AxisY->showLabel(IMAGE_GRAPH_LABEL_ZERO);
-	
-	//*
-	$GridY2 =& $Plotarea->addNew('line_grid');
-	$GridY2->setLineColor('gray');
-	$GridY2->setFillColor('lightgray@0.05');
-	$GridY2->_setPrimaryAxis($AxisY);
-	$GridY2->setLineStyle(Image_Graph::factory('Image_Graph_Line_Formatted', array(array("transparent", "transparent", "transparent", "gray"))));
-	//*/
-	
-	$AxisY->forceMinimum(0);
-	$AxisY->forceMaximum(count($severities) + 1) ;
-	
-	// set line colors
-	$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
-	
-	$Plot->setFillStyle($FillArray);
-	foreach($colors as $color)
-		$FillArray->addColor($color);
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	
-	$FillArray->addColor('green@0.6');
-	//$AxisY_Weather =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
-	
-	// Show events !
-	if ($show_event == 1) {
-		$Plot =& $Plotarea->addNew('Plot_Impulse', array($dataset_event));
-		$Plot->setLineColor( 'red' );
-		$Marker_event =& Image_Graph::factory('Image_Graph_Marker_Cross');
-		$Plot->setMarker($Marker_event);
-		$Marker_event->setFillColor( 'red' );
-		$Marker_event->setLineColor( 'red' );
-		$Marker_event->setSize ( 5 );
-	}
-	
-	$Axis =& $PlotareaMinMax->getAxis(IMAGE_GRAPH_AXIS_X);
-	$Axis->Hide();
-	$Axis =& $PlotareaMinMax->getAxis(IMAGE_GRAPH_AXIS_Y);
-	$Axis->Hide();
-	
-	$plotMinMax =& $PlotareaMinMax->addNew('bubble', array(&$dataset, true));
-	
-	grafico_modulo_log4x_trace(__LINE__);
-	
-	$Graph->done();
-	
-	grafico_modulo_log4x_trace(__LINE__);
-}
-
-function grafico_modulo_log4x_index($x, $interval)
-{
-	return $x + $interval - (($x - 1) % $interval) - 1;
-}
-
-function grafico_modulo_log4x_trace($str)
-{
-	//echo "$str\n";
-}
-
-function grafico_modulo_log4x_bubble_size($count, $max_count, $max_bubble_radius)
-{
-	//Superformula de ROA
-	$r0 = 1.5;
-	$r1 = $max_bubble_radius;
-	$v2 = pow($max_count,1/2.0);
-	
-	return $r1*pow($count,1/2.0)/($v2)+$r0;
-}
-
-function grafico_modulo_log4x_format_x_axis ( $number , $decimals=2, $dec_point=".", $thousands_sep=",")
-{
-	// $number is the unix time in the local timezone
-	
-	//$dtZone = new DateTimeZone(date_default_timezone_get());
-	//$d = new DateTime("now", $dtZone);
-	//$offset = $dtZone->getOffset($d);
-	//$number -= $offset;
-	
-	return date("d/m", $number) . "\n" . date("H:i", $number);
-}
-
-function grafico_modulo_log4x_format_y_axis ( $number , $decimals=2, $dec_point=".", $thousands_sep=",")
-{
-	
-	switch ($number) {
-		case 6:
-			return "FATAL";
-			break;
-		case 5:
-			return "ERROR";
-			break;
-		case 4:
-			return "WARN";
-			break;
-		case 3:
-			return "INFO";
-			break;
-		case 2:
-			return "DEBUG";
-			break;
-		case 1:
-			return "TRACE";
-			break;
-		default:
-			return "";
-			break;
-	}
-	
-}
-
 function graph_nodata_image($width = 300, $height = 110, $type = 'area', $text = '') {
 	$image = ui_get_full_url('images/image_problem_area_small.png',
 		false, false, false); 
@@ -7069,4 +5056,313 @@ function graph_monitor_wheel ($width = 550, $height = 600, $filter = false) {
 	return d3_sunburst_graph ($graph_data, $width, $height, true);
 }
 
-?>
\ No newline at end of file
+/**
+ * Draw a graph of Module string data of agent
+ * @param integer id_agent_modulo Agent Module ID
+ * @param integer show_event show event (1 or 0)
+ * @param integer height graph height
+ * @param integer width graph width
+ * @param string title graph title
+ * @param string unit_name String of unit name
+ * @param integer show alerts (1 or 0)
+ * @param integer avg_only calcules avg only (1 or 0)
+ * @param integer pure Fullscreen (1 or 0)
+ * @param integer date date
+ */
+function grafico_modulo_string ($agent_module_id, $period, $show_events,
+	$width, $height, $title, $unit_name, $show_alerts, $avg_only = 0, $pure = 0,
+	$date = 0, $only_image = false, $homeurl = '', $adapt_key = '', $ttl = 1, $menu = true) {
+
+	global $config;
+	global $graphic_type;
+	global $max_value;
+
+	// Set variables
+	if ($date == 0){
+		$date = get_system_time();
+	}
+
+	$datelimit = $date - $period;
+	$search_in_history_db = db_search_in_history_db($datelimit);
+	$resolution = $config['graph_res'] * 50; //Number of points of the graph
+	$interval = (int) ($period / $resolution);
+	$agent_name = modules_get_agentmodule_agent_name ($agent_module_id);
+	$agent_id = agents_get_agent_id ($agent_name);
+	$module_name = modules_get_agentmodule_name ($agent_module_id);
+	$id_module_type = modules_get_agentmodule_type ($agent_module_id);
+	$module_type = modules_get_moduletype_name ($id_module_type);
+	$uncompressed_module = is_module_uncompressed ($module_type);
+
+	if ($uncompressed_module) {
+		$avg_only = 1;
+	}
+
+	$search_in_history_db = db_search_in_history_db($datelimit);
+
+	// Get event data (contains alert data too)
+	if ($show_events == 1 || $show_alerts == 1) {
+		$events = db_get_all_rows_filter ('tevento',
+			array ('id_agentmodule' => $agent_module_id,
+				"utimestamp > $datelimit",
+				"utimestamp < $date",
+				'order' => 'utimestamp ASC'),
+			array ('evento', 'utimestamp', 'event_type'));
+		if ($events === false) {
+			$events = array ();
+		}
+	}
+
+	// Get module data
+	$data = db_get_all_rows_filter ('tagente_datos_string',
+		array ('id_agente_modulo' => $agent_module_id,
+			"utimestamp > $datelimit",
+			"utimestamp < $date",
+			'order' => 'utimestamp ASC'),
+		array ('datos', 'utimestamp'), 'AND', $search_in_history_db);
+	if ($data === false) {
+		$data = array ();
+	}
+
+	// Uncompressed module data
+	if ($uncompressed_module) {
+		$min_necessary = 1;
+	}
+	else {
+		// Compressed module data
+
+		// Get previous data
+		$previous_data = modules_get_previous_data ($agent_module_id, $datelimit, 1);
+		if ($previous_data !== false) {
+			$previous_data['utimestamp'] = $datelimit;
+			array_unshift ($data, $previous_data);
+		}
+		
+		// Get next data
+		$nextData = modules_get_next_data ($agent_module_id, $date, 1);
+		if ($nextData !== false) {
+			array_push ($data, $nextData);
+		}
+		else if (count ($data) > 0) {
+			// Propagate the last known data to the end of the interval
+			$nextData = array_pop ($data);
+			array_push ($data, $nextData);
+			$nextData['utimestamp'] = $date;
+			array_push ($data, $nextData);
+		}
+		
+		$min_necessary = 2;
+	}
+	
+	// Check available data
+	if (count ($data) < $min_necessary) {
+		if (!$graphic_type) {
+			return fs_error_image ($width, $height);
+		}
+		graphic_error ();
+	}
+	
+	// Data iterator
+	$j = 0;
+	
+	// Event iterator
+	$k = 0;
+	
+	// Set initial conditions
+	$chart = array();
+	if ($data[0]['utimestamp'] == $datelimit) {
+		$previous_data = 1;
+		$j++;
+	}
+	else {
+		$previous_data = 0;
+	}
+	
+	// Calculate chart data
+	$last_known = $previous_data;
+	for ($i = 0; $i < $resolution; $i++) {
+		$timestamp = $datelimit + ($interval * $i);
+		
+		$count = 0;
+		$total = 0;
+		// Read data that falls in the current interval
+		while (isset($data[$j]) &&
+			isset ($data[$j]) !== null &&
+			$data[$j]['utimestamp'] >= $timestamp &&
+			$data[$j]['utimestamp'] <= ($timestamp + $interval)) {
+			
+			// ---------------------------------------------------------
+			// FIX TICKET #1749
+			$last_known = $count;
+			// ---------------------------------------------------------
+			$count++;
+			$j++;
+		}
+		
+		if ($max_value < $count) {
+			$max_value = $count;
+		}
+		
+		// Read events and alerts that fall in the current interval
+		$event_value = 0;
+		$alert_value = 0;
+		while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] <= ($timestamp + $interval)) {
+			if ($show_events == 1) {
+				$event_value++;
+			}
+			if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') {
+				$alert_value++;
+			}
+			$k++;
+		}
+		
+		/////////////////////////////////////////////////////////////////
+		// Set the title and time format
+		if ($period <= SECONDS_6HOURS) {
+			$time_format = 'H:i:s';
+		}
+		elseif ($period < SECONDS_1DAY) {
+			$time_format = 'H:i';
+		}
+		elseif ($period < SECONDS_15DAYS) {
+			$time_format = 'M d H:i';
+		}
+		elseif ($period < SECONDS_1MONTH) {
+			$time_format = 'M d H\h';
+		}
+		elseif ($period < SECONDS_6MONTHS) {
+			$time_format = "M d H\h";
+		}
+		else {
+			$time_format = "Y M d H\h";
+		}
+		
+		$timestamp_short = date($time_format, $timestamp);
+		$long_index[$timestamp_short] = date(
+			html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp);
+		$timestamp = $timestamp_short;
+		/////////////////////////////////////////////////////////////////
+		
+		// Data in the interval
+		//The order in chart array is very important!!!!
+		if ($show_events) {
+			$chart[$timestamp]['event'] = $event_value;
+		}
+		
+		if ($show_alerts) {
+			$chart[$timestamp]['alert'] = $alert_value;
+		}
+		
+		if (!$avg_only) {
+			$chart[$timestamp]['max'] = 0;
+		}
+		
+		if ($count > 0) {
+			$chart[$timestamp]['sum'] = $count;
+		}
+		else {
+			// Compressed data
+			$chart[$timestamp]['sum'] = $last_known;
+		}
+		
+		if (!$avg_only) {
+			$chart[$timestamp]['min'] = 0;
+		}
+	}
+	
+	$graph_stats = get_statwin_graph_statistics($chart);
+	
+	// Fix event and alert scale
+	$event_max = 2 + (float)$max_value * 1.05;
+	foreach ($chart as $timestamp => $chart_data) {
+		if (!empty($chart_data['event']) && $chart_data['event'] > 0) {
+			$chart[$timestamp]['event'] = $event_max;
+		}
+		if (!empty($chart_data['alert']) && $chart_data['alert'] > 0) {
+			$chart[$timestamp]['alert'] = $event_max;
+		}
+	}
+	
+	if (empty($unit_name)) {
+		$unit = modules_get_unit($agent_module_id);
+	}
+	else
+		$unit = $unit_name;
+	
+	/////////////////////////////////////////////////////////////////////////////////////////
+	$color = array();
+	
+	if ($show_events) {
+		$color['event'] = array('border' => '#ff0000',
+			'color' => '#ff0000', 'alpha' => CHART_DEFAULT_ALPHA);
+	}
+	if ($show_alerts) {
+		$color['alert'] = array('border' => '#ff7f00',
+			'color' => '#ff7f00', 'alpha' => CHART_DEFAULT_ALPHA);
+	}
+	
+	if (!$avg_only) {
+		$color['max'] = array('border' => '#000000',
+			'color' => $config['graph_color3'],
+			'alpha' => CHART_DEFAULT_ALPHA);
+	}
+	$color['sum'] = array('border' => '#000000',
+		'color' => $config['graph_color2'],
+		'alpha' => CHART_DEFAULT_ALPHA);
+	
+	if (!$avg_only) {
+		$color['min'] = array('border' => '#000000',
+			'color' => $config['graph_color1'],
+			'alpha' => CHART_DEFAULT_ALPHA);
+	}
+	
+	//$color['baseline'] = array('border' => null, 'color' => '#0097BD', 'alpha' => 10);
+	/////////////////////////////////////////////////////////////////////////////////////////
+	
+	$flash_chart = $config['flash_charts'];
+	if ($only_image) {
+		$flash_chart = false;
+	}
+	
+	$legend = array();
+	
+	if ($show_events) {
+		$legend['event'] = __('Events');
+	}
+	
+	if ($show_alerts) {
+		$legend['alert'] = __('Alerts');
+	}
+	
+	if (!$avg_only) {
+		$legend['max'] = __('Max').': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['max']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['max']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['max']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['max']['min'], $config['graph_precision'])).' '.$unit;
+	}
+	
+	$legend['sum'] = __('Avg').': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['sum']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['sum']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['sum']['min'], $config['graph_precision'])).' '.$unit;
+	
+	if (!$avg_only) {
+		$legend['min'] = __('Min').': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['min']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['min']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['min']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['min']['min'], $config['graph_precision'])).' '.$unit;
+	}
+	
+	if($config["fixed_graph"] == false){
+		$water_mark = array('file' =>
+			$config['homedir'] . "/images/logo_vertical_water.png",
+			'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
+	}
+	
+	if ($type_graph === 'area') {
+		return area_graph($flash_chart, $chart, $width, $height, $color,
+			$legend, array(), '', $title, $unit, $homeurl,
+			$water_mark, $config['fontpath'], $config['font_size'], $unit,
+			1, array(),	array(), 0, 0, $adapt_key, true, '', $menu);
+	}
+	else {
+		return
+			line_graph($flash_chart, $chart, $width, $height, $color,
+				$legend, $long_index,
+				ui_get_full_url("images/image_problem_area_small.png", false, false, false),
+				$title, $unit, $water_mark, $config['fontpath'],
+				$config['font_size'], $unit, $ttl, $homeurl, $backgroundColor);
+	}
+}
+
+?>
diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php
index b940072a6a..46e5997ead 100755
--- a/pandora_console/include/functions_modules.php
+++ b/pandora_console/include/functions_modules.php
@@ -1681,26 +1681,27 @@ function modules_get_last_value ($id_agentmodule) {
  * @return mixed The row of tagente_datos of the last period. False if there were no data.
  */
 function modules_get_previous_data ($id_agent_module, $utimestamp = 0, $string = 0) {
-	if (empty ($utimestamp))
+	if (empty ($utimestamp)){
 		$utimestamp = time ();
-	
+	}
+
 	if ($string == 1) {
 		$table = 'tagente_datos_string';
 	}
 	else {
 		$table = 'tagente_datos';
 	}
-	
+
 	$sql = sprintf ('SELECT *
 		FROM ' . $table . '
 		WHERE id_agente_modulo = %d
-			AND utimestamp <= %d 
-			AND utimestamp >= %d 
+			AND utimestamp <= %d
 		ORDER BY utimestamp DESC',
-		$id_agent_module, $utimestamp, $utimestamp - SECONDS_2DAY);
-	
-	$search_in_history_db = db_search_in_history_db($utimestamp);
+		$id_agent_module, $utimestamp,
+		$utimestamp - SECONDS_2DAY
+	);
 
+	$search_in_history_db = db_search_in_history_db($utimestamp);
 	return db_get_row_sql ($sql, $search_in_history_db);
 }
 
@@ -2318,7 +2319,7 @@ function modules_change_relation_lock ($id_relation) {
  */
 function modules_get_first_date($id_agent_module, $datelimit = 0) {
 	global $config;
-	
+
 	//check datatype string or normal
 	$table = "tagente_datos";
 	$module_type_str = modules_get_type_name ($id_agent_module);
@@ -2334,14 +2335,12 @@ function modules_get_first_date($id_agent_module, $datelimit = 0) {
 		$query  = " SELECT max(utimestamp) as utimestamp FROM $table ";
 		$query .= " WHERE id_agente_modulo=$id_agent_module ";
 		$query .= " AND utimestamp < $datelimit ";
-	
 	}
 	else {
 		// get first utimestamp
 		$query  = " SELECT min(utimestamp) as utimestamp FROM $table ";
 		$query .= " WHERE id_agente_modulo=$id_agent_module ";
 	}
-	
 
 	// SEARCH ACTIVE DB
 	$data = db_get_all_rows_sql($query,$search_historydb);
diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php
index e4a2d672af..ba185c9344 100644
--- a/pandora_console/include/graphs/fgraph.php
+++ b/pandora_console/include/graphs/fgraph.php
@@ -39,11 +39,11 @@ if (!empty($graph_type)) {
 ob_end_clean ();
 
 switch($graph_type) {
-	case 'histogram': 
+	case 'histogram':
 		$width = get_parameter('width');
 		$height = get_parameter('height');
 		$data = json_decode(io_safe_output(get_parameter('data')), true);
-		
+
 		$max = get_parameter('max');
 		$title = get_parameter('title');
 		$mode = get_parameter ('mode', 1);
@@ -53,19 +53,19 @@ switch($graph_type) {
 		$width = get_parameter('width');
 		$height = get_parameter('height');
 		$progress = get_parameter('progress');
-		
+
 		$out_of_lim_str = io_safe_output(get_parameter('out_of_lim_str', false));
 		$out_of_lim_image = get_parameter('out_of_lim_image', false);
-		
+
 		$title = get_parameter('title');
-		
+
 		$mode = get_parameter('mode', 1);
-		
+
 		$fontsize = get_parameter('fontsize', 10);
-		
+
 		$value_text = get_parameter('value_text', '');
 		$colorRGB = get_parameter('colorRGB', '');
-		
+
 		gd_progress_bar ($width, $height, $progress, $title, $config['fontpath'],
 			$out_of_lim_str, $out_of_lim_image, $mode, $fontsize,
 			$value_text, $colorRGB);
@@ -74,19 +74,19 @@ switch($graph_type) {
 		$width = get_parameter('width');
 		$height = get_parameter('height');
 		$progress = get_parameter('progress');
-		
+
 		$out_of_lim_str = io_safe_output(get_parameter('out_of_lim_str', false));
 		$out_of_lim_image = get_parameter('out_of_lim_image', false);
-		
+
 		$title = get_parameter('title');
-		
+
 		$mode = get_parameter('mode', 1);
-		
+
 		$fontsize = get_parameter('fontsize', 7);
-		
+
 		$value_text = get_parameter('value_text', '');
 		$colorRGB = get_parameter('colorRGB', '');
-		
+
 		gd_progress_bubble ($width, $height, $progress, $title, $config['fontpath'],
 			$out_of_lim_str, $out_of_lim_image, $mode, $fontsize,
 			$value_text, $colorRGB);
@@ -95,7 +95,7 @@ switch($graph_type) {
 
 function histogram($chart_data, $width, $height, $font, $max, $title,
 	$mode, $ttl = 1) {
-	
+
 	$graph = array();
 	$graph['data'] = $chart_data;
 	$graph['width'] = $width;
@@ -104,18 +104,18 @@ function histogram($chart_data, $width, $height, $font, $max, $title,
 	$graph['max'] = $max;
 	$graph['title'] = $title;
 	$graph['mode'] = $mode;
-	
+
 	$id_graph = serialize_in_temp($graph, null, $ttl);
-	
+
 	return "";
 }
 
 function progressbar($progress, $width, $height, $title, $font,
 	$mode = 1, $out_of_lim_str = false, $out_of_lim_image = false,
 	$ttl = 1) {
-	
+
 	$graph = array();
-	
+
 	$graph['progress'] = $progress;
 	$graph['width'] = $width;
 	$graph['height'] = $height;
@@ -124,7 +124,7 @@ function progressbar($progress, $width, $height, $title, $font,
 	$graph['title'] = $title;
 	$graph['font'] = $font;
 	$graph['mode'] = $mode;
-	
+
 	$id_graph = serialize_in_temp($graph, null, $ttl);
 	if (is_metaconsole()) {
 		return "";
@@ -137,7 +137,7 @@ function progressbar($progress, $width, $height, $title, $font,
 
 function slicesbar_graph($chart_data, $period, $width, $height, $colors,
 	$font, $round_corner, $home_url = '', $ttl = 1) {
-	
+
 	$graph = array();
 	$graph['data'] = $chart_data;
 	$graph['period'] = $period;
@@ -146,9 +146,9 @@ function slicesbar_graph($chart_data, $period, $width, $height, $colors,
 	$graph['font'] = $font;
 	$graph['round_corner'] = $round_corner;
 	$graph['color'] = $colors;
-	
+
 	$id_graph = serialize_in_temp($graph, null, $ttl);
-	
+
 	return "";
 }
 
@@ -158,11 +158,11 @@ function vbar_graph($flash_chart, $chart_data, $width, $height,
 	$unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white',
 	$from_ux = false, $from_wux = false, $tick_color = 'white') {
 	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
+
 	if (empty($chart_data)) {
 		return '';
 	}
-	
+
 	if ($flash_chart) {
 		return flot_vcolumn_chart ($chart_data, $width, $height, $color,
 			$legend, $long_index, $homeurl, $unit, $water_mark_url,
@@ -172,20 +172,18 @@ function vbar_graph($flash_chart, $chart_data, $width, $height,
 	else {
 		foreach ($chart_data as $key => $value) {
 			if(strlen($key) > 20){
-				
-					if(strpos($key, ' - ') != -1){
-						$key_temp = explode(" - ",$key);
-						$key_temp[0] = $key_temp[0]."   \n";
-						$key_temp[1]= '...'.substr($key_temp[1],-15);
-						$key2 = $key_temp[0].$key_temp[1];
-						io_safe_output($key2);
-					}
+				if(strpos($key, ' - ') != -1){
+					$key_temp = explode(" - ",$key);
+					$key_temp[0] = $key_temp[0]."   \n";
+					$key_temp[1]= '...'.substr($key_temp[1],-15);
+					$key2 = $key_temp[0].$key_temp[1];
+					io_safe_output($key2);
+				}
 				$chart_data[$key2]['g'] = $chart_data[$key]['g'];
 				unset($chart_data[$key]);
 			}
-			
 		}
-				
+
 		$graph = array();
 		$graph['data'] = $chart_data;
 		$graph['width'] = $width;
@@ -197,85 +195,41 @@ function vbar_graph($flash_chart, $chart_data, $width, $height,
 		$graph['water_mark'] = $water_mark_file;
 		$graph['font'] = $font;
 		$graph['font_size'] = $font_size;
-		
+
 		$id_graph = serialize_in_temp($graph, null, $ttl);
-		
+
 		return "";
 	}
 }
 
-// NOT USED ACTUALLY
-function threshold_graph($flash_chart, $chart_data, $width, $height,
-	$ttl = 1) {
-	
-	if ($flash_chart) {
-		return flot_area_simple_graph($chart_data, $width, $height);
-	}
-	else {
-		echo "";
-	}
-}
+function area_graph(
+	$agent_module_id, $array_data, $color,
+	$legend, $series_type, $date_array,
+	$data_module_graph, $show_elements_graph,
+	$format_graph, $water_mark, $series_suffix_str
+) {
+	global $config;
 
-function area_graph($flash_chart, $chart_data, $width, $height, $color,
-	$legend, $long_index, $no_data_image, $xaxisname = "",
-	$yaxisname = "", $homeurl="", $water_mark = "", $font = '',
-	$font_size = '', $unit = '', $ttl = 1, $series_type = array(),
-	$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, $agent_module_id = 0, $percentil_values = array(), 
-	$threshold_data = array()) {
-	
 	include_once('functions_flot.php');
-	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
-	// ATTENTION: The min size is in constants.php
-	// It's not the same minsize for all graphs, but we are choosed a prudent minsize for all
-	if ($height <= CHART_DEFAULT_HEIGHT) {
-		$height = CHART_DEFAULT_HEIGHT;
-	}
-	if ($width < CHART_DEFAULT_WIDTH) {
-		$width = CHART_DEFAULT_WIDTH;
-	}
-	
-	if (empty($chart_data)) {
-		return graph_nodata_image($width, $height);
-		return '';
-	}
 
-	if ($vconsole) $menu = false;
-	
-	if ($flash_chart) {
-		return flot_area_simple_graph(
-			$chart_data,
-			$width,
-			$height,
+	if ($config['flash_charts']) {
+		return flot_area_graph(
+			$agent_module_id,
+			$array_data,
 			$color,
 			$legend,
-			$long_index,
-			$homeurl,
-			$unit,
-			$water_mark_url,
 			$series_type,
-			$chart_extra_data,
-			$yellow_threshold,
-			$red_threshold,
-			$adapt_key,
-			$force_integer,
-			$series_suffix_str,
-			$menu,
-			$backgroundColor,
-			$dashboard,
-			$vconsole,
-			$agent_module_id,
-			$font,
-			$font_size,
-			$xaxisname,
-			$percentil_values,
-			$threshold_data
-			);
+			$date_array,
+			$data_module_graph,
+			$show_elements_graph,
+			$format_graph,
+			$water_mark,
+			$series_suffix_str
+		);
 	}
 	else {
+		//XXXXX
+		//Corregir este problema
 		$graph = array();
 		$graph['data'] = $chart_data;
 		$graph['width'] = $width;
@@ -291,7 +245,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color,
 		$graph['unit'] = $unit;
 		$graph['series_type'] = $series_type;
 		$graph['percentil'] = $percentil_values;
-		
+
 		$id_graph = serialize_in_temp($graph, null, $ttl);
 		// Warning: This string is used in the function "api_get_module_graph" from 'functions_api.php' with the regec patern "//"
 		return "';
 	}
 
 	$menu = (!$dashboard && !$vconsole);
-	
+
 	if ($flash_chart) {
 		return flot_area_stacked_graph(
 			$chart_data,
@@ -347,7 +301,7 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height,
 	else {
 		//Stack the data
 		stack_data($chart_data, $legend, $color);
-		
+
 		$graph = array();
 		$graph['data'] = $chart_data;
 		$graph['width'] = $width;
@@ -360,9 +314,9 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height,
 		$graph['font'] = $font;
 		$graph['font_size'] = $font_size;
 		$graph['backgroundColor'] = $backgroundColor;
-		
+
 		$id_graph = serialize_in_temp($graph, null, $ttl);
-		
+
 		return "";
 	}
@@ -373,15 +327,15 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height,
 	$yaxisname = "", $water_mark = "", $font = '', $font_size = '',
 	$unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white',
 	$dashboard = false, $vconsole = false) {
-	
+
 	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
+
 	if (empty($chart_data)) {
 		return '';
 	}
-	
+
 	$menu = (!$dashboard && !$vconsole);
-	
+
 	if ($flash_chart) {
 		return flot_line_stacked_graph(
 			$chart_data,
@@ -410,7 +364,7 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height,
 	else {
 		//Stack the data
 		stack_data($chart_data, $legend, $color);
-		
+
 		$graph = array();
 		$graph['data'] = $chart_data;
 		$graph['width'] = $width;
@@ -423,9 +377,9 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height,
 		$graph['font'] = $font;
 		$graph['font_size'] = $font_size;
 		$graph['backgroundColor'] = $backgroundColor;
-		
+
 		$id_graph = serialize_in_temp($graph, null, $ttl);
-		
+
 		return "";
 	}
 }
@@ -434,11 +388,11 @@ function stacked_bullet_chart($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') {
-	
+
 	include_once('functions_d3.php');
-	
+
 	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
+
 	if (empty($chart_data)) {
 		return '';
 	}
@@ -462,11 +416,11 @@ function stacked_bullet_chart($flash_chart, $chart_data, $width, $height,
 			$temp[] = ($data['min'] != false) ? $data['min'] : 0;
 			$temp[] = ($data['value'] != false) ? $data['value'] : 0;
 			$temp[] = ($data['max'] != false) ? $data['max'] : 0;
-			
+
 			$legend[] = $data['label'];
 			array_push($new_data, $temp);
 			$temp = array();
-		} 
+		}
 		$graph = array();
 		$graph['data'] = $new_data;
 		$graph['width'] = $width;
@@ -479,27 +433,26 @@ function stacked_bullet_chart($flash_chart, $chart_data, $width, $height,
 		$graph['font'] = $font;
 		$graph['font_size'] = $font_size;
 		$graph['backgroundColor'] = $backgroundColor;
-		
+
 		$id_graph = serialize_in_temp($graph, null, $ttl);
-		
+
 		return "";
 	}
-	
 }
 
 function stacked_gauge($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') {
-	
+
 	include_once('functions_d3.php');
-	
+
 	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
+
 	if (empty($chart_data)) {
 		return '';
 	}
-	
+
 	return d3_gauges(
 			$chart_data,
 			$width,
@@ -521,17 +474,17 @@ function line_graph($flash_chart, $chart_data, $width, $height, $color,
 	$dashboard = false, $vconsole = false, $series_type = array(),
 	$percentil_values = array(), $yellow_threshold = 0, $red_threshold = 0,
 	$threshold_data = array()) {
-	
+
 	include_once("functions_flot.php");
-	
+
 	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
+
 	if (empty($chart_data)) {
 		return '';
 	}
 
 	$menu = (!$dashboard && !$vconsole);
-	
+
 	if ($flash_chart) {
 		return flot_line_simple_graph(
 			$chart_data,
@@ -576,7 +529,7 @@ function line_graph($flash_chart, $chart_data, $width, $height, $color,
 		$graph['backgroundColor'] = $backgroundColor;
 		$graph['percentil'] = $percentil_values;
 		$id_graph = serialize_in_temp($graph, null, $ttl);
-		
+
 		if(empty($homeurl)){
 			return "";
 		}else{
@@ -587,54 +540,38 @@ function line_graph($flash_chart, $chart_data, $width, $height, $color,
 
 function kiviat_graph($graph_type, $flash_chart, $chart_data, $width,
 	$height, $no_data_image, $ttl = 1, $homedir="") {
-	
+
 	if (empty($chart_data)) {
 		return '';
 	}
-	
+
 	$graph = array();
 	$graph['data'] = $chart_data;
 	$graph['width'] = $width;
 	$graph['height'] = $height;
-	
+
 	$id_graph = serialize_in_temp($graph, null, $ttl);
-	
+
 	return "";
 }
 
-function radar_graph($flash_chart, $chart_data, $width, $height,
-	$no_data_image, $ttl = 1, $homedir="") {
-	
-	return kiviat_graph('radar', $flash_chart, $chart_data, $width,
-		$height, $no_data_image, $ttl, $homedir);
-}
-
-function polar_graph($flash_chart, $chart_data, $width, $height,
-	$no_data_image, $ttl = 1, $homedir="") {
-	
-	return kiviat_graph('polar', $flash_chart, $chart_data, $width,
-		$height, $no_data_image, $ttl, $homedir="");
-}
-
-
 function hbar_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',
 	$tick_color = "white", $val_min=null, $val_max=null) {
-	
+
 	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
+
 	if (empty($chart_data)) {
 		return '';
 	}
-	
+
 	if ($flash_chart) {
 		return flot_hcolumn_chart(
 			$chart_data, $width, $height, $water_mark_url, $font, $font_size, $backgroundColor, $tick_color, $val_min, $val_max);
 	}
 	else {
-		
 		foreach ($chart_data as $key => $value) {
 			if(strlen($key) > 40){
 					if(strpos($key, ' - ') != -1){
@@ -648,8 +585,7 @@ function hbar_graph($flash_chart, $chart_data, $width, $height,
 				unset($chart_data[$key]);
 			}
 		}
-		
-		
+
 		$graph = array();
 		$graph['data'] = $chart_data;
 		$graph['width'] = $width;
@@ -663,9 +599,9 @@ function hbar_graph($flash_chart, $chart_data, $width, $height,
 		$graph['font'] = $font;
 		$graph['font_size'] = $font_size;
 		$graph['force_steps'] = $force_steps;
-		
+
 		$id_graph = serialize_in_temp($graph, null, $ttl);
-		
+
 		return "";
 	}
 }
@@ -674,7 +610,7 @@ function pie3d_graph($flash_chart, $chart_data, $width, $height,
 	$others_str = "other", $homedir = "", $water_mark = "", $font = '',
 	$font_size = '', $ttl = 1, $legend_position = false, $colors = '',
 	$hide_labels = false) {
-	
+
 	return pie_graph('3d', $flash_chart, $chart_data, $width, $height,
 		$others_str, $homedir, $water_mark, $font, $font_size, $ttl,
 		$legend_position, $colors, $hide_labels);
@@ -684,9 +620,9 @@ function pie2d_graph($flash_chart, $chart_data, $width, $height,
 	$others_str = "other", $homedir="", $water_mark = "", $font = '',
 	$font_size = '', $ttl = 1, $legend_position = false, $colors = '',
 	$hide_labels = false) {
-	
+
 	return pie_graph('2d', $flash_chart, $chart_data, $width, $height,
-		$others_str, $homedir, $water_mark, $font, $font_size, $ttl, 
+		$others_str, $homedir, $water_mark, $font, $font_size, $ttl,
 		$legend_position, $colors, $hide_labels);
 }
 
@@ -694,23 +630,23 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width,
 	$height, $others_str = "other", $homedir="", $water_mark = "",
 	$font = '', $font_size = '', $ttl = 1, $legend_position = false,
 	$colors = '', $hide_labels = false) {
-	
+
 	if (empty($chart_data)) {
 		return graph_nodata_image($width, $height, 'pie');
 	}
-	
+
 	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
+
 	// This library allows only 8 colors
 	$max_values = 5;
-	
+
 	//Remove the html_entities
 	$temp = array();
 	foreach ($chart_data as $key => $value) {
 		$temp[io_safe_output($key)] = $value;
 	}
 	$chart_data = $temp;
-	
+
 	if (count($chart_data) > $max_values) {
 		$chart_data_trunc = array();
 		$n = 1;
@@ -728,7 +664,7 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width,
 		}
 		$chart_data = $chart_data_trunc;
 	}
-	
+
 	if ($flash_chart) {
 		return flot_pie_chart(array_values($chart_data),
 			array_keys($chart_data), $width, $height, $water_mark_url,
@@ -736,7 +672,6 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width,
 	}
 	else {
 		//TODO SET THE LEGEND POSITION
-		
 		$graph = array();
 		$graph['data'] = $chart_data;
 		$graph['width'] = $width;
@@ -746,9 +681,9 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width,
 		$graph['font_size'] = $font_size;
 		$graph['legend_position'] = $legend_position;
 		$graph['color'] = $colors;
-		
+
 		$id_graph = serialize_in_temp($graph, null, $ttl);
-		
+
 		switch ($graph_type) {
 			case "2d":
 				return "";
@@ -764,17 +699,16 @@ function ring_graph($flash_chart, $chart_data, $width,
 	$height, $others_str = "other", $homedir="", $water_mark = "",
 	$font = '', $font_size = '', $ttl = 1, $legend_position = false,
 	$colors = '', $hide_labels = false,$background_color = 'white') {
-	
+
 	if (empty($chart_data)) {
 		return graph_nodata_image($width, $height, 'pie');
 	}
-	
+
 	setup_watermark($water_mark, $water_mark_file, $water_mark_url);
-	
+
 	// This library allows only 8 colors
 	$max_values = 18;
-	
-	
+
 	if ($flash_chart) {
 		return flot_custom_pie_chart ($flash_chart, $chart_data,
 		$width, $height, $colors, $module_name_list, $long_index,
@@ -784,7 +718,7 @@ function ring_graph($flash_chart, $chart_data, $width,
 	else {
 		$total_modules = $chart_data['total_modules'];
 		unset($chart_data['total_modules']);
-		
+
 		$max_values = 9;
 		//Remove the html_entities
 		$n = 0;
@@ -798,13 +732,13 @@ function ring_graph($flash_chart, $chart_data, $width,
 			$n++;
 		}
 		$chart_data = $temp;
-		
+
 		$chart_data_trunc = array();
 		$coloretes = array();
 		$n = 1;
 		//~ foreach ($chart_data as $key => $value) {
 			//~ if ($n < $max_values) {
-				
+
 				//~ $chart_data_trunc[$key] = $value;
 			//~ }
 			//~ else {
@@ -816,9 +750,8 @@ function ring_graph($flash_chart, $chart_data, $width,
 			//~ $n++;
 		//~ }
 		//~ $chart_data = $chart_data_trunc;
-		
+
 		//TODO SET THE LEGEND POSITION
-		
 		$graph = array();
 		$graph['data'] = $chart_data;
 		$graph['width'] = $width;
@@ -828,11 +761,11 @@ function ring_graph($flash_chart, $chart_data, $width,
 		$graph['font_size'] = $font_size;
 		$graph['legend_position'] = $legend_position;
 		$graph['legend'] = $legend;
-		
+
 		$id_graph = serialize_in_temp($graph, null, $ttl);
-		
+
 		return "";
-				
+
 	}
 }
 
diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js
index 968c0d7600..575e36d7f4 100644
--- a/pandora_console/include/graphs/flot/pandora.flot.js
+++ b/pandora_console/include/graphs/flot/pandora.flot.js
@@ -861,1264 +861,6 @@ function pandoraFlotSlicebar(graph_id, values, datacolor, labels, legend, acumul
 	}
 }
 
-function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
-	colors, type, serie_types, water_mark, width, max_x, homeurl, unit,
-	font_size, font, menu, events, event_ids, legend_events, alerts,
-	alert_ids, legend_alerts, yellow_threshold, red_threshold,
-	force_integer, separator, separator2, 
-	yellow_up, red_up, yellow_inverse, red_inverse,
-	series_suffix_str, dashboard, vconsole, xaxisname,background_color,legend_color,
-	short_data) {
-
-	var threshold = true;
-	var thresholded = false;
-	font = font.split("/").pop().split(".").shift();
-
-	values = values.split(separator2);
-	serie_types = serie_types.split(separator);
-	labels_long = labels_long.split(separator);
-	labels = labels.split(separator);
-	//XXX 1827
-	//Translate datetime to utimestamp -> avoid convert datetime in server better...
-	$.each(labels, function (i,v) {
-		labels[i] = labels[i] * 1000;
-	});
-
-	legend = legend.split(separator);
-	events = events.split(separator);
-	event_ids = event_ids.split(separator);
-	if (alerts.length != 0)
-		alerts = alerts.split(separator);
-	else
-		alerts = [];
-	alert_ids = alert_ids.split(separator);
-	colors = colors.split(separator);
-
-	var eventsz = new Array();
-	$.each(events,function(i,v) {
-		eventsz[event_ids[i]] = v;
-	});
-
-	var alertsz = new Array();
-	$.each(alerts,function(i,v) {
-		alertsz[alert_ids[i]] = v;
-	});
-
-	switch (type) {
-		case 'line_simple':
-			stacked = null;
-			filled = false;
-			break;
-		case 'line_stacked':
-			stacked = 'stack';
-			filled = false;
-			break;
-		case 'area_simple':
-			stacked = null;
-			filled = true;
-			break;
-		case 'area_stacked':
-			stacked = 'stack';
-			filled = true;
-			break;
-	}
-
-	var datas = new Array();
-	var data_base = new Array();
-
-	// Prepared to turn series with a checkbox
-	// var showed = new Array();
-
-	var min_check = 0;
-	for (i = 0; i < values.length; i++) {
-		var serie = values[i].split(separator);
-		var aux = new Array();
-
-		$.each(serie, function(i, v) {
-			if(v < 0){
-				if(min_check > parseFloat(v)){
-					min_check = v;
-				}
-			}
-			// XXX 1827
-			//aux.push([i, v]);
-			aux.push([labels[i], v]);
-		});
-		
-		//XXX
-		var time_format_y = labels[labels.length - 1] - labels[0];
-		switch (serie_types[i]) {
-			case 'area':
-				line_show = true;
-				points_show = false; // XXX - false
-				filled = 0.2;
-				steps_chart = false;
-				break;
-			case 'line':
-			default:
-				line_show = true;
-				points_show = false;
-				filled = false;
-				steps_chart = false;
-				break;
-			case 'points':
-				line_show = false;
-				points_show = true;
-				filled = false;
-				steps_chart = false
-				break;
-			case 'unknown':
-			case 'boolean':
-				line_show = true;
-				points_show = false;
-				filled = true;
-				steps_chart = true;
-				break;
-		}
-
-		var serie_color;
-		if (colors[i] != '') {
-			serie_color = colors[i];
-		}
-		else {
-			serie_color = '#8c2';
-		}
-
-		var normalw = '#efe';
-		var warningw = '#ffe';
-		var criticalw = '#fee';
-		var normal = '#0f0';
-		var warning = '#ff0';
-		var critical = '#f00';
-	
-		var lineWidth = $('#hidden-line_width_graph').val() || 1;
-
-		// Data
-		data_base.push({
-			id: 'serie_' + i,
-			data: aux,
-			label: legend[i],
-			color: serie_color,
-			//threshold: [{ below: 80, color: "rgb(200, 20, 30)" } , { below: 65, color: "rgb(30, 200, 30)" }, { below: 50, color: "rgb(30, 200, 30)" }],
-			lines: {
-				show: line_show,
-				fill: filled,
-				lineWidth: lineWidth,
-				steps: steps_chart
-			},
-			points: { show: points_show }
-		});
-
-		// Prepared to turn series with a checkbox
-		// showed[i] = true;
-	}
-
-	max_x = data_base[0]['data'][data_base[0]['data'].length -1][0];
-
-	if(min_check != 0){
-		min_check = min_check -5;
-	}
-
-	// If threshold and up are the same, that critical or warning is disabled
-	if (yellow_threshold == yellow_up) yellow_inverse = false;
-	if (red_threshold == red_up) red_inverse = false;
-
-	//Array with points to be painted
-	var threshold_data = new Array();
-	//Array with some interesting points
-	var extremes = new Array ();
-	
-	yellow_threshold = parseFloat (yellow_threshold);
-	yellow_up = parseFloat (yellow_up);
-	red_threshold = parseFloat (red_threshold);
-	red_up = parseFloat (red_up);
-	var yellow_only_min = ((yellow_up == 0) && (yellow_threshold != 0));
-	red_only_min = ((red_up == 0) && (red_threshold != 0));
-	
-	if (threshold) {
-		// Warning interval. Change extremes depends on critical interval
-		if (yellow_inverse && red_inverse) {
-			if (red_only_min && yellow_only_min) {
-				// C: |--------         |
-				// W: |········====     |
-				
-				if (yellow_threshold > red_threshold) {
-					threshold_data.push({
-						id: 'warning_normal_fdown',
-						data: [[max_x, red_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: yellow_threshold - red_threshold, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fdown_1'] = red_threshold;
-					extremes['warning_normal_fdown_2'] = yellow_threshold;
-				}
-			} else if (!red_only_min && yellow_only_min) {
-				// C: |--------   ------|
-				// W: |········===·     |
-				
-				if (yellow_threshold > red_up) {
-					yellow_threshold = red_up;
-				}
-				if (yellow_threshold > red_threshold) {
-					threshold_data.push({
-						id: 'warning_normal_fdown',
-						data: [[max_x, red_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: yellow_threshold - red_threshold, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fdown_1'] = red_threshold;
-					extremes['warning_normal_fdown_2'] = yellow_threshold;
-				}
-			} else if (red_only_min && !yellow_only_min) {
-				// C: |-------          |
-				// W: |·······====   ===|
-				if (red_threshold < yellow_threshold) {
-					threshold_data.push({
-						id: 'warning_normal_fdown',
-						data: [[max_x, red_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: yellow_threshold - red_threshold, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fdown_1'] = red_threshold;
-					extremes['warning_normal_fdown_2'] = yellow_threshold;
-				}
-				
-				if (yellow_up < red_threshold) {
-					yellow_up = red_threshold;
-				}
-				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}
-				});
-				extremes['warning_up'] = yellow_up;
-				
-			} else {
-				if (yellow_threshold > red_threshold) {
-					// C: |--------   ------|
-					// W: |········===·  ···|
-					if (yellow_threshold > red_up) {
-						yellow_threshold = red_up;
-					}
-					threshold_data.push({
-						id: 'warning_normal_fdown',
-						data: [[max_x, red_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: yellow_threshold - red_threshold, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fdown_1'] = red_threshold;
-					extremes['warning_normal_fdown_2'] = yellow_threshold;
-				}
-				if (yellow_up < red_up) {
-					// C: |--------      ---|
-					// W: |·····  ·======···|
-					if (yellow_up < red_threshold) {
-						yellow_up = red_up;
-					}
-					threshold_data.push({ 
-						id: 'warning_normal_fup',
-						data: [[max_x, yellow_up]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: red_up - yellow_up, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fup_1'] = red_up;
-					extremes['warning_normal_fup_2'] = yellow_up;
-				}
-				// If warning is under critical completely do not paint anything yellow
-					// C: |--------    -----|
-					// W: |····          ···|
-			}
-		} else if (yellow_inverse && !red_inverse) {
-			if (red_only_min && yellow_only_min) {
-				// C: |            -----|
-				// W: |============···  |
-				if (yellow_threshold > red_threshold) {
-					yellow_threshold = red_threshold;
-				}
-				threshold_data.push({ // barWidth will be correct on draw time
-					id: 'warning_down',
-					data: [[max_x, yellow_threshold]],
-					label: null,
-					color: warning, 
-					bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-				});
-				extremes['warning_down'] = yellow_threshold;
-				
-			} else if (!red_only_min && yellow_only_min) {
-				// C: |      ----       |
-				// W: |======····===    |
-				
-				if (yellow_threshold > red_up) {
-					threshold_data.push({
-						id: 'warning_normal_fdown',
-						data: [[max_x, red_up]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: yellow_threshold - red_up, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fdown_1'] = red_up;
-					extremes['warning_normal_fdown_2'] = yellow_threshold;
-				}
-				
-				if (yellow_threshold > red_threshold) {
-					yellow_threshold = red_threshold;
-				}
-				threshold_data.push({ // barWidth will be correct on draw time
-						id: 'warning_down',
-						data: [[max_x, yellow_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-					});
-				extremes['warning_down'] = yellow_threshold;
-				
-			} else if (red_only_min && !yellow_only_min) {
-				if (yellow_threshold < red_threshold) {
-					// C: |            -----|
-					// W: |=======  ===·····|
-					threshold_data.push({ // barWidth will be correct on draw time
-						id: 'warning_down',
-						data: [[max_x, yellow_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_down'] = yellow_threshold;
-					
-					if (red_threshold > yellow_up) {
-						threshold_data.push({
-							id: 'warning_normal_fup',
-							data: [[max_x, yellow_up]],
-							label: null,
-							color: warning, 
-							bars: {show: true, align: "left", barWidth: red_threshold - yellow_up, lineWidth: 0, horizontal: true}
-						});
-						extremes['warning_normal_fup_1'] = yellow_up;
-						extremes['warning_normal_fup_2'] = red_threshold;
-					}
-				} else {
-					// C: |     ------------|
-					// W: |=====··  ········|
-					threshold_data.push({ // barWidth will be correct on draw time
-						id: 'warning_down',
-						data: [[max_x, red_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_down'] = red_threshold;
-				}
-			} else {
-				if (yellow_threshold > red_up) {
-					// C: |    -----        |
-					// W: |====·····===  ===|
-					threshold_data.push({ // barWidth will be correct on draw time
-						id: 'warning_down',
-						data: [[max_x, red_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_down'] = red_threshold;
-					
-					threshold_data.push({
-						id: 'warning_normal_fdown',
-						data: [[max_x, red_up]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: yellow_threshold - red_up, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fdown_1'] = red_up;
-					extremes['warning_normal_fdown_2'] = yellow_threshold;
-					
-					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}
-					});
-					extremes['warning_up'] = yellow_up;
-				} else if (red_threshold > yellow_up){
-					// C: |          -----  |
-					// W: |===    ===·····==|
-					threshold_data.push({ // barWidth will be correct on draw time
-						id: 'warning_down',
-						data: [[max_x, yellow_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_down'] = yellow_threshold;
-					
-					threshold_data.push({
-						id: 'warning_normal_fup',
-						data: [[max_x, yellow_up]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: red_threshold - yellow_up, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fup_1'] = yellow_up;
-					extremes['warning_normal_fup_2'] = red_threshold;
-					
-					threshold_data.push({ // barWidth will be correct on draw time
-						id: 'warning_up',
-						data: [[max_x, red_up]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_up'] = red_up;
-				} else {
-					// C: |  --------       |
-					// W: |==·    ···=======|
-					if (yellow_threshold > red_threshold) {
-						yellow_threshold = red_threshold;
-					}
-					if (yellow_up < red_up) {
-						yellow_up = red_up;
-					}
-					
-					threshold_data.push({ // barWidth will be correct on draw time
-						id: 'warning_down',
-						data: [[max_x, yellow_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_down'] = yellow_threshold;
-					
-					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}
-					});
-					extremes['warning_up'] = yellow_up;
-				}
-			}
-		} else if (!yellow_inverse && red_inverse) {
-			if (yellow_only_min && red_only_min) {
-				// C: |-----            |
-				// W: |   ··============|
-				if (yellow_threshold < red_threshold) {
-					yellow_threshold = red_threshold;
-				}
-				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}
-				});
-				extremes['warning_up'] = yellow_threshold;
-				
-			} else if (!yellow_only_min && red_only_min) {
-				// C: |-----            |
-				// W: |   ··========    |
-				if (yellow_threshold < red_threshold) {
-					yellow_threshold = red_threshold;
-				}
-				if (yellow_up > red_threshold) {
-					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}
-					});
-					extremes['warning_normal_1'] = yellow_threshold;
-					extremes['warning_normal_2'] = yellow_up;
-				}
-			} else if (yellow_only_min && !red_only_min) {
-				// C: |-----      ------|
-				// W: |   ··======······|
-				if (yellow_threshold < red_threshold) {
-					yellow_threshold = red_threshold;
-				}
-				if (yellow_threshold < red_up) {
-					threshold_data.push({
-						id: 'warning_normal',
-						data: [[max_x, yellow_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: (red_up - yellow_threshold), lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_1'] = yellow_threshold;
-					extremes['warning_normal_2'] = red_up;
-				}
-				// If warning is under critical completely do not paint anything yellow
-					// C: |--------    -----|
-					// W: |              ···|
-			} else {
-				if (red_up > yellow_threshold && red_threshold < yellow_up) {
-					// C: |-----      ------|
-					// W: |   ··======·     |
-					if (yellow_threshold < red_threshold) {
-						yellow_threshold = red_threshold;
-					}
-					if (yellow_up > red_up) {
-						yellow_up = red_up;
-					}
-					
-					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}
-					});
-					extremes['warning_normal_1'] = yellow_threshold;
-					extremes['warning_normal_2'] = yellow_up;
-				}
-			}
-		}
-			// If warning is under critical completely do not paint anything yellow
-				// C: |--------    -----|   or	// C: |--------    -----|
-				// W: |   ····          |		// W: |             ··  |
-		else {
-			if (red_only_min && yellow_only_min) {
-				if (yellow_threshold < red_threshold) {
-					// C: |        ---------|
-					// W: |   =====·········|
-					threshold_data.push({
-						id: 'warning_normal',
-						data: [[max_x, yellow_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: (red_threshold - yellow_threshold), lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_1'] = yellow_threshold;
-					extremes['warning_normal_2'] = red_threshold;
-				}
-			} else if (red_only_min && !yellow_only_min) {
-				// C: |        ---------|
-				// W: |   =====···      |
-				if (yellow_up > red_threshold) {
-					yellow_up = red_threshold;
-				}
-				if (yellow_threshold < red_threshold) {
-					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}
-					});
-					extremes['warning_normal_1'] = yellow_threshold;
-					extremes['warning_normal_2'] = yellow_up;
-				}
-			} else if (!red_only_min && yellow_only_min) {
-				// C: |     -------     |
-				// W: |   ==·······=====|
-				
-				if (yellow_threshold < red_threshold) {
-					threshold_data.push({
-						id: 'warning_normal_fdown',
-						data: [[max_x, yellow_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: red_threshold - yellow_threshold, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fdown_1'] = yellow_threshold;
-					extremes['warning_normal_fdown_2'] = red_threshold;
-				}
-				
-				if (yellow_threshold < red_up) {
-					yellow_threshold = red_up;
-				}
-				
-				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}
-				});
-				extremes['warning_up'] = yellow_threshold;
-				
-			} else {
-				if (red_threshold > yellow_threshold && red_up < yellow_up ) {
-					// C: |    ------       |
-					// W: |  ==······====   |
-					threshold_data.push({
-						id: 'warning_normal_fdown',
-						data: [[max_x, yellow_threshold]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: red_threshold - yellow_threshold, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fdown_1'] = yellow_threshold;
-					extremes['warning_normal_fdown_2'] = red_threshold;
-					
-					threshold_data.push({
-						id: 'warning_normal_fup',
-						data: [[max_x, red_up]],
-						label: null,
-						color: warning, 
-						bars: {show: true, align: "left", barWidth: yellow_up - red_up, lineWidth: 0, horizontal: true}
-					});
-					extremes['warning_normal_fup_1'] = red_up;
-					extremes['warning_normal_fup_2'] = yellow_up;
-				} else if (red_threshold < yellow_threshold && red_up > yellow_up) {
-				// If warning is under critical completely do not paint anything yellow
-					// C: |  --------        |
-					// W: |    ····          |
-				} else {
-					// C: |     --------    |   or	// C: |     ------      |
-					// W: |   ==··          |		// W: |        ···====  |
-					if ((yellow_up > red_threshold) && (yellow_up < red_up)) {
-						yellow_up = red_threshold;
-					}
-					if ((yellow_threshold < red_up) && (yellow_threshold > red_threshold)) {
-						yellow_threshold = red_up;
-					}
-					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}
-					});
-					extremes['warning_normal_1'] = yellow_threshold;
-					extremes['warning_normal_2'] = yellow_up;
-				}
-			}
-		}
-		// Critical interval
-		if (red_inverse) {
-			if (!red_only_min) {
-				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, red_threshold]],
-				label: null,
-				color: critical, 
-				bars: {show: true, align: "left", barWidth: 1, lineWidth: 0, horizontal: true}
-			});
-		} else {
-			if (red_up == 0 && red_threshold != 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
-	datas = data_base;
-
-	// minTickSize
-	var count_data = datas[0].data.length;
-	var min_tick_pixels = 80;
-	
-	if (unit != "") {
-		xaxisname = xaxisname + " (" + unit + ")"
-	}
-	
-	var options = {
-			series: {
-				stack: stacked,
-				shadowSize: 0.1
-			},
-			crosshair: { mode: 'xy' },
-			selection: { mode: 'x', color: '#777' },
-			export: {
-				export_data: true,
-				labels_long: labels_long,
-				homeurl: homeurl
-			},
-			grid: {
-				hoverable: true,
-				clickable: true,
-				borderWidth:1,
-				borderColor: '#C1C1C1',
-				tickColor: background_color,
-				color: legend_color
-			},
-			xaxes: [{
-				/*
-				axisLabelFontSizePixels: font_size,
-				axisLabelUseCanvas: false,
-				tickFormatter: xFormatter,
-				labelHeight: 50,
-				color: '',
-				font: font,
-				*/
-			// XXX 1827
-				axisLabelUseCanvas: false,
-				axisLabelFontSizePixels: font_size,
-				mode: "time",
-				tickFormatter: xFormatter,
-				// timeformat: "%Y/%m/%d %H:%M:%S",
-			}],
-			yaxes: [{
-				tickFormatter: yFormatter,
-				color: '',
-				alignTicksWithAxis: 1,
-				labelWidth: 30,
-				position: 'left',
-				font: font,
-				reserveSpace: true,
-				min: min_check
-			}],
-			legend: {
-				position: 'se',
-				container: $('#legend_' + graph_id),
-				labelFormatter: lFormatter
-			}
-		};
-	if (vconsole) {
-		options.grid['hoverable'] = false;
-		options.grid['clickable'] = false;
-		options.crosshair = false;
-		options.selection = false;
-	}
-	
-	var stack = 0, bars = true, lines = false, steps = false;
-	var plot = $.plot($('#' + graph_id), datas, options);
-	
-	// Re-calculate the graph height with the legend height
-	if (dashboard || vconsole) {
-		var hDiff = $('#'+graph_id).height() - $('#legend_'+graph_id).height();
-		if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ){
-		}
-		else {
-			$('#'+graph_id).css('height', hDiff);
-		}
-	}
-	
-	if (vconsole) {
-		var myCanvas = plot.getCanvas();
-		plot.setupGrid(); // redraw plot to new size
-		plot.draw();
-		var image = myCanvas.toDataURL("image/png");
-		return;
-	}
-	
-	// Adjust the overview plot to the width and position of the main plot
-	adjust_left_width_canvas(graph_id, 'overview_'+graph_id);
-	update_left_width_canvas(graph_id); 
-
-	// Adjust overview when main chart is resized
-	$('#'+graph_id).resize(function(){
-		update_left_width_canvas(graph_id);
-	});
-
-	// Adjust linked graph to the width and position of the main plot
-
-	// Miniplot
-	if (!vconsole) {
-		var overview = $.plot($('#overview_'+graph_id),datas, {
-			series: {
-				stack: stacked,
-				lines: { show: true, lineWidth: 1 },
-				shadowSize: 0
-			},
-			grid: { borderWidth: 1, hoverable: true, autoHighlight: false},
-			xaxis: { },
-				xaxes: [ {
-					tickFormatter: xFormatter,
-					minTickSize: steps,
-					color: ''
-					} ],
-			yaxis: {ticks: [], autoscaleMargin: 0.1 },
-			selection: {mode: 'x', color: '#777' },
-			legend: {show: false},
-			crosshair: {mode: 'x'}
-		});
-	}
-	// Connection between plot and miniplot
-
-	$('#' + graph_id).bind('plotselected', function (event, ranges) {
-		// do the zooming if exist menu to undo it
-		if (menu == 0) {
-			return;
-		}
-		
-		//XXX
-		dataInSelection = ranges.xaxis.to - ranges.xaxis.from;
-		//time_format_y = dataInSelection;
-		dataInPlot = plot.getData()[0].data.length;
-
-		factor = dataInSelection / dataInPlot;
-
-		new_steps = parseInt(factor * steps);
-
-		plot = $.plot($('#' + graph_id), data_base,
-			$.extend(true, {}, options, {
-				xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to},
-				xaxes: [ {
-						tickFormatter: xFormatter,
-						//XXX
-						//minTickSize: new_steps,
-						color: ''
-						} ],
-				legend: { show: false }
-			}));
-		if (thresholded) {
-			var zoom_data_threshold = new Array ();
-			
-			var y_recal = axis_thresholded(threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max,
-									red_threshold, extremes, red_up);
-			plot = $.plot($('#' + graph_id), data_base,
-			$.extend(true, {}, options, {
-				yaxis: {
-					max: y_recal.max,
-					min: y_recal.min
-				},
-				xaxis: {
-					min: plot.getAxes().xaxis.min,
-					max: plot.getAxes().xaxis.max
-				}
-			}));
-			zoom_data_threshold = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max,
-										red_threshold, extremes, red_up);
-			plot.setData(zoom_data_threshold);
-			plot.draw();
-		}
-			
-
-		$('#menu_cancelzoom_' + graph_id)
-			.attr('src', homeurl + '/images/zoom_cross_grey.png');
-
-		currentRanges = ranges;
-		// don't fire event on the overview to prevent eternal loop
-		overview.setSelection(ranges, true);
-	});
-
-	$('#overview_' + graph_id)
-		.bind('plotselected', function (event, ranges) {
-			plot.setSelection(ranges);
-		});
-
-	var legends = $('#legend_' + graph_id + ' .legendLabel');
-
-	var updateLegendTimeout = null;
-	var latestPosition = null;
-	var currentPlot = null;
-	var currentRanges = null;
-
-	// Update legend with the data of the plot in the mouse position
-	function updateLegend() {
-		updateLegendTimeout = null;
-
-		var pos = latestPosition;
-
-		var axes = currentPlot.getAxes();
-		if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max ||
-			pos.y < axes.yaxis.min || pos.y > axes.yaxis.max) {
-			return;
-		}
-
-		var j, dataset = currentPlot.getData();
-
-		var i = 0;
-		for (k = 0; k < dataset.length; k++) {
-
-			// k is the real series counter
-			// i is the series counter without thresholds
-			var series = dataset[k];
-
-			if (series.label == null) {
-				continue;
-			}
-
-			// find the nearest points, x-wise
-			for (j = 0; j < series.data.length; ++j)
-				if (series.data[j][0] > pos.x) {
-					break;
-				}
-
-			var y = series.data[j][1];
-
-			var how_bigger = "";
-			if (y > 1000000) {
-				how_bigger = "M";
-				y = y / 1000000;
-			}
-			else if (y > 1000) {
-				how_bigger = "K";
-				y = y / 1000;
-			}
-			else if(y < -1000000) {
-				how_bigger = "M";
-				y = y / 1000000;
-			}
-			else if (y < -1000) {
-				how_bigger = "K";
-				y = y / 1000;	
-			}
-
-			if (currentRanges == null || (currentRanges.xaxis.from < j && j < currentRanges.xaxis.to)) {
-				$('#timestamp_'+graph_id).show();
-				// If no legend, the timestamp labels are short and with value
-				if (legend.length == 0) {
-					$('#timestamp_'+graph_id).text(labels[j] + ' (' + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + ')');
-				}
-				else {
-					var date_format = new Date(labels_long[j]*1000);
-
-					date_format = 
-								date_format.getDate() + "/" +
-								(date_format.getMonth() + 1) + "/" + 
-								date_format.getFullYear() + "\n" + 
-								date_format.getHours() + ":" + 
-								date_format.getMinutes() + ":" + 
-								date_format.getSeconds();
-
-					$('#timestamp_'+graph_id).text(date_format);
-				}
-				//$('#timestamp_'+graph_id).css('top', plot.offset().top-$('#timestamp_'+graph_id).height()*1.5);
-
-				var timesize = $('#timestamp_'+graph_id).width();
-
-				if (currentRanges != null) {
-					dataset = plot.getData();
-				}
-
-				var timenewpos = dataset[0].xaxis.p2c(pos.x)+$('.yAxis>div').eq(0).width();
-
-				var canvaslimit = plot.width();
-
-				if (timesize+timenewpos > canvaslimit) {
-					$('#timestamp_'+graph_id).css('left', timenewpos - timesize);
-					$('#timestamp_'+graph_id).css('top', 50);
-				}
-				else {
-					$('#timestamp_'+graph_id).css('left', timenewpos);
-					$('#timestamp_'+graph_id).css('top', 50);
-				}
-			}
-			else {
-				$('#timestamp_'+graph_id).hide();
-			}
-
-			var label_aux = series.label;
-
-			// The graphs of points type and unknown graphs will dont be updated
-			if (serie_types[i] != 'points' && series.label != $('#hidden-unknown_text').val()) {
-				$('#legend_' + graph_id + ' .legendLabel')
-					.eq(i).html(label_aux +	'= ' + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + how_bigger + ' ' + unit);
-			}
-
-			$('#legend_' + graph_id + ' .legendLabel')
-				.eq(i).css('font-size',font_size+'pt');
-
-			$('#legend_' + graph_id + ' .legendLabel')
-				.eq(i).css('color','');
-
-			$('#legend_' + graph_id + ' .legendLabel')
-				.eq(i).css('font-family',font+'Font');
-
-			i++;
-		}
-	}
-
-	// Events
-	$('#' + graph_id).bind('plothover',  function (event, pos, item) {
-		overview.setCrosshair({ x: pos.x, y: 0 });
-		currentPlot = plot;
-		latestPosition = pos;
-		if (!updateLegendTimeout) {
-			updateLegendTimeout = setTimeout(updateLegend, 50);
-		}
-
-	});
-
-	$('#' + graph_id).bind("plotclick", function (event, pos, item) {
-		plot.unhighlight();
-		if (item && item.series.label != '' && (item.series.label == legend_events || item.series.label == legend_events+series_suffix_str || item.series.label == legend_alerts || item.series.label == legend_alerts+series_suffix_str)) {
-			plot.unhighlight();
-			var dataset  = plot.getData();
-
-			var extra_info = 'No info to show';
-			var extra_show = false;
-
-			var coord_x = (item.dataIndex/item.series.xaxis.datamax)* (event.target.clientWidth - event.target.offsetLeft + 1) + event.target.offsetLeft;
-
-
-			$('#extra_'+graph_id).css('left',coord_x);
-			$('#extra_'+graph_id).css('top', event.target.offsetTop + 55 );
-
-			switch(item.series.label) {
-				case legend_alerts+series_suffix_str:
-				case legend_alerts:
-					extra_info = ''+legend_alerts+':
From: '+labels_long[item.dataIndex]; - if (labels_long[item.dataIndex+1] != undefined) { - extra_info += '
To: '+labels_long[item.dataIndex+1]; - } - extra_info += '
'+get_event_details(alertsz[item.dataIndex]); - extra_show = true; - break; - case legend_events+series_suffix_str: - case legend_events: - extra_info = ''+legend_events+':
From: '+labels_long[item.dataIndex]; - if (labels_long[item.dataIndex+1] != undefined) { - extra_info += '
To: '+labels_long[item.dataIndex+1]; - } - extra_info += '
'+get_event_details(eventsz[item.dataIndex]); - extra_show = true; - break; - default: - return; - break; - } - - if (extra_show) { - $('#extra_'+graph_id).html(extra_info); - $('#extra_'+graph_id).css('display',''); - } - plot.highlight(item.series, item.datapoint); - } - else { - $('#extra_'+graph_id).html(''); - $('#extra_'+graph_id).css('display','none'); - } - }); - - $('#overview_'+graph_id).bind('plothover', function (event, pos, item) { - plot.setCrosshair({ x: pos.x, y: 0 }); - currentPlot = overview; - latestPosition = pos; - if (!updateLegendTimeout) { - updateLegendTimeout = setTimeout(updateLegend, 50); - } - }); - - $('#'+graph_id).bind('mouseout',resetInteractivity); - $('#overview_'+graph_id).bind('mouseout',resetInteractivity); - - //~ // Reset interactivity styles - function resetInteractivity() { - $('#timestamp_'+graph_id).hide(); - dataset = plot.getData(); - for (i = 0; i < dataset.length; ++i) { - var series = dataset[i]; - var label_aux = series.label; - $('#legend_' + graph_id + ' .legendLabel') - .eq(i).html(label_aux); - } - plot.clearCrosshair(); - overview.clearCrosshair(); - } - - // Format functions - function xFormatter(v, axis) { - //XXX - /* - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = "M \nd H:i"; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = "M \nd H\h"; - } - elseif ($period < SECONDS_6MONTHS) { - $time_format = "M \nd H\h"; - } - else { - $time_format = "Y M \nd H\h"; - } - */ - - var d = new Date(v); - var result_date_format = 0; - - // if(time_format_y > 86400000){ //DAY - - result_date_format = - (d.getDate() <10?'0':'') + d.getDate() + "/" + - (d.getMonth()<9?'0':'') + (d.getMonth() + 1) + "/" + - d.getFullYear() + "\n" + - (d.getHours()<10?'0':'') + d.getHours() + ":" + - (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + - (d.getSeconds()<10?'0':'') + d.getSeconds(); //+ ":" + d.getMilliseconds(); - /* } - else{ - result_date_format = - d.getHours() + ":" + - d.getMinutes() + ":" + - d.getSeconds(); //+ ":" + d.getMilliseconds(); - } - */ - //extra_css = ''; - return '
'+result_date_format+'
'; - } - - function yFormatter(v, axis) { - axis.datamin = 0; - if (short_data) { - var formatted = number_format(v, force_integer, ""); - } - else { - var formatted = v; - } - - return '
'+formatted+'
'; - } - - function lFormatter(v, item) { - return '
'+v+'
'; - // Prepared to turn series with a checkbox - //return '
'+v+'
'; - } - - if (menu) { - var parent_height; - $('#menu_overview_' + graph_id).click(function() { - $('#overview_' + graph_id).toggle(); - }); - - //~ $('#menu_export_csv_' + graph_id).click(function() { - //~ exportData({ type: 'csv' }); - //~ }); - - $("#menu_export_csv_"+graph_id) - .click(function (event) { - event.preventDefault(); - plot.exportDataCSV(); - }); - - //Not a correct call - //~ $('#menu_export_json_' + graph_id).click(function() { - //~ exportData({ type: 'json' }); - //~ }); - - //This is a correct call to export data in json - //~ $("#menu_export_json_"+graph_id) - //~ .click(function (event) { - //~ event.preventDefault(); - //~ plot.exportDataJSON(); - //~ }); - - $('#menu_threshold_' + graph_id).click(function() { - datas = new Array(); - - if (thresholded) { - $.each(data_base, function() { - // Prepared to turning series - //if(showed[this.id.split('_')[1]]) { - datas.push(this); - //} - }); - plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - yaxis: {max: max_draw}, - xaxis: { - min: plot.getAxes().xaxis.min, - max: plot.getAxes().xaxis.max - } - })); - thresholded = false; - } - else { - var max_draw = plot.getAxes().yaxis.datamax; - // Recalculate the y axis - var y_recal = axis_thresholded(threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, - red_threshold, extremes, red_up); - - plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - yaxis: { - max: y_recal.max, - min: y_recal.min - }, - xaxis: { - mode:"time", - min: plot.getAxes().xaxis.min, - max: plot.getAxes().xaxis.max - } - })); - - datas = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, - red_threshold, extremes, red_up); - - thresholded = true; - - } - - plot.setData(datas); - plot.draw(); - - //~ plot.setSelection(currentRanges); - }); - - $('#menu_cancelzoom_' + graph_id).click(function() { - // cancel the zooming - plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - //XXX - xaxis: {max: max_x }, - legend: { show: false } - })); - - $('#menu_cancelzoom_' + graph_id) - .attr('src', homeurl + '/images/zoom_cross.disabled.png'); - overview.clearSelection(); - currentRanges = null; - - thresholded = false; - }); - - // Adjust the menu image on top of the plot - // If there is no legend we increase top-padding to make space to the menu - if (legend.length == 0) { - $('#menu_' + graph_id).parent().css('padding-top', - $('#menu_' + graph_id).css('height')); - } - - // Add bottom margin in the legend - // Estimated height of 24 (works fine with this data in all browsers) - menu_height = 24; - var legend_margin_bottom = parseInt( - $('#legend_'+graph_id).css('margin-bottom').split('px')[0]); - $('#legend_'+graph_id).css('margin-bottom', '10px'); - parent_height = parseInt( - $('#menu_'+graph_id).parent().css('height').split('px')[0]); - adjust_menu(graph_id, plot, parent_height, width); - } - - if (!dashboard) { - if (water_mark) - set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); - adjust_menu(graph_id, plot, parent_height, width); - } -} - function adjust_menu(graph_id, plot, parent_height, width) { /* if ($('#'+graph_id+' .xAxis .tickLabel').eq(0).css('width') != undefined) { @@ -2369,7 +1111,7 @@ function add_threshold (data_base, threshold_data, y_min, y_max, if (end > y_max) { this.bars.barWidth = y_max - this.data[0][1]; } - } + } datas.push(this); }); return datas; @@ -2382,14 +1124,13 @@ function reduceText (text, maxLength) { return str_cut + '...' + text.substr(-firstSlideEnd - 3); } -function pandoraFlotAreaNew( +function pandoraFlotArea( graph_id, values, legend, agent_module_id, series_type, watermark, date_array, data_module_graph, show_elements_graph, - format_graph, force_integer, series_suffix_str, + format_graph, force_integer, series_suffix_str, background_color, legend_color, short_data ) { - console.log(legend); //diferents vars var unit = format_graph.unit ? format_graph.unit : ''; var homeurl = format_graph.homeurl; @@ -2408,22 +1149,21 @@ function pandoraFlotAreaNew( var yellow_threshold = parseFloat (data_module_graph.w_min); var red_threshold = parseFloat (data_module_graph.c_min); var yellow_up = parseFloat (data_module_graph.w_max); - var red_up = parseFloat (data_module_graph.c_max); + var red_up = parseFloat (data_module_graph.c_max); var yellow_inverse = parseInt (data_module_graph.w_inv); var red_inverse = parseInt (data_module_graph.c_inv); - //XXXX ver que hay que hacer var type = 'area_simple'; //var xaxisname = 'xaxisname'; - + var labels_long = ''; var min_check = 0; var water_mark = ''; - + var legend_events = null; var legend_alerts = null; - + switch (type) { case 'line_simple': stacked = null; @@ -2446,7 +1186,7 @@ function pandoraFlotAreaNew( var datas = new Array(); var data_base = new Array(); var lineWidth = $('#hidden-line_width_graph').val() || 1; - + i=0; $.each(values, function (index, value) { if (typeof value.data !== "undefined") { @@ -2500,8 +1240,8 @@ function pandoraFlotAreaNew( if (yellow_threshold == yellow_up){ yellow_inverse = false; } - - if (red_threshold == red_up){ + + if (red_threshold == red_up){ red_inverse = false; } @@ -2512,7 +1252,7 @@ function pandoraFlotAreaNew( var yellow_only_min = ((yellow_up == 0) && (yellow_threshold != 0)); var red_only_min = ((red_up == 0) && (red_threshold != 0)); - + //color var normalw = '#efe'; var warningw = '#ffe'; @@ -3025,19 +1765,19 @@ function pandoraFlotAreaNew( // minTickSize var count_data = datas[0].data.length; var min_tick_pixels = 80; - + var maxticks = date_array['period'] / 3600 /6; var options = { series: { stack: stacked, shadowSize: 0.1 }, - crosshair: { + crosshair: { mode: 'xy' }, - selection: { + selection: { mode: 'x', - color: '#777' + color: '#777' }, export: { export_data: true, @@ -3080,7 +1820,7 @@ function pandoraFlotAreaNew( options.crosshair = false; options.selection = false; } - + var stack = 0, bars = true, lines = false, @@ -3097,7 +1837,7 @@ function pandoraFlotAreaNew( $('#'+graph_id).css('height', hDiff); } } - + if (vconsole) { var myCanvas = plot.getCanvas(); plot.setupGrid(); // redraw plot to new size @@ -3105,10 +1845,10 @@ function pandoraFlotAreaNew( var image = myCanvas.toDataURL("image/png"); return; } - + // Adjust the overview plot to the width and position of the main plot adjust_left_width_canvas(graph_id, 'overview_'+graph_id); - update_left_width_canvas(graph_id); + update_left_width_canvas(graph_id); // Adjust overview when main chart is resized $('#'+graph_id).resize(function(){ @@ -3122,7 +1862,7 @@ function pandoraFlotAreaNew( var overview = $.plot($('#overview_'+graph_id),datas, { series: { stack: stacked, - lines: { + lines: { show: true, lineWidth: 1 }, @@ -3142,11 +1882,11 @@ function pandoraFlotAreaNew( labelWidth: 70, } ], yaxis: { - ticks: [], + ticks: [], autoscaleMargin: 0.1 }, selection: { - mode: 'x', + mode: 'x', color: '#777' }, legend: { @@ -3177,13 +1917,13 @@ function pandoraFlotAreaNew( plot = $.plot($('#' + graph_id), data_base, $.extend(true, {}, options, { - grid: { - borderWidth: 1, - hoverable: true, + grid: { + borderWidth: 1, + hoverable: true, autoHighlight: true }, - xaxis: { - min: ranges.xaxis.from, + xaxis: { + min: ranges.xaxis.from, max: ranges.xaxis.to }, xaxes: [{ @@ -3191,14 +1931,14 @@ function pandoraFlotAreaNew( tickFormatter: xFormatter, tickSize: [maxticks_zoom, 'hour'] }], - legend: { - show: true + legend: { + show: true } })); if (thresholded) { var zoom_data_threshold = new Array (); - + var y_recal = axis_thresholded(threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, red_threshold, extremes, red_up); @@ -3216,11 +1956,10 @@ function pandoraFlotAreaNew( zoom_data_threshold = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, red_threshold, extremes, red_up); - + plot.setData(zoom_data_threshold); plot.draw(); } - $('#menu_cancelzoom_' + graph_id) .attr('src', homeurl + '/images/zoom_cross_grey.png'); @@ -3242,7 +1981,6 @@ function pandoraFlotAreaNew( // Update legend with the data of the plot in the mouse position function updateLegend() { - console.log(currentPlot); updateLegendTimeout = null; var pos = latestPosition; var axes = currentPlot.getAxes(); @@ -3252,20 +1990,20 @@ function pandoraFlotAreaNew( } $('#timestamp_'+graph_id).show(); - + var d = new Date(pos.x); - var monthNames = [ + var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; - - date_format = (d.getDate() <10?'0':'') + d.getDate() + " " + + + date_format = (d.getDate() <10?'0':'') + d.getDate() + " " + monthNames[d.getMonth()] + " " + - d.getFullYear() + "\n" + - (d.getHours()<10?'0':'') + d.getHours() + ":" + - (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + + d.getFullYear() + "\n" + + (d.getHours()<10?'0':'') + d.getHours() + ":" + + (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + (d.getSeconds()<10?'0':'') + d.getSeconds(); $('#timestamp_'+graph_id).text(date_format); @@ -3276,10 +2014,11 @@ function pandoraFlotAreaNew( var timenewpos = dataset[0].xaxis.p2c(pos.x)+$('.yAxis>div').eq(0).width(); var canvaslimit = $('#'+graph_id).width(); - - - $('#timestamp_'+graph_id).css('top', currentPlot.offset().top - $('#timestamp_'+graph_id).height()*2.5); - + + $('#timestamp_'+graph_id) + .css('top', currentPlot.getPlotOffset().top - + $('#timestamp_'+graph_id).height() + + $('#legend_' + graph_id).height()); if (timesize+timenewpos > canvaslimit) { $('#timestamp_'+graph_id).css('left', timenewpos - timesize); @@ -3297,7 +2036,7 @@ function pandoraFlotAreaNew( if (series.label == null) { continue; } - + // find the nearest points, x-wise for (j = 0; j < series.data.length; ++j){ if (series.data[j][0] > pos.x) { @@ -3324,19 +2063,19 @@ function pandoraFlotAreaNew( } else if (y < -1000) { how_bigger = "K"; - y = y / 1000; + y = y / 1000; } var label_aux = legend[series.label] + series_suffix_str; // The graphs of points type and unknown graphs will dont be updated - if (series_type[dataset[k]["label"]] != 'points' && + if (series_type[dataset[k]["label"]] != 'points' && series_type[dataset[k]["label"]] != 'unknown' && series_type[dataset[k]["label"]] != 'percentil' ) { $('#legend_' + graph_id + ' .legendLabel') - .eq(i).html(label_aux + ' value = ' + - (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + + .eq(i).html(label_aux + ' value = ' + + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + how_bigger + ' ' + unit ); } @@ -3349,7 +2088,7 @@ function pandoraFlotAreaNew( $('#legend_' + graph_id + ' .legendLabel') .eq(i).css('font-family',font+'Font'); - + i++; } } @@ -3359,7 +2098,7 @@ function pandoraFlotAreaNew( plot.setCrosshair({ x: pos.x, y: 0 }); currentPlot = plot; latestPosition = pos; - console.log('entra'); + if (!updateLegendTimeout) { updateLegendTimeout = setTimeout(updateLegend, 50); } @@ -3369,7 +2108,6 @@ function pandoraFlotAreaNew( overview.setCrosshair({ x: pos.x, y: 0 }); currentPlot = plot; latestPosition = pos; - console.log('entra 2'); if (!updateLegendTimeout) { updateLegendTimeout = setTimeout(updateLegend, 50); } @@ -3428,7 +2166,7 @@ function pandoraFlotAreaNew( $('#'+graph_id).bind('mouseout',resetInteractivity); $('#overview_'+graph_id).bind('mouseout',resetInteractivity); - + // Reset interactivity styles function resetInteractivity() { $('#timestamp_'+graph_id).hide(); @@ -3448,20 +2186,20 @@ function pandoraFlotAreaNew( var d = new Date(v); var result_date_format = 0; - var monthNames = [ + var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; - + result_date_format = (d.getDate() <10?'0':'') + d.getDate() + " " + monthNames[d.getMonth()] + " " + - d.getFullYear() + "\n" + - (d.getHours()<10?'0':'') + d.getHours() + ":" + - (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + + d.getFullYear() + "\n" + + (d.getHours()<10?'0':'') + d.getHours() + ":" + + (d.getMinutes()<10?'0':'') + d.getMinutes() + ":" + (d.getSeconds()<10?'0':'') + d.getSeconds(); - + return '
'+result_date_format+'
'; } @@ -3477,10 +2215,9 @@ function pandoraFlotAreaNew( } function lFormatter(v, item) { - console.log(v); return '
'+legend[v]+'
'; } - + if (menu) { var parent_height; $('#menu_overview_' + graph_id).click(function() { @@ -3490,25 +2227,25 @@ function pandoraFlotAreaNew( //~ $('#menu_export_csv_' + graph_id).click(function() { //~ exportData({ type: 'csv' }); //~ }); - + $("#menu_export_csv_"+graph_id) .click(function (event) { event.preventDefault(); plot.exportDataCSV(); }); - + //Not a correct call //~ $('#menu_export_json_' + graph_id).click(function() { //~ exportData({ type: 'json' }); //~ }); - + //This is a correct call to export data in json //~ $("#menu_export_json_"+graph_id) //~ .click(function (event) { //~ event.preventDefault(); //~ plot.exportDataJSON(); //~ }); - + $('#menu_threshold_' + graph_id).click(function() { datas = new Array(); @@ -3552,9 +2289,7 @@ function pandoraFlotAreaNew( red_threshold, extremes, red_up); thresholded = true; - } - plot.setData(datas); plot.draw(); @@ -3567,12 +2302,10 @@ function pandoraFlotAreaNew( $.extend(true, {}, options, { legend: { show: true } })); - $('#menu_cancelzoom_' + graph_id) .attr('src', homeurl + '/images/zoom_cross.disabled.png'); overview.clearSelection(); currentRanges = null; - thresholded = false; }); @@ -3592,7 +2325,7 @@ function pandoraFlotAreaNew( parent_height = parseInt($('#menu_'+graph_id).parent().css('height').split('px')[0]); adjust_menu(graph_id, plot, parent_height, width); } - + if (!dashboard) { if (water_mark) set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 5356dd57b3..8fcaf060a5 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -176,417 +176,19 @@ function flot_line_simple_graph($chart_data, $width, $height, $color, $threshold_data); } -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, - $agent_module_id = 0, $font = '', $font_size = 7, $xaxisname = '', - $percentil_values = array(), $threshold_data = array()) { - - global $config; - - include_javascript_dependencies_flot_graph(); - - $menu = (int)$menu; - // Get a unique identifier to graph - $graph_id = uniqid('graph_'); - - $background_style = ''; - switch ($background_color) { - default: - case 'white': - $background_style = ' background: #fff; '; - break; - case 'black': - $background_style = ' background: #000; '; - break; - case 'transparent': - $background_style = ''; - break; - } - - // Parent layer - $return = "
"; - // Set some containers to legend, graph, timestamp tooltip, etc. - $return .= "

"; - - if (!empty($threshold_data)) { - $yellow_up = $threshold_data['yellow_up']; - $red_up = $threshold_data['red_up']; - $yellow_inverse = $threshold_data['yellow_inverse']; - $red_inverse = $threshold_data['red_inverse']; - } - else { - // 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 != $yellow_up || $red_threshold != $red_up) { - $threshold = true; - } - - $nbuttons = 3; - - if ($threshold) { - $nbuttons++; - } - $menu_width = 25 * $nbuttons + 15; - if ( $dashboard == false AND $vconsole == false) { - $return .= ""; - } - - if ($dashboard) { - $return .= ""; - } - } - - $return .= html_print_input_hidden('line_width_graph', $config['custom_graph_width'], true); - $return .= ""; - $return .= "
"; - if ($menu) { - $height = 100; - } - else { - $height = 1; - } - if (!$vconsole) - $return .= ""; - - if ($water_mark != '') { - $return .= ""; - $watermark = 'true'; - } - else { - $watermark = 'false'; - } - - // Set a weird separator to serialize and unserialize passing data from php to javascript - $separator = ';;::;;'; - $separator2 = ':,:,,,:,:'; - - // Transform data from our format to library format - $legend2 = array(); - $labels = array(); - $a = array(); - $vars = array(); - $serie_types2 = array(); - - $colors = array(); - - $index = array_keys(reset($chart_data)); - foreach ($index as $serie_key) { - if (isset($color[$serie_key])) { - $colors[] = $color[$serie_key]['color']; - } - else { - $colors[] = ''; - } - } - foreach ($chart_data as $label => $values) { - $labels[] = $label; - - foreach($values as $key => $value) { - $jsvar = "data_" . $graph_id . "_" . $key; - - - if (!isset($serie_types[$key])) { - switch ($type) { - case 'line_simple': - case 'line_stacked': - $serie_types2[$jsvar] = 'line'; - break; - case 'area_simple': - case 'area_stacked': - default: - $serie_types2[$jsvar] = 'area'; - break; - } - } - else { - $serie_types2[$jsvar] = $serie_types[$key]; - } - - - if ($serie_types2[$jsvar] == 'points' && $value == 0) { - $data[$jsvar][] = 'null'; - } - else { - $data[$jsvar][] = $value; - } - - if (!isset($legend[$key])) { - $legend2[$jsvar] = 'null'; - } - else { - $legend2[$jsvar] = $legend[$key]; - } - } - } - - if (!empty($percentil_values)) { - foreach($percentil_values as $key => $value) { - $jsvar = "percentil_" . $graph_id . "_" . $key; - $serie_types2[$jsvar] = 'line'; - $data[$jsvar] = $value; - } - } - - // Store data series in javascript format - $jsvars = ''; - $jsseries = array(); - $values2 = array(); - $i = 0; - $max_x = 0; - foreach ($data as $jsvar => $values) { - $n_values = count($values); - if ($n_values > $max_x) { - $max_x = $n_values; - } - - $values2[] = implode($separator,$values); - $i ++; - } - - $values = implode($separator2, $values2); - - // Max is "n-1" because start with 0 - $max_x--; - - $extra_width = (int)($width / 3); - - $return .= ""; - - // Process extra data - $events = array(); - $event_ids = array(); - $alerts = array(); - $alert_ids = array(); - $legend_events = ''; - $legend_alerts = ''; - - if (empty($chart_extra_data)) { - $chart_extra_data = array(); - } - - foreach ($chart_extra_data as $i => $data) { - switch ($i) { - case 'legend_alerts': - $legend_alerts = $data; - break; - case 'legend_events': - $legend_events = $data; - break; - default: - if (isset($data['events'])) { - $event_ids[] = $i; - $events[$i] = $data['events']; - } - if (isset($data['alerts'])) { - $alert_ids[] = $i; - $alerts[$i] = $data['alerts']; - } - break; - } - } - - // Store serialized data to use it from javascript - $events = implode($separator,$events); - $event_ids = implode($separator,$event_ids); - $alerts = implode($separator,$alerts); - $alert_ids = implode($separator,$alert_ids); - $labels = implode($separator,$labels); - if (!empty($long_index)) { - $labels_long = implode($separator, $long_index); - } - else { - $labels_long = $labels; - } - if (!empty($legend)) { - $legend = io_safe_output(implode($separator, $legend)); - } - $serie_types = implode($separator, $serie_types2); - $colors = implode($separator, $colors); - - // transform into string to pass to javascript - if ($force_integer) { - $force_integer = 'true'; - } - else { - $force_integer = 'false'; - } - - //modify internal grid lines and legend text color - - if(substr($background_style, -6, 4) == '#fff'){ - $background_color = "#eee"; - $legend_color = "#151515"; - - } - else if(substr($background_style, -6, 4) == '#000'){ - $background_color = "#151515"; - $legend_color = "#BDBDBD"; - } - else{ - $background_color = "#A4A4A4"; - $legend_color = "#A4A4A4"; - } - - // Trick to get translated string from javascript - $return .= html_print_input_hidden('unknown_text', __('Unknown'), - true); - - if (!isset($config["short_module_graph_data"])) - $config["short_module_graph_data"] = true; - - if ($config["short_module_graph_data"]) { - $short_data = true; - } - else { - $short_data = false; - } - - //html_debug_print($values); - // Javascript code - $return .= ""; - - // Parent layer - $return .= "
"; - - return $return; -} - - - - - - - -function flot_area_graph_new ( +function flot_area_graph ( $agent_module_id, $array_data, $color, $legend, $series_type, $date_array, $data_module_graph, $show_elements_graph, $format_graph, $water_mark, $series_suffix_str ) { - + global $config; - + include_javascript_dependencies_flot_graph(); // Get a unique identifier to graph $graph_id = uniqid('graph_'); - - //html_debug_print($agent_module_id); - //html_debug_print($array_data); - //html_debug_print($color); - //html_debug_print($legend); - //html_debug_print($series_type); - //html_debug_print($date_array); - -/* - html_debug_print($water_mark); - html_debug_print($series_suffix_str); -*/ - //html_debug_print($series_suffix_str); $background_style = ''; switch ($format_graph['background']) { default: @@ -600,64 +202,53 @@ function flot_area_graph_new ( $background_style = ''; break; } - + // Parent layer $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "

"; - - /* - if (!empty($threshold_data)) { - $yellow_up = $threshold_data['yellow_up']; - $red_up = $threshold_data['red_up']; - $yellow_inverse = $threshold_data['yellow_inverse']; - $red_inverse = $threshold_data['red_inverse']; - } - else { - */ - $yellow_threshold = $data_module_graph['w_min']; - $red_threshold = $data_module_graph['c_min']; - // 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 { - $yellow_up = $data_module_graph['w_max']; - $red_up = $data_module_graph['c_max']; - $yellow_inverse = !($data_module_graph['w_inv'] == 0); - $red_inverse = !($data_module_graph['c_inv'] == 0); - } - //} - + $yellow_threshold = $data_module_graph['w_min']; + $red_threshold = $data_module_graph['c_min']; + // 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 { + $yellow_up = $data_module_graph['w_max']; + $red_up = $data_module_graph['c_max']; + $yellow_inverse = !($data_module_graph['w_inv'] == 0); + $red_inverse = !($data_module_graph['c_inv'] == 0); + } + if ($show_elements_graph['menu']) { $return .= menu_graph( - $yellow_threshold, $red_threshold, - $yellow_up, $red_up, $yellow_inverse, - $red_inverse, $show_elements_graph['dashboard'], - $show_elements_graph['vconsole'], - $graph_id, $format_graph['width'], + $yellow_threshold, $red_threshold, + $yellow_up, $red_up, $yellow_inverse, + $red_inverse, $show_elements_graph['dashboard'], + $show_elements_graph['vconsole'], + $graph_id, $format_graph['width'], $format_graph['homeurl'] ); } $return .= html_print_input_hidden('line_width_graph', $config['custom_graph_width'], true); - $return .= "
"; $return .= "
"; if ($show_elements_graph['menu']) { @@ -668,11 +259,11 @@ function flot_area_graph_new ( } if (!$vconsole){ - $return .= "
"; } //XXXXTODO @@ -684,23 +275,21 @@ function flot_area_graph_new ( else { $watermark = 'false'; } - foreach($series_type as $k => $v){ - $series_type_unique["data_" . $graph_id . "_" . $k] = $v; - } + $series_type_unique["data_" . $graph_id . "_" . $k] = $v; + } - // Store data series in javascript format $extra_width = (int)($format_graph['width'] / 3); - $return .= "
"; - + if(substr($background_style, -6, 4) == '#fff'){ $background_color = "#eee"; $legend_color = "#151515"; @@ -716,32 +305,32 @@ function flot_area_graph_new ( //XXXX force_integer TODO $force_integer = 0; - + // Trick to get translated string from javascript $return .= html_print_input_hidden('unknown_text', __('Unknown'), true); if (!isset($config["short_module_graph_data"])) $config["short_module_graph_data"] = true; - + if ($config["short_module_graph_data"]) { $short_data = true; } else { $short_data = false; } - + $values = json_encode($array_data); $legend = json_encode($legend); $series_type = json_encode($series_type); $date_array = json_encode($date_array); - $data_module_graph = json_encode($data_module_graph); + $data_module_graph = json_encode($data_module_graph); $show_elements_graph = json_encode($show_elements_graph); $format_graph = json_encode($format_graph); // Javascript code $return .= ""; - + // Parent layer $return .= "
"; - + return $return; } - - - - - - function menu_graph( - $yellow_threshold, $red_threshold, - $yellow_up, $red_up, $yellow_inverse, - $red_inverse, $dashboard, $vconsole, + $yellow_threshold, $red_threshold, + $yellow_up, $red_up, $yellow_inverse, + $red_inverse, $dashboard, $vconsole, $graph_id, $width, $homeurl ){ $return = ''; @@ -784,9 +367,9 @@ function menu_graph( if ($yellow_threshold != $yellow_up || $red_threshold != $red_up) { $threshold = true; } - + $nbuttons = 3; - + if ($threshold) { $nbuttons++; } @@ -810,12 +393,12 @@ function menu_graph( } $return .= " " . __("; - + // Export buttons $return .= " ".__("; // Button disabled. This feature works, but seems that is not useful enough to the final users. //$return .= " ".__("; - + $return .= ""; $return .= ""; } @@ -835,35 +418,13 @@ function menu_graph( "position: relative;". "border-bottom: 0px;'> ".__("; - + $return .= ""; $return .= ""; } return $return; } - - - - - - - - - - - - - - - - - - - - - - /////////////////////////////// /////////////////////////////// /////////////////////////////// diff --git a/pandora_console/mobile/operation/module_graph.php b/pandora_console/mobile/operation/module_graph.php index 3af94962be..7719ae55ed 100644 --- a/pandora_console/mobile/operation/module_graph.php +++ b/pandora_console/mobile/operation/module_graph.php @@ -15,7 +15,7 @@ class ModuleGraph { private $correct_acl = false; private $acl = "AR"; - + private $id = 0; private $id_agent = 0; private $graph_type = "sparse"; @@ -31,14 +31,14 @@ class ModuleGraph { private $unknown_graph = 1; private $zoom = 1; private $baseline = 0; - + private $module = null; - + function __construct() { $system = System::getInstance(); - + $this->start_date = date("Y-m-d"); - + if ($system->checkACL($this->acl)) { $this->correct_acl = true; } @@ -46,17 +46,17 @@ class ModuleGraph { $this->correct_acl = false; } } - + private function getFilters() { $system = System::getInstance(); - + $this->id = (int)$system->getRequest('id', 0); $this->id_agent = (int)$system->getRequest('id_agent', 0); $this->module = modules_get_agentmodule($this->id); $this->graph_type = return_graphtype($this->module["id_tipo_modulo"]); - + $period_hours = $system->getRequest('period_hours', false); - + if ($period_hours == false) { $this->period = SECONDS_1DAY; } @@ -78,29 +78,29 @@ class ModuleGraph { $this->unknown_graph = (int)$system->getRequest('unknown_graph', 0); $this->zoom = (int)$system->getRequest('zoom', 1); $this->baseline = (int)$system->getRequest('baseline', 0); - + $this->width = (int)$system->getRequest('width', 0); $this->width -= 20; //Correct the width $this->height = (int)$system->getRequest('height', 0); - + //Sancho says "put the height to 1/2 for to make more beautyful" $this->height = $this->height / 1.5; - + $this->height -= 80; //Correct the height - + //For to avoid fucking IPHONES when they are in horizontal. if ($this->height < 140) { $this->height = 140; } - + } - + public function ajax($parameter2 = false) { - + global $config; - + $system = System::getInstance(); - + if (!$this->correct_acl) { return; } @@ -110,23 +110,20 @@ class ModuleGraph { $this->getFilters(); $correct = 0; $graph = ''; - $correct = 1; - $label = $this->module["nombre"]; $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $this->id); - $utime = get_system_time (); $current = date("Y-m-d", $utime); - + if ($this->start_date != $current) $date = strtotime($this->start_date); else $date = $utime; - + $urlImage = ui_get_full_url(false); - + $time_compare = false; if ($this->time_compare_separated) { $time_compare = 'separated'; @@ -134,37 +131,10 @@ class ModuleGraph { else if ($this->time_compare_overlapped) { $time_compare = 'overlapped'; } - + ob_start(); switch ($this->graph_type) { case 'boolean': - $graph = grafico_modulo_boolean ( - $this->id, - $this->period, - $this->draw_events, - $this->width, - $this->height, - false, - $unit, - $this->draw_alerts, - $this->avg_only, - false, - $date, - false, - $urlImage, - 'adapter_' . $this->graph_type, - $time_compare, - $this->unknown_graph, false); - if ($this->draw_events) { - $graph .= '
'; - $graph .= graphic_module_events( - $this->id, - $this->width, $this->height, - $this->period, $config['homeurl'], - $this->zoom, - 'adapted_' . $this->graph_type, $date); - } - break; case 'sparse': $graph = grafico_modulo_sparse( $this->id, @@ -223,38 +193,18 @@ class ModuleGraph { $this->zoom, 'adapted_' . $this->graph_type, $date); } break; - case 'log4x': - $graph = grafico_modulo_log4x( - $this->id, - $this->period, - $this->draw_events, - $this->width, - $this->height, - false, - $unit_name, - $this->draw_alerts, - 1, - $pure, - $date); - if ($this->draw_events) { - $graph .= '
'; - $graph .= graphic_module_events($this->id, - $this->width, $this->height, - $this->period, $config['homeurl'], $this->zoom, '', $date); - } - break; default: $graph .= fs_error_image ('../images'); break; } $graph = ob_get_clean() . $graph; - + echo json_encode(array('correct' => $correct, 'graph' => $graph)); break; } } } - + public function show() { if (!$this->correct_acl) { $this->show_fail_acl(); @@ -264,7 +214,7 @@ class ModuleGraph { $this->showModuleGraph(); } } - + private function show_fail_acl() { $error['type'] = 'onStart'; $error['title_text'] = __('You don\'t have access to this page'); @@ -275,7 +225,7 @@ class ModuleGraph { $home = new Home(); $home->show($error); } - + private function javascript_code() { ob_start(); ?> @@ -283,24 +233,24 @@ class ModuleGraph { $(document).ready(function() { function load_graph() { $("#loading_graph").show(); - - var heigth = $(document).height() + + var heigth = $(document).height() - $(".ui-header").height() - $(".ui-collapsible").height() - 55; var width = $(document).width() - 25; ajax_get_graph($("#id_module").val(), heigth, width); } - + load_graph(); - + // Detect orientation change to refresh dinamic content window.addEventListener("resize", function() { // Reload dinamic content load_graph(); }); }); - + function ajax_get_graph(id, heigth_graph, width_graph) { postvars = {}; postvars["action"] = "ajax"; @@ -308,20 +258,20 @@ class ModuleGraph { postvars["parameter2"] = "get_graph"; postvars["width"] = width_graph; postvars["height"] = heigth_graph; - + postvars["draw_alerts"] = ($("input[name = 'draw_alerts']").is(":checked"))?1:0; postvars["draw_events"] = ($("input[name = 'draw_events']").is(":checked"))?1:0; postvars["time_compare_separated"] = ($("input[name = 'time_compare_separated']").is(":checked"))?1:0; postvars["time_compare_overlapped"] = ($("input[name = 'time_compare_overlapped']").is(":checked"))?1:0; postvars["unknown_graph"] = ($("input[name = 'unknown_graph']").is(":checked"))?1:0;; postvars["avg_only"] = ($("input[name = 'avg_only']").is(":checked"))?1:0;; - + postvars["period_hours"] = $("input[name = 'period_hours']").val(); postvars["zoom"] = $("input[name = 'zoom']").val(); postvars["start_date"] = $("input[name = 'start_date']").val(); - + postvars["id"] = id; - + $.ajax ({ type: "POST", url: "index.php", @@ -348,17 +298,17 @@ class ModuleGraph { module['id_agente']); - + $ui = Ui::getInstance(); - + $ui->createPage(); - + if ($this->id_agent) { $ui->createDefaultHeader( sprintf(__("PandoraFMS: %s"), $this->module["nombre"]), @@ -394,7 +344,7 @@ class ModuleGraph { 'label' => __('Show Alerts') ); $ui->formAddCheckbox($options); - + $options = array( 'name' => 'draw_events', 'value' => 1, @@ -402,7 +352,7 @@ class ModuleGraph { 'label' => __('Show Events') ); $ui->formAddCheckbox($options); - + $options = array( 'name' => 'time_compare_separated', 'value' => 1, @@ -410,7 +360,7 @@ class ModuleGraph { 'label' => __('Time compare (Separated)') ); $ui->formAddCheckbox($options); - + $options = array( 'name' => 'time_compare_overlapped', 'value' => 1, @@ -418,7 +368,7 @@ class ModuleGraph { 'label' => __('Time compare (Overlapped)') ); $ui->formAddCheckbox($options); - + $options = array( 'name' => 'unknown_graph', 'value' => 1, @@ -426,7 +376,7 @@ class ModuleGraph { 'label' => __('Show unknown graph') ); $ui->formAddCheckbox($options); - + $options = array( 'name' => 'avg_only', 'value' => 1, @@ -434,7 +384,7 @@ class ModuleGraph { 'label' => __('Avg Only') ); $ui->formAddCheckbox($options); - + $options = array( 'label' => __('Time range (hours)'), 'name' => 'period_hours', @@ -444,22 +394,21 @@ class ModuleGraph { 'step' => 4 ); $ui->formAddSlider($options); - - + $options = array( 'name' => 'start_date', 'value' => $this->start_date, 'label' => __('Begin date') ); $ui->formAddInpuDate($options); - + $options = array( 'icon' => 'refresh', 'icon_pos' => 'right', 'text' => __('Update graph') ); $ui->formAddSubmitButton($options); - + $html = $ui->getEndForm(); $ui->contentCollapsibleAddItem($html); $ui->contentEndCollapsible(); diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index 8e27312304..04f4e3f2d8 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -36,7 +36,6 @@ check_login (); $server_id = (int) get_parameter("server"); if (is_metaconsole() && !empty($server_id)) { $server = metaconsole_get_connection_by_id($server_id); - // Error connecting if (metaconsole_connect($server) !== NOERR) { echo ""; @@ -72,7 +71,6 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); $refresh = (int) get_parameter ("refresh", -1); if ($refresh > 0) { $query = ui_get_url_refresh (false); - echo ''; } ?> @@ -89,10 +87,10 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); window.onload = function() { // Hack to repeat the init process to period select var periodSelectId = $('[name="period"]').attr('class'); - + period_select_init(periodSelectId); }; - + function show_others() { if ($('#checkbox-avg_only').is(":checked") == true) { $("#hidden-show_other").val(1); @@ -118,18 +116,18 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); $id = (int) get_parameter ("id", 0); // Agent id $agent_id = (int) modules_get_agentmodule_agent($id); - + if (empty($id) || empty($agent_id)) { ui_print_error_message(__('There was a problem locating the source of the graph')); exit; } - + // ACL $permission = false; $agent_group = (int) agents_get_agent_group($agent_id); $strict_user = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); - + if (!empty($agent_group)) { if ($strict_user) { $permission = tags_check_acl_by_module($id, $config['id_user'], 'RR') === true; @@ -138,24 +136,24 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); $permission = check_acl($config['id_user'], $agent_group, "RR"); } } - + if (!$permission) { require ($config['homedir'] . "/general/noaccess.php"); exit; } - + $draw_alerts = get_parameter("draw_alerts", 0); if(isset($config['only_average'])){ $avg_only = $config['only_average']; } - + $show_other = get_parameter('show_other',-1); - + if ($show_other != -1) { $avg_only = $show_other; } - + $period = get_parameter ("period"); $id = get_parameter ("id", 0); $width = get_parameter ("width", STATWIN_DEFAULT_CHART_WIDTH); @@ -196,53 +194,42 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); // To avoid the horizontal overflow $width -= 20; - + $time_compare = false; - + if ($time_compare_separated) { $time_compare = 'separated'; } else if ($time_compare_overlapped) { $time_compare = 'overlapped'; } - + if ($zoom > 1) { $height = $height * ($zoom / 2.1); $width = $width * ($zoom / 1.4); } echo ""; - + // Build date $date = strtotime("$start_date $start_time"); $now = time(); - + if ($date > $now) $date = $now; - + $urlImage = ui_get_full_url(false, false, false, false); - + $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $id); - + // log4x doesnt support flash yet // if ($config['flash_charts'] == 1) echo '
'; else echo '
'; - + switch ($graph_type) { case 'boolean': - echo grafico_modulo_boolean ($id, $period, $draw_events, - $width, $height, $label_graph, $unit, $draw_alerts, - $avg_only, false, $date, false, $urlImage, - 'adapter_' . $graph_type, $time_compare, - $unknown_graph, true, $fullscale); - echo '
'; - if ($show_events_graph) - echo graphic_module_events($id, $width, $height, - $period, $config['homeurl'], $zoom, - 'adapted_' . $graph_type, $date, true); - break; case 'sparse': echo grafico_modulo_sparse ($id, $period, $draw_events, $width, $height, $label_graph, $unit, $draw_alerts, @@ -259,6 +246,7 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); 'adapted_' . $graph_type, $date, true); break; case 'string': + html_debug_print('entra x stats win hay que rehacer esta funcion'); echo grafico_modulo_string ($id, $period, $draw_events, $width, $height, $label_graph, null, $draw_alerts, 1, false, $date, false, $urlImage, @@ -269,21 +257,12 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); $period, $config['homeurl'], $zoom, 'adapted_' . $graph_type, $date, true); break; - case 'log4x': - echo grafico_modulo_log4x ($id, $period, $draw_events, - $width, $height, $label_graph, $unit, $draw_alerts, 1, - $pure, $date); - echo '
'; - if ($show_events_graph) - echo graphic_module_events($id, $width, $height, - $period, $config['homeurl'], $zoom, '', $date, true); - break; default: echo fs_error_image ('../images'); break; } echo '
'; - + //////////////////////////////////////////////////////////////// // SIDE MENU //////////////////////////////////////////////////////////////// @@ -293,22 +272,21 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); $params['top_text'] = "
" . html_print_image('images/wrench_blanco.png', true, array('width' => '16px'), false, false, true) . ' ' . __('Pandora FMS Graph configuration menu') . ui_print_help_icon ("graphs",true, $config["homeurl"], "images/help_w.png") . "
"; $params['body_text'] = "'; // outer - + // ICONS $params['icon_closed'] = '/images/graphmenu_arrow_hide.png'; $params['icon_open'] = '/images/graphmenu_arrow.png'; - + // SIZE $params['width'] = 500; - + // POSITION $params['position'] = 'left'; - + html_print_side_layer($params); - + // Hidden div to forced title html_print_div(array('id' => 'forced_title_layer', 'class' => 'forced_title_layer', 'hidden' => true)); ?> - + @@ -495,8 +473,7 @@ ui_include_time_picker(true); $('#checkbox-time_compare_overlapped').click(function() { $('#checkbox-time_compare_separated').removeAttr('checked'); }); - - + - + // Add datepicker and timepicker $("#text-start_date").datepicker({ dateFormat: "" @@ -542,14 +519,14 @@ ui_include_time_picker(true); currentText: '', closeText: '' }); - + $.datepicker.setDefaults($.datepicker.regional[""]); - + $(window).ready(function() { $("#field_list").css('height', ($(window).height() - 160) + 'px'); }); - + $(window).resize(function() { $("#field_list").css('height', ($(window).height() - 160) + 'px'); }); - + \ No newline at end of file From 51f22413a82b3f25b5be56a04c10be8244cb453f Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 28 Feb 2018 08:46:51 +0100 Subject: [PATCH 10/33] fixed errors in graphs --- pandora_console/include/functions_graph.php | 59 +++++++++++++------ pandora_console/include/graphs/fgraph.php | 6 +- .../include/graphs/flot/pandora.flot.js | 26 +++++++- .../include/graphs/functions_flot.php | 9 ++- 4 files changed, 75 insertions(+), 25 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 1925a836d7..51f6063d7c 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -359,6 +359,7 @@ function grafico_modulo_sparse_data( global $color; global $legend; global $series_type; + global $array_events_alerts; if($show_elements_graph['fullscale']){ $array_data = fullscale_data( @@ -483,25 +484,39 @@ function grafico_modulo_sparse_data( $events_array = array(); if($events && is_array($events)){ - $i=0; + $count_events=0; + $count_alerts=0; foreach ($events as $k => $v) { if (strpos($v["event_type"], "alert") !== false){ if($show_elements_graph['flag_overlapped']){ - $alerts_array['data'][$i] = array( ($v['utimestamp'] + $date_array['period'] *1000) , $max * 1.10); + $alerts_array['data'][$count_alerts] = array( + ($v['utimestamp'] + $date_array['period'] *1000), + $max * 1.10 + ); } else{ - $alerts_array['data'][$i] = array( ($v['utimestamp']*1000) , $max * 1.10); + $alerts_array['data'][$count_alerts] = array( + ($v['utimestamp']*1000), + $max * 1.10 + ); } + $count_alerts++; } else{ if($show_elements_graph['flag_overlapped']){ - $events_array['data'][$i] = array( ($v['utimestamp'] + $date_array['period'] *1000) , $max * 1.2); + $events_array['data'][$count_events] = array( + ($v['utimestamp'] + $date_array['period'] *1000), + $max * 1.2 + ); } else{ - $events_array['data'][$i] = array( ($v['utimestamp']*1000) , $max * 1.2); + $events_array['data'][$count_events] = array( + ($v['utimestamp']*1000), + $max * 1.2 + ); } + $count_events++; } - $i++; } } } @@ -532,9 +547,10 @@ function grafico_modulo_sparse_data( $caption = array(); } - //XXX - //$graph_stats = get_statwin_graph_statistics($chart, $series_suffix); - $color = color_graph_array($series_suffix, $show_elements_graph['flag_overlapped']); + $color = color_graph_array( + $series_suffix, + $show_elements_graph['flag_overlapped'] + ); foreach ($color as $k => $v) { if(is_array($array_data[$k])){ @@ -565,6 +581,8 @@ function grafico_modulo_sparse_data( break; } $series_type['percentil' . $series_suffix] = 'percentil'; + + $array_events_alerts[$series_suffix] = $events; } function grafico_modulo_sparse ($agent_module_id, $period, $show_events, @@ -585,12 +603,15 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, global $color; global $legend; global $series_type; + global $array_events_alerts; - $array_data = array(); - $caption = array(); - $color = array(); - $legend = array(); - $series_type = array(); + $array_data = array(); + $caption = array(); + $color = array(); + $legend = array(); + $series_type = array(); + + $array_events_alerts = array(); //date start final period if($date == 0){ @@ -751,6 +772,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, false ) ); + //esto la sparse //setup_watermark($water_mark, $water_mark_file, $water_mark_url); // Check available data @@ -767,7 +789,8 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $show_elements_graph, $format_graph, $water_mark, - $series_suffix_str + $series_suffix_str, + $array_events_alerts ); } else{ @@ -786,7 +809,8 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $show_elements_graph, $format_graph, $water_mark, - $series_suffix_str + $series_suffix_str, + $array_events_alerts ); } else{ @@ -806,7 +830,8 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $show_elements_graph, $format_graph, $water_mark, - $series_suffix_str + $series_suffix_str, + $array_events_alerts ); } else{ diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index ba185c9344..5ad02f9de4 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -206,7 +206,8 @@ function area_graph( $agent_module_id, $array_data, $color, $legend, $series_type, $date_array, $data_module_graph, $show_elements_graph, - $format_graph, $water_mark, $series_suffix_str + $format_graph, $water_mark, $series_suffix_str, + $array_events_alerts ) { global $config; @@ -224,7 +225,8 @@ function area_graph( $show_elements_graph, $format_graph, $water_mark, - $series_suffix_str + $series_suffix_str, + $array_events_alerts ); } else { diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 575e36d7f4..db66b2cb60 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1129,8 +1129,10 @@ function pandoraFlotArea( series_type, watermark, date_array, data_module_graph, show_elements_graph, format_graph, force_integer, series_suffix_str, - background_color, legend_color, short_data + background_color, legend_color, short_data, + events_array ) { + console.log(events_array); //diferents vars var unit = format_graph.unit ? format_graph.unit : ''; var homeurl = format_graph.homeurl; @@ -1190,12 +1192,20 @@ function pandoraFlotArea( i=0; $.each(values, function (index, value) { if (typeof value.data !== "undefined") { + if(index == 'alert') { + fill_color = '#ffff00'; + } + else if(index == 'events') { + fill_color = '#ff66cc'; + } switch (series_type[index]) { case 'area': line_show = true; points_show = false; // XXX - false filled = 0.2; steps_chart = false; + radius = false; + fill_points = ''; break; case 'percentil': case 'line': @@ -1204,12 +1214,16 @@ function pandoraFlotArea( points_show = false; filled = false; steps_chart = false; + radius = false; + fill_points = ''; break; case 'points': line_show = false; points_show = true; filled = false; - steps_chart = false + steps_chart = false; + radius = 3; + fill_points = fill_color; break; case 'unknown': case 'boolean': @@ -1217,6 +1231,8 @@ function pandoraFlotArea( points_show = false; filled = true; steps_chart = true; + radius = false; + fill_points = ''; break; } data_base.push({ @@ -1230,7 +1246,11 @@ function pandoraFlotArea( lineWidth: lineWidth, steps: steps_chart }, - points: { show: points_show } + points: { + show: points_show, + radius: radius, + fillColor: fill_points + } }); i++; } diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 8fcaf060a5..2e1a74bfa5 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -180,7 +180,8 @@ function flot_area_graph ( $agent_module_id, $array_data, $color, $legend, $series_type, $date_array, $data_module_graph, $show_elements_graph, - $format_graph, $water_mark, $series_suffix_str ) { + $format_graph, $water_mark, $series_suffix_str, + $array_events_alerts ) { global $config; @@ -326,6 +327,7 @@ function flot_area_graph ( $data_module_graph = json_encode($data_module_graph); $show_elements_graph = json_encode($show_elements_graph); $format_graph = json_encode($format_graph); + $array_events_alerts = json_encode($array_events_alerts); // Javascript code $return .= ""; From 3910b455ca7d50af8d612233638915f0aae00c00 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 28 Feb 2018 10:02:06 +0100 Subject: [PATCH 11/33] fixed errors --- pandora_console/include/functions_graph.php | 2 ++ .../include/graphs/flot/pandora.flot.js | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 51f6063d7c..4ceb8b520f 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -583,6 +583,8 @@ function grafico_modulo_sparse_data( $series_type['percentil' . $series_suffix] = 'percentil'; $array_events_alerts[$series_suffix] = $events; + + $data_module_graph['series_suffix'] = $series_suffix; } function grafico_modulo_sparse ($agent_module_id, $period, $show_events, diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index db66b2cb60..65638ad2f0 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1144,6 +1144,7 @@ function pandoraFlotArea( var dashboard = show_elements_graph.dashboard; var menu = show_elements_graph.menu; var max_x = date_array['final_date'] *1000; + var s_suffix = data_module_graph['series_suffix']; //for threshold var threshold = true; @@ -1192,12 +1193,19 @@ function pandoraFlotArea( i=0; $.each(values, function (index, value) { if (typeof value.data !== "undefined") { - if(index == 'alert') { + console.log(index); + console.log(s_suffix); + if(index == 'alert' + s_suffix) { + console.log('entra'); fill_color = '#ffff00'; } - else if(index == 'events') { + else if(index == 'event' + s_suffix) { + console.log('entra2'); fill_color = '#ff66cc'; } + else{ + fill_color = ''; + } switch (series_type[index]) { case 'area': line_show = true; @@ -1205,7 +1213,7 @@ function pandoraFlotArea( filled = 0.2; steps_chart = false; radius = false; - fill_points = ''; + fill_points = fill_color; break; case 'percentil': case 'line': @@ -1215,7 +1223,7 @@ function pandoraFlotArea( filled = false; steps_chart = false; radius = false; - fill_points = ''; + fill_points = fill_color; break; case 'points': line_show = false; @@ -1232,7 +1240,7 @@ function pandoraFlotArea( filled = true; steps_chart = true; radius = false; - fill_points = ''; + fill_points = fill_color; break; } data_base.push({ From 815e9c675997533b4f28e6b8fdcb301ad658d151 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 1 Mar 2018 09:46:52 +0100 Subject: [PATCH 12/33] fixed errors graph --- pandora_console/include/functions_graph.php | 9 +- .../include/graphs/flot/pandora.flot.js | 108 +++++++++++------- 2 files changed, 73 insertions(+), 44 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 4ceb8b520f..5572877cae 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -506,13 +506,13 @@ function grafico_modulo_sparse_data( if($show_elements_graph['flag_overlapped']){ $events_array['data'][$count_events] = array( ($v['utimestamp'] + $date_array['period'] *1000), - $max * 1.2 + $max * 1.15 ); } else{ $events_array['data'][$count_events] = array( ($v['utimestamp']*1000), - $max * 1.2 + $max * 1.15 ); } $count_events++; @@ -583,8 +583,6 @@ function grafico_modulo_sparse_data( $series_type['percentil' . $series_suffix] = 'percentil'; $array_events_alerts[$series_suffix] = $events; - - $data_module_graph['series_suffix'] = $series_suffix; } function grafico_modulo_sparse ($agent_module_id, $period, $show_events, @@ -777,6 +775,9 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, //esto la sparse //setup_watermark($water_mark, $water_mark_file, $water_mark_url); + + $data_module_graph['series_suffix'] = $series_suffix; + // Check available data if ($show_elements_graph['compare'] === 'separated') { if (!empty($array_data)) { diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 65638ad2f0..2015039c6e 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1132,7 +1132,6 @@ function pandoraFlotArea( background_color, legend_color, short_data, events_array ) { - console.log(events_array); //diferents vars var unit = format_graph.unit ? format_graph.unit : ''; var homeurl = format_graph.homeurl; @@ -1144,7 +1143,6 @@ function pandoraFlotArea( var dashboard = show_elements_graph.dashboard; var menu = show_elements_graph.menu; var max_x = date_array['final_date'] *1000; - var s_suffix = data_module_graph['series_suffix']; //for threshold var threshold = true; @@ -1193,19 +1191,16 @@ function pandoraFlotArea( i=0; $.each(values, function (index, value) { if (typeof value.data !== "undefined") { - console.log(index); - console.log(s_suffix); - if(index == 'alert' + s_suffix) { - console.log('entra'); - fill_color = '#ffff00'; + if(index.search("alert") >= 0){ + fill_color = '#ff7f00'; } - else if(index == 'event' + s_suffix) { - console.log('entra2'); - fill_color = '#ff66cc'; + else if(index.search("event") >= 0){ + fill_color = '#ff0000'; } else{ - fill_color = ''; + fill_color = 'green'; } + switch (series_type[index]) { case 'area': line_show = true; @@ -1230,7 +1225,7 @@ function pandoraFlotArea( points_show = true; filled = false; steps_chart = false; - radius = 3; + radius = 1.5; fill_points = fill_color; break; case 'unknown': @@ -2143,41 +2138,74 @@ function pandoraFlotArea( $('#' + graph_id).bind("plotclick", function (event, pos, item) { plot.unhighlight(); - if (item && item.series.label != '' && (item.series.label == legend_events || item.series.label == legend_events+series_suffix_str || item.series.label == legend_alerts || item.series.label == legend_alerts+series_suffix_str)) { + if(item && item.series.label != '' && + ( (item.series.label.search("alert") >= 0) || + (item.series.label.search("event") >= 0) ) + ){ plot.unhighlight(); - var dataset = plot.getData(); - var extra_info = 'No info to show'; - var extra_show = false; + $('#extra_'+graph_id).css('width', '170px'); + $('#extra_'+graph_id).css('height', '60px'); - var coord_x = (item.dataIndex/item.series.xaxis.datamax)* (event.target.clientWidth - event.target.offsetLeft + 1) + event.target.offsetLeft; + var dataset = plot.getData(); + var extra_info = 'No info to show'; + var extra_show = false; + var extra_height = $('#extra_'+graph_id).height(); + var extra_width = parseInt($('#extra_'+graph_id) + .css('width') + .split('px')[0]); + var events_data = new Array(); + var offset_graph = plot.getPlotOffset(); + var offset_relative = plot.offset(); + var width_graph = plot.width(); + var height_legend = $('#legend_' + graph_id).height(); + var coord_x = pos.pageX - offset_relative.left + offset_graph.left; + var coord_y = offset_graph.top + height_legend + extra_height; + if(coord_x + extra_width > width_graph){ + coord_x = coord_x - extra_width; + } + + var coord_y = offset_graph.top + height_legend + extra_height; $('#extra_'+graph_id).css('left',coord_x); - $('#extra_'+graph_id).css('top', event.target.offsetTop + 55 ); + $('#extra_'+graph_id).css('top', coord_y ); - switch(item.series.label) { - case legend_alerts+series_suffix_str: - case legend_alerts: - extra_info = ''+legend_alerts+':
From: '+labels_long[item.dataIndex]; - if (labels_long[item.dataIndex+1] != undefined) { - extra_info += '
To: '+labels_long[item.dataIndex+1]; - } - extra_info += '
'+get_event_details(alertsz[item.dataIndex]); - extra_show = true; - break; - case legend_events+series_suffix_str: - case legend_events: - extra_info = ''+legend_events+':
From: '+labels_long[item.dataIndex]; - if (labels_long[item.dataIndex+1] != undefined) { - extra_info += '
To: '+labels_long[item.dataIndex+1]; - } - extra_info += '
'+get_event_details(eventsz[item.dataIndex]); - extra_show = true; - break; - default: - return; - break; + if( (item.series.label.search("alert") >= 0) || + (item.series.label.search("event") >= 0) ){ + + $.each(events_array, function (i, v) { + $.each(v, function (index, value) { + if((value.utimestamp) == item.datapoint[0]/1000){ + events_data = value; + } + }); + }); + + if(events_data.event_type.search("alert") >= 0){ + $extra_color = '#FFA631'; + } + else if(events_data.event_type.search("critical") >= 0){ + $extra_color = '#FC4444'; + } + else if(events_data.event_type.search("warning") >= 0){ + $extra_color = '#FAD403'; + } + else if(events_data.event_type.search("unknown") >= 0){ + $extra_color = '#3BA0FF'; + } + else if(events_data.event_type.search("normal") >= 0){ + $extra_color = '#80BA27'; + } + else{ + $extra_color = '#ffffff'; + } + + $('#extra_'+graph_id).css('background-color',$extra_color); + + extra_info = ''+events_data.evento+':'; + extra_info += '

Time: '+events_data.timestamp; + extra_show = true; } if (extra_show) { From 3fbd9adc3867e18cf2c50e7d73c3c1d060ee4081 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 24 Apr 2018 13:19:24 +0200 Subject: [PATCH 13/33] fixed graph --- pandora_console/include/functions_graph.php | 7 +- pandora_console/include/graphs/fgraph.php | 26 ++-- .../include/graphs/flot/pandora.flot.js | 121 +++++++++--------- .../include/graphs/functions_flot.php | 17 +-- pandora_console/include/styles/pandora.css | 3 +- pandora_console/mobile/include/style/main.css | 4 - .../operation/agentes/stat_win.php | 22 ++-- 7 files changed, 94 insertions(+), 106 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 3a534f15de..74e8e52886 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -679,13 +679,14 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, // ATTENTION: The min size is in constants.php // It's not the same minsize for all graphs, but we are choosed a prudent minsize for all + /* if ($height <= CHART_DEFAULT_HEIGHT) { $height = CHART_DEFAULT_HEIGHT; } if ($width < CHART_DEFAULT_WIDTH) { $width = CHART_DEFAULT_WIDTH; } - + */ $format_graph = array(); $format_graph['width'] = $width; $format_graph['height'] = $height; @@ -2367,10 +2368,6 @@ function fullscale_data_combined($module_list, $period, $date, $flash_charts, $p foreach ($data_uncompress as $key_data => $value_data) { foreach ($value_data['data'] as $k => $v) { $real_date = $v['utimestamp']; -<<<<<<< HEAD - -======= ->>>>>>> origin/develop if(!isset($v['datos'])){ $v['datos'] = $previous_data; } diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 347aeb37d1..6feb3f700b 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -251,20 +251,20 @@ function area_graph( //XXXXX //Corregir este problema $graph = array(); - $graph['data'] = $chart_data; - $graph['width'] = $width; - $graph['height'] = $height; - $graph['color'] = $color; - $graph['legend'] = $legend; - $graph['xaxisname'] = $xaxisname; - $graph['yaxisname'] = $yaxisname; - $graph['water_mark'] = $water_mark_file; - $graph['font'] = $font; - $graph['font_size'] = $font_size; + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + $graph['xaxisname'] = $xaxisname; + $graph['yaxisname'] = $yaxisname; + $graph['water_mark'] = $water_mark_file; + $graph['font'] = $font; + $graph['font_size'] = $font_size; $graph['backgroundColor'] = $backgroundColor; - $graph['unit'] = $unit; - $graph['series_type'] = $series_type; - $graph['percentil'] = $percentil_values; + $graph['unit'] = $unit; + $graph['series_type'] = $series_type; + $graph['percentil'] = $percentil_values; $id_graph = serialize_in_temp($graph, null, $ttl); // Warning: This string is used in the function "api_get_module_graph" from 'functions_api.php' with the regec patern "//" diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 6f1c069158..60f7547dcd 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -959,12 +959,6 @@ function adjust_left_width_canvas(adapter_id, adapted_id) { $('#'+adapted_id).css('margin-left', adapter_left_margin); } - -function update_left_width_canvas(graph_id) { - $('#overview_'+graph_id).width($('#'+graph_id).width()); - $('#overview_'+graph_id).css('margin-left', $('#'+graph_id+' .yAxis .tickLabel').width()); -} - function check_adaptions(graph_id) { var classes = $('#'+graph_id).attr('class').split(' '); @@ -1132,6 +1126,7 @@ function pandoraFlotArea( background_color, legend_color, short_data, events_array ) { + console.log(format_graph.font_size); //diferents vars var unit = format_graph.unit ? format_graph.unit : ''; var homeurl = format_graph.homeurl; @@ -1156,8 +1151,6 @@ function pandoraFlotArea( //XXXX ver que hay que hacer var type = 'area_simple'; - //var xaxisname = 'xaxisname'; - var labels_long = ''; var min_check = 0; var water_mark = ''; @@ -1784,7 +1777,7 @@ function pandoraFlotArea( // The first execution, the graph data is the base data datas = data_base; - + font_size = 8; // minTickSize var count_data = datas[0].data.length; var min_tick_pixels = 80; @@ -1799,7 +1792,7 @@ function pandoraFlotArea( mode: 'xy' }, selection: { - mode: 'x', + mode: 'xy', color: '#777' }, export: { @@ -1885,38 +1878,48 @@ function pandoraFlotArea( var overview = $.plot($('#overview_'+graph_id),datas, { series: { stack: stacked, - lines: { - show: true, - lineWidth: 1 - }, - shadowSize: 0 + shadowSize: 0.1 + }, + crosshair: { + mode: 'xy' + }, + selection: { + mode: 'xy', + color: '#777' + }, + export: { + export_data: true, + labels_long: labels_long, + homeurl: homeurl }, grid: { - borderWidth: 1, - borderColor: '#C1C1C1', hoverable: true, - autoHighlight: false + clickable: true, + borderWidth:1, + borderColor: '#C1C1C1', + tickColor: background_color, + color: legend_color }, - xaxes: [ { + xaxes: [{ axisLabelFontSizePixels: font_size, mode: "time", tickFormatter: xFormatter, tickSize: [maxticks, 'hour'], - labelWidth: 70, - } ], - yaxis: { - ticks: [], - autoscaleMargin: 0.1 - }, - selection: { - mode: 'x', - color: '#777' - }, + labelWidth: 70 + }], + yaxes: [{ + tickFormatter: yFormatter, + color: '', + alignTicksWithAxis: 1, + labelWidth: 30, + position: 'left', + font: font, + reserveSpace: true, + }], legend: { - show: false - }, - crosshair: { - mode: 'x' + position: 'se', + container: $('#legend_' + graph_id), + labelFormatter: lFormatter } }); } @@ -1954,6 +1957,19 @@ function pandoraFlotArea( tickFormatter: xFormatter, tickSize: [maxticks_zoom, 'hour'] }], + yaxis:{ + min: ranges.yaxis.from, + max: ranges.yaxis.to + }, + yaxes: [{ + tickFormatter: yFormatter, + color: '', + alignTicksWithAxis: 1, + labelWidth: 30, + position: 'left', + font: font, + reserveSpace: true, + }], legend: { show: true } @@ -2121,7 +2137,6 @@ function pandoraFlotArea( plot.setCrosshair({ x: pos.x, y: 0 }); currentPlot = plot; latestPosition = pos; - if (!updateLegendTimeout) { updateLegendTimeout = setTimeout(updateLegend, 50); } @@ -2285,31 +2300,20 @@ function pandoraFlotArea( if (menu) { var parent_height; $('#menu_overview_' + graph_id).click(function() { - $('#overview_' + graph_id).toggle(); + if($('#overview_' + graph_id).css('visibility') == 'visible'){ + $('#overview_' + graph_id).css('visibility', 'hidden'); + } + else{ + $('#overview_' + graph_id).css('visibility', 'visible'); + } }); - //~ $('#menu_export_csv_' + graph_id).click(function() { - //~ exportData({ type: 'csv' }); - //~ }); - $("#menu_export_csv_"+graph_id) .click(function (event) { event.preventDefault(); plot.exportDataCSV(); }); - //Not a correct call - //~ $('#menu_export_json_' + graph_id).click(function() { - //~ exportData({ type: 'json' }); - //~ }); - - //This is a correct call to export data in json - //~ $("#menu_export_json_"+graph_id) - //~ .click(function (event) { - //~ event.preventDefault(); - //~ plot.exportDataJSON(); - //~ }); - $('#menu_threshold_' + graph_id).click(function() { datas = new Array(); @@ -2408,12 +2412,6 @@ function adjust_menu(graph_id, plot, parent_height, width) { var parent_height_new = 0; var legend_height = parseInt($('#legend_'+graph_id).css('height').split('px')[0]) + parseInt($('#legend_'+graph_id).css('margin-top').split('px')[0]); - if ($('#overview_'+graph_id).css('display') == 'none') { - overview_height = 0; - } - else { - overview_height = parseInt($('#overview_'+graph_id).css('height').split('px')[0]) + parseInt($('#overview_'+graph_id).css('margin-top').split('px')[0]); - } var menu_height = '25'; @@ -2422,13 +2420,9 @@ function adjust_menu(graph_id, plot, parent_height, width) { } offset = $('#' + graph_id)[0].offsetTop; - + $('#menu_' + graph_id).css('top', ((offset) + 'px')); - //$('#legend_' + graph_id).css('width',plot.width()); - - //~ $('#menu_' + graph_id).css('left', $('#'+graph_id)[0].offsetWidth); - $('#menu_' + graph_id).show(); } @@ -2498,9 +2492,8 @@ function adjust_left_width_canvas(adapter_id, adapted_id) { $('#'+adapted_id).css('margin-left', adapter_left_margin); } - function update_left_width_canvas(graph_id) { - $('#overview_'+graph_id).width($('#'+graph_id).width() - 30); + $('#overview_'+graph_id).width($('#'+graph_id).width()); $('#overview_'+graph_id).css('margin-left', $('#'+graph_id+' .yAxis .tickLabel').width()); } diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 8a00b5ee69..edc782f654 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -205,7 +205,7 @@ function flot_area_graph ( } // Parent layer - $return = "
"; + $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "

"; @@ -260,13 +260,14 @@ function flot_area_graph ( } if (!$vconsole){ - $return .= "
"; + $return .= "
"; } + //XXXXTODO $water_mark = ''; if ($water_mark != '') { @@ -377,7 +378,7 @@ function menu_graph( $return .= ""; } //XXXXTODO diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index c56f855d6e..8252ff8c90 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -55,11 +55,11 @@ if (file_exists ('../../include/languages/'.$user_language.'.mo')) { echo ''; -$label = get_parameter('label'); -$label = base64_decode($label); -$id = get_parameter('id'); +$label = get_parameter('label'); +$label = base64_decode($label); +$id = get_parameter('id'); $id_agent = db_get_value ("id_agente","tagente_modulo","id_agente_modulo",$id); -$alias = db_get_value ("alias","tagente","id_agente",$id_agent); +$alias = db_get_value ("alias","tagente","id_agente",$id_agent); //$agent = agents_get_agent_with_ip ("192.168.50.31"); //$label = rawurldecode(urldecode(base64_decode(get_parameter('label', '')))); ?> @@ -121,7 +121,7 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); } // ACL - $permission = false; + $permission = false; $agent_group = (int) agents_get_agent_group($agent_id); $strict_user = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); @@ -153,14 +153,13 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); } $period = get_parameter ("period"); - $id = get_parameter ("id", 0); - + $id = get_parameter ("id", 0); + //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX /* $width = get_parameter ("width", STATWIN_DEFAULT_CHART_WIDTH); $height = get_parameter ("height", STATWIN_DEFAULT_CHART_HEIGHT); */ - $label = get_parameter ("label", ""); $label_graph = base64_decode(get_parameter ("label", "")); @@ -212,7 +211,6 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); $height = $height * ($zoom / 2.1); $width = $width * ($zoom / 1.4); } - echo ""; // Build date $date = strtotime("$start_date $start_time"); @@ -480,37 +478,6 @@ ui_include_time_picker(true); $('#checkbox-time_compare_separated').removeAttr('checked'); }); - - var show_overview = false; - var height_window; - var width_window; - - $(window).ready(function() { - height_window = window.innerHeight; - width_window = window.innerWidth; - }); - - $("*").filter(function() { - if (typeof(this.id) == "string") - return this.id.match(/menu_overview_graph.*/); - else - return false; - }).click(function() { - if (show_overview) { - window.resizeTo(width_window, height_window); - } - else { - window.resizeTo(width_window, height_window + 150); - } - show_overview = !show_overview; - }); - - // Add datepicker and timepicker $("#text-start_date").datepicker({ dateFormat: "" From 30dc841bae259ab275082b22414e62b37b0a1f92 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 27 Apr 2018 10:03:05 +0200 Subject: [PATCH 15/33] custom graph --- pandora_console/include/functions.php | 161 +- .../include/functions_custom_graphs.php | 26 +- pandora_console/include/functions_graph.php | 1321 +++++------------ .../include/graphs/functions_flot.php | 10 +- 4 files changed, 477 insertions(+), 1041 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index ab5c20154f..edcb7c9034 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2818,6 +2818,95 @@ function color_graph_array($series_suffix, $compare = false){ ////////////////////////////////////////////////// // Color commented not to restrict serie colors // ////////////////////////////////////////////////// + $color_series = array(); + $color_series[0] = array( + 'border' => '#000000', + 'color' => $config['graph_color1'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[1] = array( + 'border' => '#000000', + 'color' => $config['graph_color2'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[2] = array( + 'border' => '#000000', + 'color' => $config['graph_color3'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[3] = array( + 'border' => '#000000', + 'color' => $config['graph_color4'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[4] = array( + 'border' => '#000000', + 'color' => $config['graph_color5'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[5] = array( + 'border' => '#000000', + 'color' => $config['graph_color6'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[6] = array( + 'border' => '#000000', + 'color' => $config['graph_color7'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[7] = array( + 'border' => '#000000', + 'color' => $config['graph_color8'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[8] = array( + 'border' => '#000000', + 'color' => $config['graph_color9'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[9] = array( + 'border' => '#000000', + 'color' => $config['graph_color10'], + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[11] = array( + 'border' => '#000000', + 'color' => COL_GRAPH9, + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[12] = array( + 'border' => '#000000', + 'color' => COL_GRAPH10, + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[13] = array( + 'border' => '#000000', + 'color' => COL_GRAPH11, + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[14] = array( + 'border' => '#000000', + 'color' => COL_GRAPH12, + 'alpha' => CHART_DEFAULT_ALPHA + ); + $color_series[15] = array( + 'border' => '#000000', + 'color' => COL_GRAPH13, + 'alpha' => CHART_DEFAULT_ALPHA + ); + + +/* + if($id_widget_dashboard){ + $opcion = unserialize(db_get_value_filter('options','twidget_dashboard',array('id' => $id_widget_dashboard))); + foreach ($module_list as $key => $value) { + if(!empty($opcion[$value])){ + $color[$key]['color'] = $opcion[$value]; + } + } + } +*/ + if(!$compare) { $color['event' . $series_suffix] = array( 'border' => '#ff0000', @@ -2843,23 +2932,8 @@ function color_graph_array($series_suffix, $compare = false){ 'alpha' => CHART_DEFAULT_ALPHA ); - $color['max'.$series_suffix] = - array( 'border' => '#000000', - 'color' => $config['graph_color3'], - 'alpha' => CHART_DEFAULT_ALPHA - ); - $color['sum'.$series_suffix] = - array( 'border' => '#000000', - 'color' => $config['graph_color2'], - 'alpha' => CHART_DEFAULT_ALPHA - ); - - $color['min'.$series_suffix] = - array( 'border' => '#000000', - 'color' => $config['graph_color1'], - 'alpha' => CHART_DEFAULT_ALPHA - ); + $color_series[$series_suffix]; $color['unit'.$series_suffix] = array( 'border' => null, @@ -2898,23 +2972,8 @@ function color_graph_array($series_suffix, $compare = false){ 'alpha' => CHART_DEFAULT_ALPHA ); - $color['max'.$series_suffix] = - array( 'border' => '#000000', - 'color' => $config['graph_color3'], - 'alpha' => CHART_DEFAULT_ALPHA - ); - $color['sum'.$series_suffix] = - array( 'border' => '#000000', - 'color' => '#b781c1', - 'alpha' => CHART_DEFAULT_ALPHA - ); - - $color['min'.$series_suffix] = - array( 'border' => '#000000', - 'color' => $config['graph_color1'], - 'alpha' => CHART_DEFAULT_ALPHA - ); + $color_series[$series_suffix]; $color['unit'.$series_suffix] = array( 'border' => null, @@ -2927,7 +2986,6 @@ function color_graph_array($series_suffix, $compare = false){ 'color' => '#003333', 'alpha' => CHART_DEFAULT_ALPHA ); - } return $color; @@ -2946,8 +3004,15 @@ function legend_graph_array( global $legend; $unit = $format_graph['unit']; - $legend['sum'.$series_suffix] = - $data_module_graph['module_name'] . ' ' . + if (isset($show_elements_graph['labels']) && is_array($show_elements_graph['labels'])){ + $legend['sum'.$series_suffix] = $show_elements_graph['labels'][$data_module_graph['module_id']] . ' ' ; + } + else{ + $legend['sum'.$series_suffix] = $data_module_graph['agent_name'] . ' / ' . + $data_module_graph['module_name'] . ': '; + } + + $legend['sum'.$series_suffix] .= __('Min:') . remove_right_zeros( number_format( $min, @@ -2977,13 +3042,25 @@ function legend_graph_array( $legend['alert'.$series_suffix] = __('Alert') . ' ' . $series_suffix_str; } if($show_elements_graph['percentil']){ - $legend['percentil'.$series_suffix] = __('Percentil') . ' Value: ' . - remove_right_zeros( - number_format( - $percentil_value, - $config['graph_precision'] - ) - ) . ' ' . $series_suffix_str; + $legend['percentil'.$series_suffix] = + __('Percentil') . ' ' . + $config['percentil'] . + 'º ' . __('of module') . ' '; + + if (isset($show_elements_graph['labels']) && is_array($show_elements_graph['labels'])){ + $legend['percentil'.$series_suffix] .= $show_elements_graph['labels'][$data_module_graph['module_id']] . ' ' ; + } + else{ + $legend['percentil'.$series_suffix] .= $data_module_graph['agent_name'] . ' / ' . + $data_module_graph['module_name'] . ': ' . ' Value: '; + } + + $legend['percentil'.$series_suffix] .= remove_right_zeros( + number_format( + $percentil_value, + $config['graph_precision'] + ) + ) . ' ' . $series_suffix_str; } return $legend; diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index e61b8cf09d..83ffb6e290 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -168,9 +168,8 @@ function custom_graphs_print($id_graph, $height, $width, $period, $dashboard = false, $vconsole = false, $percentil = null, $from_interface = false,$id_widget_dashboard=false, $fullscale = false) { - html_debug_print('esta en esta otro arch'); global $config; - + if ($from_interface) { if ($config["type_interface_charts"] == 'line') { $graph_conf['stacked'] = CUSTOM_GRAPH_LINE; @@ -187,29 +186,29 @@ function custom_graphs_print($id_graph, $height, $width, $period, $graph_conf = db_get_row('tgraph', 'id_graph', $id_graph); } } - + if ($stacked === null) { $stacked = $graph_conf['stacked']; } - + $sources = false; if ($id_graph == 0) { $modules = $modules_param; $count_modules = count($modules); $weights = array_fill(0, $count_modules, 1); - + if ($count_modules > 0) $sources = true; } else { $sources = db_get_all_rows_field_filter('tgraph_source', 'id_graph', $id_graph); - + $series = db_get_all_rows_sql('SELECT summatory_series,average_series,modules_series FROM tgraph WHERE id_graph = '.$id_graph); $summatory = $series[0]['summatory_series']; $average = $series[0]['average_series']; $modules_series = $series[0]['modules_series']; - + $modules = array (); $weights = array (); $labels = array (); @@ -224,22 +223,21 @@ function custom_graphs_print($id_graph, $height, $width, $period, } } } - - + if ($sources === false) { if ($return){ return false; } - else{ + else{ ui_print_info_message ( array ( 'no_close' => true, 'message' => __('No items.') ) ); return; } } - + if (empty($homeurl)) { $homeurl = ui_get_full_url(false, false, false, false); } - + $output = graphic_combined_module($modules, $weights, $period, @@ -273,8 +271,8 @@ function custom_graphs_print($id_graph, $height, $width, $period, $fullscale, $summatory, $average, - $modules_series); - + $modules_series); + if ($return) return $output; echo $output; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 51b67ecf68..8a749ee4aa 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1072,8 +1072,8 @@ function graph_get_formatted_date($timestamp, $format1, $format2) { * @param bool Show the max value of the item on the list. * @param bool Show the min value of the item on the list. * @param bool Show the average value of the item on the list. - * - * @return Mixed + * + * @return Mixed */ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $height, $title, $unit_name, $show_events = 0, $show_alerts = 0, $pure = 0, $stacked = 0, $date = 0, $only_image = false, $homeurl = '', @@ -1085,12 +1085,11 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, global $config; global $graphic_type; global $legend; - global $array_data; + global $series_type; - $array_data = array(); - $legend = array(); - $caption = array(); - $series_type = array(); + $legend = array(); + $caption = array(); + $series_type = array(); //date start final period if($date == 0){ @@ -1099,7 +1098,6 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, //XXX colocar /* - $weight_list $stacked $prediction_period $name_list @@ -1108,13 +1106,17 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $show_max $show_min $show_avg - $labels $from_interface $summatory $average $modules_series */ +html_debug_print($stacked); +html_debug_print($name_list); +html_debug_print($unit_list); +html_debug_print($from_interface); + $date_array = array(); $date_array["period"] = $period; $date_array["final_date"] = $date; @@ -1147,8 +1149,7 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $show_elements_graph['only_image'] = $only_image; $show_elements_graph['return_data'] = true; //dont use $show_elements_graph['id_widget'] = $id_widget_dashboard; - - + $show_elements_graph['labels'] = $labels; $format_graph = array(); $format_graph['width'] = $width; @@ -1166,8 +1167,24 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $format_graph['font'] = $config['fontpath']; $format_graph['font-size'] = $config['font_size']; + /* + $user = users_get_user_by_id($config['id_user']); + $user_flash_charts = $user['flash_chart']; + + if ($user_flash_charts == 1) + $flash_charts = true; + elseif($user_flash_charts == -1) + $flash_charts = $config['flash_charts']; + elseif($user_flash_charts == 0) + $flash_charts = false; + + if ($only_image) { + $flash_charts = false; + } + */ $i=0; + $array_data = array(); foreach ($module_list as $key => $agent_module_id) { $module_data = db_get_row_sql ( @@ -1190,8 +1207,10 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $data_module_graph['c_min'] = $module_data['min_critical']; $data_module_graph['c_max'] = $module_data['max_critical']; $data_module_graph['c_inv'] = $module_data['critical_inverse']; + $data_module_graph['module_id'] = $agent_module_id; - grafico_modulo_sparse_data( + //stract data + $array_data_module = grafico_modulo_sparse_data( $agent_module_id, $date_array, $data_module_graph, @@ -1205,6 +1224,16 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $series_suffix = $i; $series_suffix_str = ''; + //convert to array graph and weight + foreach ($array_data_module as $key => $value) { + $array_data[$key] = $value; + if($weight_list[$i] > 1){ + foreach ($value['data'] as $k => $v) { + $array_data[$key]['data'][$k][1] = $v[1] * $weight_list[$i]; + } + } + } + $max = $array_data['sum' . $i]['max']; $min = $array_data['sum' . $i]['min']; $avg = $array_data['sum' . $i]['avg']; @@ -1237,59 +1266,297 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $data_module_graph ); + if($config["fixed_graph"] == false){ + $water_mark = array( + 'file' => $config['homedir'] . "/images/logo_vertical_water.png", + 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); + } + + //Work around for fixed the agents name with huge size chars. + $fixed_font_size = $config['font_size']; + //$array_events_alerts[$series_suffix] = $events; $i++; } - html_debug_print($legend); - html_debug_print($series_type); -/* - foreach ($data_array_prepare as $key => $value) { - foreach ($value as $k => $v) { - $data_array[$k] = $v; - } + if ($flash_charts === false && $stacked == CUSTOM_GRAPH_GAUGE) + $stacked = CUSTOM_GRAPH_BULLET_CHART; + + switch ($stacked) { + case CUSTOM_GRAPH_BULLET_CHART_THRESHOLD: + case CUSTOM_GRAPH_BULLET_CHART: + $datelimit = $date - $period; + if($stacked == CUSTOM_GRAPH_BULLET_CHART_THRESHOLD){ + $acumulador = 0; + foreach ($module_list as $module_item) { + $module = $module_item; + $query_last_value = sprintf(' + SELECT datos + FROM tagente_datos + WHERE id_agente_modulo = %d + AND utimestamp < %d + ORDER BY utimestamp DESC', + $module, $date); + $temp_data = db_get_value_sql($query_last_value); + if ($acumulador < $temp_data){ + $acumulador = $temp_data; + } + } + } + foreach ($module_list as $module_item) { + $automatic_custom_graph_meta = false; + if ($config['metaconsole']) { + // Automatic custom graph from the report template in metaconsole + if (is_array($module_list[$i])) { + $server = metaconsole_get_connection_by_id ($module_item['server']); + metaconsole_connect($server); + $automatic_custom_graph_meta = true; + } + } + + if ($automatic_custom_graph_meta) + $module = $module_item['module']; + else + $module = $module_item; + + $search_in_history_db = db_search_in_history_db($datelimit); + + $temp[$module] = modules_get_agentmodule($module); + $query_last_value = sprintf(' + SELECT datos + FROM tagente_datos + WHERE id_agente_modulo = %d + AND utimestamp < %d + ORDER BY utimestamp DESC', + $module, $date); + $temp_data = db_get_value_sql($query_last_value); + + if ($temp_data) { + if (is_numeric($temp_data)) + $value = $temp_data; + else + $value = count($value); + } + else { + if ($flash_charts === false) + $value = 0; + else + $value = false; + } + + if ( !empty($labels) && isset($labels[$module]) ){ + $label = io_safe_input($labels[$module]); + }else{ + $alias = db_get_value ("alias","tagente","id_agente",$temp[$module]['id_agente']); + $label = $alias . ': ' . $temp[$module]['nombre']; + } + + $temp[$module]['label'] = $label; + $temp[$module]['value'] = $value; + $temp_max = reporting_get_agentmodule_data_max($module,$period,$date); + if ($temp_max < 0) + $temp_max = 0; + if (isset($acumulador)){ + $temp[$module]['max'] = $acumulador; + }else{ + $temp[$module]['max'] = ($temp_max === false) ? 0 : $temp_max; + } + + $temp_min = reporting_get_agentmodule_data_min($module,$period,$date); + if ($temp_min < 0) + $temp_min = 0; + $temp[$module]['min'] = ($temp_min === false) ? 0 : $temp_min; + + if ($config['metaconsole']) { + // Automatic custom graph from the report template in metaconsole + if (is_array($module_list[0])) { + metaconsole_restore_db(); + } + } + + } + + break; + case CUSTOM_GRAPH_HBARS: + case CUSTOM_GRAPH_VBARS: + $datelimit = $date - $period; + + $label = ''; + foreach ($module_list as $module_item) { + $automatic_custom_graph_meta = false; + if ($config['metaconsole']) { + // Automatic custom graph from the report template in metaconsole + if (is_array($module_list[$i])) { + $server = metaconsole_get_connection_by_id ($module_item['server']); + metaconsole_connect($server); + $automatic_custom_graph_meta = true; + } + } + + if ($automatic_custom_graph_meta) + $module = $module_item['module']; + else + $module = $module_item; + + $module_data = modules_get_agentmodule($module); + $query_last_value = sprintf(' + SELECT datos + FROM tagente_datos + WHERE id_agente_modulo = %d + AND utimestamp < %d + ORDER BY utimestamp DESC', + $module, $date); + $temp_data = db_get_value_sql($query_last_value); + + $agent_name = io_safe_output( + modules_get_agentmodule_agent_name ($module)); + + if (!empty($labels) && isset($labels[$module]) ){ + $label = $labels[$module]; + }else { + $alias = db_get_value ("alias","tagente","id_agente",$module_data['id_agente']); + $label = $alias . " - " .$module_data['nombre']; + } + + $temp[$label]['g'] = round($temp_data,4); + + if ($config['metaconsole']) { + // Automatic custom graph from the report template in metaconsole + if (is_array($module_list[0])) { + metaconsole_restore_db(); + } + } + } + break; + case CUSTOM_GRAPH_PIE: + $datelimit = $date - $period; + $total_modules = 0; + foreach ($module_list as $module_item) { + $automatic_custom_graph_meta = false; + if ($config['metaconsole']) { + // Automatic custom graph from the report template in metaconsole + if (is_array($module_list[$i])) { + $server = metaconsole_get_connection_by_id ($module_item['server']); + metaconsole_connect($server); + $automatic_custom_graph_meta = true; + } + } + + if ($automatic_custom_graph_meta) + $module = $module_item['module']; + else + $module = $module_item; + + $data_module = modules_get_agentmodule($module); + $query_last_value = sprintf(' + SELECT datos + FROM tagente_datos + WHERE id_agente_modulo = %d + AND utimestamp > %d + AND utimestamp < %d + ORDER BY utimestamp DESC', + $module, $datelimit, $date); + $temp_data = db_get_value_sql($query_last_value); + + if ( $temp_data ){ + if (is_numeric($temp_data)) + $value = $temp_data; + else + $value = count($value); + } + else { + $value = false; + } + $total_modules += $value; + + if ( !empty($labels) && isset($labels[$module]) ){ + $label = io_safe_output($labels[$module]); + }else { + $alias = db_get_value ("alias","tagente","id_agente",$data_module['id_agente']); + $label = io_safe_output($alias . ": " . $data_module['nombre']); + } + + $temp[$label] = array('value'=>$value, + 'unit'=>$data_module['unit']); + if ($config['metaconsole']) { + // Automatic custom graph from the report template in metaconsole + if (is_array($module_list[0])) { + metaconsole_restore_db(); + } + } + } + $temp['total_modules'] = $total_modules; + + break; + case CUSTOM_GRAPH_GAUGE: + $datelimit = $date - $period; + $i = 0; + foreach ($module_list as $module_item) { + $automatic_custom_graph_meta = false; + if ($config['metaconsole']) { + // Automatic custom graph from the report template in metaconsole + if (is_array($module_list[$i])) { + $server = metaconsole_get_connection_by_id ($module_item['server']); + metaconsole_connect($server); + $automatic_custom_graph_meta = true; + } + } + + if ($automatic_custom_graph_meta) + $module = $module_item['module']; + else + $module = $module_item; + + $temp[$module] = modules_get_agentmodule($module); + $query_last_value = sprintf(' + SELECT datos + FROM tagente_datos + WHERE id_agente_modulo = %d + AND utimestamp < %d + ORDER BY utimestamp DESC', + $module, $date); + $temp_data = db_get_value_sql($query_last_value); + if ( $temp_data ) { + if (is_numeric($temp_data)) + $value = $temp_data; + else + $value = count($value); + } + else { + $value = false; + } + $temp[$module]['label'] = ($labels[$module] != '') ? $labels[$module] : $temp[$module]['nombre']; + + $temp[$module]['value'] = $value; + $temp[$module]['label'] = ui_print_truncate_text($temp[$module]['label'],"module_small",false,true,false,".."); + + if ($temp[$module]['unit'] == '%') { + $temp[$module]['min'] = 0; + $temp[$module]['max'] = 100; + } + else { + $min = $temp[$module]['min']; + if ($temp[$module]['max'] == 0) + $max = reporting_get_agentmodule_data_max($module,$period,$date); + else + $max = $temp[$module]['max']; + $temp[$module]['min'] = ($min == 0 ) ? 0 : $min; + $temp[$module]['max'] = ($max == 0 ) ? 100 : $max; + } + $temp[$module]['gauge'] = uniqid('gauge_'); + + if ($config['metaconsole']) { + // Automatic custom graph from the report template in metaconsole + if (is_array($module_list[0])) { + metaconsole_restore_db(); + } + } + $i++; + } + break; + default: + break; } -*/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1323,19 +1590,6 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $names_number = count($name_list); $units_number = count($unit_list); -*/ - // interval - This is the number of "rows" we are divided the time to fill data. - // more interval, more resolution, and slower. - // periodo - Gap of time, in seconds. This is now to (now-periodo) secs - // Init weights - for ($i = 0; $i < $module_number; $i++) { - if (! isset ($weight_list[$i])) { - $weight_list[$i] = 1; - } - else if ($weight_list[$i] == 0) { - $weight_list[$i] = 1; - } - } $aux_array = array(); // Set data containers @@ -1344,7 +1598,7 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $timestamp_short = date($time_format, $timestamp); $long_index[$timestamp_short] = date( html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp); - $timestamp = $timestamp_short;*/ + $timestamp = $timestamp_short;* $graph[$timestamp]['count'] = 0; $graph[$timestamp]['timestamp_bottom'] = $timestamp; $graph[$timestamp]['timestamp_top'] = $timestamp + $interval; @@ -1358,841 +1612,42 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $graph_values = array(); $module_name_list = array(); $collector = 0; - $user = users_get_user_by_id($config['id_user']); - $user_flash_charts = $user['flash_chart']; - if ($user_flash_charts == 1) - $flash_charts = true; - elseif($user_flash_charts == -1) - $flash_charts = $config['flash_charts']; - elseif($user_flash_charts == 0) - $flash_charts = false; - if ($only_image) { - $flash_charts = false; - } - // Calculate data for each module - for ($i = 0; $i < $module_number; $i++) { - $automatic_custom_graph_meta = false; - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id ($module_list[$i]['server']); - metaconsole_connect($server); - $automatic_custom_graph_meta = true; - } - } - $search_in_history_db = db_search_in_history_db($datelimit); - - // If its a projection graph, - // first module will be data and second will be the projection - - if ($projection != false && $i != 0) { - if ($automatic_custom_graph_meta) - $agent_module_id = $module_list[0]['module']; - else - $agent_module_id = $module_list[0]; - $id_module_type = modules_get_agentmodule_type ($agent_module_id); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - } - else { - if ($automatic_custom_graph_meta) - $agent_module_id = $module_list[$i]['module']; - else - $agent_module_id = $module_list[$i]; - - $id_module_type = modules_get_agentmodule_type ($agent_module_id); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - } - - if ($uncompressed_module) { - $avg_only = 1; - } - - // Get event data (contains alert data too) - if ($show_events == 1 || $show_alerts == 1) { - $events = db_get_all_rows_filter ('tevento', - array ('id_agentmodule' => $agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('evento', 'utimestamp', 'event_type')); - if ($events === false) { - $events = array (); - } - } - - // Get module data - $data = db_get_all_rows_filter ('tagente_datos', - array ('id_agente_modulo' => $agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('datos', 'utimestamp'), 'AND', $search_in_history_db); - - if ($data === false) { - $data = array (); - } - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($agent_module_id, $datelimit); - if ($previous_data !== false) { - $previous_data['utimestamp'] = $datelimit; - array_unshift ($data, $previous_data); - } - - // Get next data - $nextData = modules_get_next_data ($agent_module_id, $date); - if ($nextData !== false) { - array_push ($data, $nextData); - } - else if (count ($data) > 0) { - // Propagate the last known data to the end of the interval - $nextData = array_pop ($data); - array_push ($data, $nextData); - $nextData['utimestamp'] = $date; - array_push ($data, $nextData); - } - - $min_necessary = 2; - } - - // Set initial conditions - $graph_values[$i] = array(); - - // Check available data - if (count ($data) < $min_necessary) { - continue; - } - - // if(empty($aux_array)){ - // foreach ($data as $key => $value) { - // $aux_array[$value['utimestamp']] = $value['datos']; - // } - // } else { - // foreach ($data as $key => $value) { - // if(array_key_exists($value['utimestamp'],$aux_array)){ - // $aux_array[$value['utimestamp']] = $aux_array[$value['utimestamp']] + $value['datos']; - // } else { - // $aux_array[$value['utimestamp']] = $value['datos']; - // } - // } - // } - - if (!empty($name_list) && $names_number == $module_number && isset($name_list[$i])) { - if ($labels[$agent_module_id] != '') - $module_name_list[$i] = $labels[$agent_module_id]; - else { - $agent_name = io_safe_output( - modules_get_agentmodule_agent_name ($agent_module_id)); - $alias = db_get_value ("alias","tagente","nombre",$agent_name); - $module_name = io_safe_output( - modules_get_agentmodule_name ($agent_module_id)); - - if ($flash_charts) - $module_name_list[$i] = '' . $alias . " / " . $module_name. ''; - else - $module_name_list[$i] = $alias . " / " . $module_name; - } - } - else { - //Get and process agent name - $agent_name = io_safe_output( - modules_get_agentmodule_agent_name ($agent_module_id)); - $alias = db_get_value ("alias","tagente","nombre",$agent_name); - $agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false); - - $agent_id = agents_get_agent_id ($agent_name); - - if(empty($unit_list)){ - $unit_aux = modules_get_unit($agent_module_id); - array_push($unit_list_aux,$unit_aux); - } - //Get and process module name - $module_name = io_safe_output( - modules_get_agentmodule_name ($agent_module_id)); - $module_name = sprintf(__("%s"), $module_name); - $module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false); - - if ($flash_charts) { - if ($labels[$agent_module_id] != '') - $module_name_list[$i] = '' . - $labels[$agent_module_id] . ''; - else - $module_name_list[$i] = '' . - $alias . ' / ' . $module_name . ''; - } - else { - if ($labels[$agent_module_id] != '') - $module_name_list[$i] = $labels[$agent_module_id]; - else - $module_name_list[$i] = $alias . ' / ' . $module_name; - } - } - - // Data iterator - $j = 0; - - // Event iterator - $k = 0; - - // Set initial conditions - - //$graph_values[$i] = array(); - $temp_graph_values = array(); - - if ($data[0]['utimestamp'] == $datelimit) { - $previous_data = $data[0]['datos']; - $j++; - } - else { - $previous_data = 0; - } - - $max = 0; - $min = null; - $avg = 0; - $countAvg = 0; - - // Calculate chart data - $last_known = $previous_data; - for ($l = 0; $l <= $resolution; $l++) { - $countAvg ++; - - $timestamp = $datelimit + ($interval * $l); - $timestamp_short = graph_get_formatted_date($timestamp, $time_format, $time_format_2); - - $long_index[$timestamp_short] = date( - html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp); - //$timestamp = $timestamp_short; - - $total = 0; - $count = 0; - - // Read data that falls in the current interval - $interval_min = $last_known; - $interval_max = $last_known; - - while (isset ($data[$j]) && $data[$j]['utimestamp'] >= $timestamp && $data[$j]['utimestamp'] < ($timestamp + $interval)) { - if ($data[$j]['datos'] > $interval_max) { - $interval_max = $data[$j]['datos']; - } - else if ($data[$j]['datos'] < $interval_max) { - $interval_min = $data[$j]['datos']; - } - $total += $data[$j]['datos']; - $last_known = $data[$j]['datos']; - $count++; - $j++; - } - - // Average - if ($count > 0) { - $total /= $count; - } - - // Read events and alerts that fall in the current interval - $event_value = 0; - $alert_value = 0; - while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] <= ($timestamp + $interval)) { - if ($show_events == 1) { - $event_value++; - } - if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') { - $alert_value++; - } - $k++; - } - - // Data - if ($count > 0) { - //$graph_values[$i][$timestamp] = $total * $weight_list[$i]; - $temp_graph_values[$timestamp_short] = $total * $weight_list[$i]; - } - else { - // Compressed data - if ($uncompressed_module || ($timestamp > time ())) { - $temp_graph_values[$timestamp_short] = 0; - } - else { - $temp_graph_values[$timestamp_short] = $last_known * $weight_list[$i]; - } - } - - //Extract max, min, avg - if ($max < $temp_graph_values[$timestamp_short]) { - $max = $temp_graph_values[$timestamp_short]; - } - - if (isset($min)) { - if ($min > $temp_graph_values[$timestamp_short]) { - $min = $temp_graph_values[$timestamp_short]; - } - } - else { - $min = $temp_graph_values[$timestamp_short]; - } - $avg += $temp_graph_values[$timestamp_short]; - // Added to support projection graphs if ($projection != false and $i != 0) { $projection_data = array(); - $projection_data = array_merge($before_projection, $projection); + $projection_data = array_merge($before_projection, $projection); $graph_values[$i] = $projection_data; } else { - $graph_values[$i] = $temp_graph_values; + $graph_values[$i] = $temp_graph_values; } - } - //Add the max, min and avg in the legend - $avg = round($avg / $countAvg, 1); - $graph_stats = get_graph_statistics($graph_values[$i]); - + if (!isset($config["short_module_graph_data"])) $config["short_module_graph_data"] = true; - - if ($config["short_module_graph_data"]) { - $min = $graph_stats['min']; - $max = $graph_stats['max']; - $avg = $graph_stats['avg']; - $last = $graph_stats['last']; - - if ($min > 1000000) - $min = sprintf("%sM", remove_right_zeros(number_format($min / 1000000, remove_right_zeros))); - else if ($min > 1000) - $min = sprintf("%sK", remove_right_zeros(number_format($min / 1000, $config['graph_precision']))); - - if ($max > 1000000) - $max = sprintf("%sM", remove_right_zeros(number_format($max / 1000000, $config['graph_precision']))); - else if ($max > 1000) - $max = sprintf("%sK", remove_right_zeros(number_format($max / 1000, $config['graph_precision']))); - - if ($avg > 1000000) - $avg = sprintf("%sM", remove_right_zeros(number_format($avg / 1000000, $config['graph_precision']))); - else if ($avg > 1000) - $avg = sprintf("%sK", remove_right_zeros(number_format($avg / 1000, $config['graph_precision']))); - - if ($last > 1000000) - $last = sprintf("%sM", remove_right_zeros(number_format($last / 1000000, $config['graph_precision']))); - else if ($last > 1000) - $last = sprintf("%sK", remove_right_zeros(number_format($last / 1000, $config['graph_precision']))); - } - else { - $min = remove_right_zeros(number_format($graph_stats['min'], $config['graph_precision'])); - $max = remove_right_zeros(number_format($graph_stats['max'], $config['graph_precision'])); - $avg = remove_right_zeros(number_format($graph_stats['avg'], $config['graph_precision'])); - $last = remove_right_zeros(number_format($graph_stats['last'], $config['graph_precision'])); - } - - + if (!empty($unit_list) && $units_number == $module_number && isset($unit_list[$i])) { $unit = $unit_list[$i]; }else{ $unit = $unit_list_aux[$i]; } - - if ($projection == false or ($projection != false and $i == 0)) { - $module_name_list[$i] .= ": "; - if ($show_max) - $module_name_list[$i] .= __("Max") . ": $max $unit; "; - if ($show_min) - $module_name_list[$i] .= __("Min") . ": $min $unit; "; - if ($show_avg) - $module_name_list[$i] .= __("Avg") . ": $avg $unit"; - } - + if ($weight_list[$i] != 1) { //$module_name_list[$i] .= " (x". format_numeric ($weight_list[$i], 1).")"; $module_name_list[$i] .= " (x". format_numeric ($weight_list[$i], 1).")"; } - - //$graph_values[$module_name_list[$i]] = $graph_values[$i]; - //unset($graph_values[$i]); - - //$graph_values[$i] = $graph_values[$i]; - - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[0])) { - metaconsole_restore_db(); - } - } - } - +*/ $temp = array(); - if ($flash_charts === false && $stacked == CUSTOM_GRAPH_GAUGE) - $stacked = CUSTOM_GRAPH_BULLET_CHART; - switch ($stacked) { - case CUSTOM_GRAPH_BULLET_CHART_THRESHOLD: - case CUSTOM_GRAPH_BULLET_CHART: - $datelimit = $date - $period; - if($stacked == CUSTOM_GRAPH_BULLET_CHART_THRESHOLD){ - $acumulador = 0; - foreach ($module_list as $module_item) { - $module = $module_item; - $query_last_value = sprintf(' - SELECT datos - FROM tagente_datos - WHERE id_agente_modulo = %d - AND utimestamp < %d - ORDER BY utimestamp DESC', - $module, $date); - $temp_data = db_get_value_sql($query_last_value); - if ($acumulador < $temp_data){ - $acumulador = $temp_data; - } - } - } - foreach ($module_list as $module_item) { - $automatic_custom_graph_meta = false; - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id ($module_item['server']); - metaconsole_connect($server); - $automatic_custom_graph_meta = true; - } - } - if ($automatic_custom_graph_meta) - $module = $module_item['module']; - else - $module = $module_item; - - $search_in_history_db = db_search_in_history_db($datelimit); - - $temp[$module] = modules_get_agentmodule($module); - $query_last_value = sprintf(' - SELECT datos - FROM tagente_datos - WHERE id_agente_modulo = %d - AND utimestamp < %d - ORDER BY utimestamp DESC', - $module, $date); - $temp_data = db_get_value_sql($query_last_value); - - if ($temp_data) { - if (is_numeric($temp_data)) - $value = $temp_data; - else - $value = count($value); - } - else { - if ($flash_charts === false) - $value = 0; - else - $value = false; - } - - if ( !empty($labels) && isset($labels[$module]) ){ - $label = io_safe_input($labels[$module]); - }else{ - $alias = db_get_value ("alias","tagente","id_agente",$temp[$module]['id_agente']); - $label = $alias . ': ' . $temp[$module]['nombre']; - } - - $temp[$module]['label'] = $label; - $temp[$module]['value'] = $value; - $temp_max = reporting_get_agentmodule_data_max($module,$period,$date); - if ($temp_max < 0) - $temp_max = 0; - if (isset($acumulador)){ - $temp[$module]['max'] = $acumulador; - }else{ - $temp[$module]['max'] = ($temp_max === false) ? 0 : $temp_max; - } - - $temp_min = reporting_get_agentmodule_data_min($module,$period,$date); - if ($temp_min < 0) - $temp_min = 0; - $temp[$module]['min'] = ($temp_min === false) ? 0 : $temp_min; - - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[0])) { - metaconsole_restore_db(); - } - } - - } - - break; - case CUSTOM_GRAPH_HBARS: - case CUSTOM_GRAPH_VBARS: - $datelimit = $date - $period; - - $label = ''; - foreach ($module_list as $module_item) { - $automatic_custom_graph_meta = false; - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id ($module_item['server']); - metaconsole_connect($server); - $automatic_custom_graph_meta = true; - } - } - - if ($automatic_custom_graph_meta) - $module = $module_item['module']; - else - $module = $module_item; - - $module_data = modules_get_agentmodule($module); - $query_last_value = sprintf(' - SELECT datos - FROM tagente_datos - WHERE id_agente_modulo = %d - AND utimestamp < %d - ORDER BY utimestamp DESC', - $module, $date); - $temp_data = db_get_value_sql($query_last_value); - - $agent_name = io_safe_output( - modules_get_agentmodule_agent_name ($module)); - - if (!empty($labels) && isset($labels[$module]) ){ - $label = $labels[$module]; - }else { - $alias = db_get_value ("alias","tagente","id_agente",$module_data['id_agente']); - $label = $alias . " - " .$module_data['nombre']; - } - - $temp[$label]['g'] = round($temp_data,4); - - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[0])) { - metaconsole_restore_db(); - } - } - } - break; - case CUSTOM_GRAPH_PIE: - $datelimit = $date - $period; - $total_modules = 0; - foreach ($module_list as $module_item) { - $automatic_custom_graph_meta = false; - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id ($module_item['server']); - metaconsole_connect($server); - $automatic_custom_graph_meta = true; - } - } - - if ($automatic_custom_graph_meta) - $module = $module_item['module']; - else - $module = $module_item; - - $data_module = modules_get_agentmodule($module); - $query_last_value = sprintf(' - SELECT datos - FROM tagente_datos - WHERE id_agente_modulo = %d - AND utimestamp > %d - AND utimestamp < %d - ORDER BY utimestamp DESC', - $module, $datelimit, $date); - $temp_data = db_get_value_sql($query_last_value); - - if ( $temp_data ){ - if (is_numeric($temp_data)) - $value = $temp_data; - else - $value = count($value); - } - else { - $value = false; - } - $total_modules += $value; - - if ( !empty($labels) && isset($labels[$module]) ){ - $label = io_safe_output($labels[$module]); - }else { - $alias = db_get_value ("alias","tagente","id_agente",$data_module['id_agente']); - $label = io_safe_output($alias . ": " . $data_module['nombre']); - } - - $temp[$label] = array('value'=>$value, - 'unit'=>$data_module['unit']); - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[0])) { - metaconsole_restore_db(); - } - } - } - $temp['total_modules'] = $total_modules; - - break; - case CUSTOM_GRAPH_GAUGE: - $datelimit = $date - $period; - $i = 0; - foreach ($module_list as $module_item) { - $automatic_custom_graph_meta = false; - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id ($module_item['server']); - metaconsole_connect($server); - $automatic_custom_graph_meta = true; - } - } - - if ($automatic_custom_graph_meta) - $module = $module_item['module']; - else - $module = $module_item; - - $temp[$module] = modules_get_agentmodule($module); - $query_last_value = sprintf(' - SELECT datos - FROM tagente_datos - WHERE id_agente_modulo = %d - AND utimestamp < %d - ORDER BY utimestamp DESC', - $module, $date); - $temp_data = db_get_value_sql($query_last_value); - if ( $temp_data ) { - if (is_numeric($temp_data)) - $value = $temp_data; - else - $value = count($value); - } - else { - $value = false; - } - $temp[$module]['label'] = ($labels[$module] != '') ? $labels[$module] : $temp[$module]['nombre']; - - $temp[$module]['value'] = $value; - $temp[$module]['label'] = ui_print_truncate_text($temp[$module]['label'],"module_small",false,true,false,".."); - - if ($temp[$module]['unit'] == '%') { - $temp[$module]['min'] = 0; - $temp[$module]['max'] = 100; - } - else { - $min = $temp[$module]['min']; - if ($temp[$module]['max'] == 0) - $max = reporting_get_agentmodule_data_max($module,$period,$date); - else - $max = $temp[$module]['max']; - $temp[$module]['min'] = ($min == 0 ) ? 0 : $min; - $temp[$module]['max'] = ($max == 0 ) ? 100 : $max; - } - $temp[$module]['gauge'] = uniqid('gauge_'); - - if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole - if (is_array($module_list[0])) { - metaconsole_restore_db(); - } - } - $i++; - } - break; - default: - if (!is_null($percentil) && $percentil) { - foreach ($graph_values as $graph_group => $point) { - foreach ($point as $timestamp_point => $point_value) { - $temp[$timestamp_point][$graph_group] = $point_value; - } - $percentile_value = get_percentile($config['percentil'], $point); - $percentil_result[$graph_group] = array_fill ( 0, count($point), $percentile_value); - $series_type[$graph_group] = 'line'; - $agent_name = io_safe_output( - modules_get_agentmodule_agent_alias ($module_list[$graph_group])); - $module_name = io_safe_output( - modules_get_agentmodule_name ($module_list[$graph_group])); - $module_name_list['percentil'.$graph_group] = __('Percentile %dº', $config['percentil']) . __(' of module ') . $agent_name .' / ' . $module_name . ' (' . $percentile_value . ' ' . $unit . ') '; - } - } - else { - foreach ($graph_values as $graph_group => $point) { - foreach ($point as $timestamp_point => $point_value) { - $temp[$timestamp_point][$graph_group] = $point_value; - } - } - } - - //check min array two elements - if(count($temp) == 1){ - $timestamp_short = graph_get_formatted_date($date, $time_format, $time_format_2); - foreach($temp as $key => $value){ - foreach($value as $k => $v){ - $temp[$timestamp_short][$k] = $v; - } - } - } - break; - } -/* - $flash_charts = true; - if($ttl>1 || !$config['flash_charts']){ - $flash_charts = false; - } - - $temp = fullscale_data_combined($module_list, $period, $date, $flash_charts, $percentil); - - if (!is_null($percentil) && $percentil) { - if(isset($temp['percentil'])){ - $percentil_result = array_pop($temp); - } - } - - $resolution = count($temp); //Number of points of the graph - $interval = (int) ($period / $resolution); - $module_name_list = array(); - - if($ttl>1 || !$config['flash_charts']){ - $temp2 = array(); - foreach ($temp as $key => $value) { - $real_date = date("Y/M/d", $key); - $real_date .= "\n"; - $real_date .= date(" H:i:s", $key); - $temp2[$real_date] = $value; - } - $temp = $temp2; - } - - foreach ($module_list as $key => $value) { - if (is_metaconsole() && is_array($value)) { - $server = metaconsole_get_connection_by_id ($value['server']); - metaconsole_connect($server); - $value = $value['module']; - } - if ($labels[$value] != ''){ - $module_name_list[$key] = $labels[$value]; - } - else { - $agent_name = io_safe_output( modules_get_agentmodule_agent_name ($value) ); - $alias = db_get_value ("alias","tagente","nombre",$agent_name); - $module_name = io_safe_output( modules_get_agentmodule_name ($value) ); - - if ($flash_charts){ - $module_name_list[$key] = '' . $alias . " / " . $module_name. ''; - } - else{ - $module_name_list[$key] = $alias . " / " . $module_name; - } - } - if (is_metaconsole() && is_array($value)) { - metaconsole_restore_db(); - } - } - - if (!is_null($percentil) && $percentil) { - foreach ($module_list as $key => $value) { - if (is_metaconsole() && is_array($value)) { - $server = metaconsole_get_connection_by_id ($value['server']); - metaconsole_connect($server); - $value = $value['module']; - } - - $agent_name = io_safe_output( modules_get_agentmodule_agent_name ($value) ); - $alias = db_get_value ("alias","tagente","nombre",$agent_name); - $module_name = io_safe_output( modules_get_agentmodule_name ($value) ); - - if (is_metaconsole() && is_array($value)) { - metaconsole_restore_db(); - } - - $module_name_list['percentil'.$key] = __('Percentile %dº', $config['percentil']) . __(' of module ') . $agent_name .' / ' . $module_name . ' (' . $percentil_result[$key][0] . ' ' . $unit . ') '; - $series_type[$key] = 'line'; - } - } -*/ - - $graph_values = $temp; - - if($config["fixed_graph"] == false){ - $water_mark = array( - 'file' => $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - //Work around for fixed the agents name with huge size chars. - $fixed_font_size = $config['font_size']; //Set graph color -/* - $color = array(); - - $color[0] = array('border' => '#000000', - 'color' => $config['graph_color1'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[1] = array('border' => '#000000', - 'color' => $config['graph_color2'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[2] = array('border' => '#000000', - 'color' => $config['graph_color3'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[3] = array('border' => '#000000', - 'color' => $config['graph_color4'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[4] = array('border' => '#000000', - 'color' => $config['graph_color5'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[5] = array('border' => '#000000', - 'color' => $config['graph_color6'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[6] = array('border' => '#000000', - 'color' => $config['graph_color7'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[7] = array('border' => '#000000', - 'color' => $config['graph_color8'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[8] = array('border' => '#000000', - 'color' => $config['graph_color9'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[9] = array('border' => '#000000', - 'color' => $config['graph_color10'], - 'alpha' => CHART_DEFAULT_ALPHA); - $color[11] = array('border' => '#000000', - 'color' => COL_GRAPH9, - 'alpha' => CHART_DEFAULT_ALPHA); - $color[12] = array('border' => '#000000', - 'color' => COL_GRAPH10, - 'alpha' => CHART_DEFAULT_ALPHA); - $color[13] = array('border' => '#000000', - 'color' => COL_GRAPH11, - 'alpha' => CHART_DEFAULT_ALPHA); - $color[14] = array('border' => '#000000', - 'color' => COL_GRAPH12, - 'alpha' => CHART_DEFAULT_ALPHA); - $color[15] = array('border' => '#000000', - 'color' => COL_GRAPH13, - 'alpha' => CHART_DEFAULT_ALPHA); -*/ - if($id_widget_dashboard){ - $opcion = unserialize(db_get_value_filter('options','twidget_dashboard',array('id' => $id_widget_dashboard))); - foreach ($module_list as $key => $value) { - if(!empty($opcion[$value])){ - $color[$key]['color'] = $opcion[$value]; - } - } - } - $threshold_data = array(); if ($from_interface) { @@ -2428,9 +1883,6 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, switch ($stacked) { case CUSTOM_GRAPH_AREA: - // html_debug_print('entra por este sitio'); - // html_debug_print($data_array); - //$array_data = $data_array; return area_graph($agent_module_id, $array_data, $color, $legend, $series_type, $date_array, $data_module_graph, $show_elements_graph, @@ -2438,20 +1890,21 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, $array_events_alerts); break; default: - case CUSTOM_GRAPH_STACKED_AREA: - return stacked_area_graph($flash_charts, $graph_values, + case CUSTOM_GRAPH_STACKED_AREA: + html_debug_print('entra por akiiii'); + return stacked_area_graph($flash_charts, $array_data, $width, $height, $color, $module_name_list, $long_index, ui_get_full_url("images/image_problem_area_small.png", false, false, false), $title, "", $water_mark, $config['fontpath'], $fixed_font_size, "", $ttl, $homeurl, $background_color,$dashboard, $vconsole); break; - case CUSTOM_GRAPH_LINE: + case CUSTOM_GRAPH_LINE: return line_graph($flash_charts, $graph_values, $width, $height, $color, $module_name_list, $long_index, ui_get_full_url("images/image_problem_area_small.png", false, false, false), $title, "", $water_mark, $config['fontpath'], $fixed_font_size, - $unit, $ttl, $homeurl, $background_color, $dashboard, - $vconsole, $series_type, $percentil_result, $yellow_threshold, $red_threshold, $threshold_data); + $unit, $ttl, $homeurl, $background_color, $dashboard, + $vconsole, $series_type, $percentil_result, $yellow_threshold, $red_threshold, $threshold_data); break; case CUSTOM_GRAPH_STACKED_LINE: return stacked_line_graph($flash_charts, $graph_values, @@ -2497,101 +1950,9 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width, } } -function fullscale_data_combined($module_list, $period, $date, $flash_charts, $percentil){ - global $config; - // Set variables - if ($date == 0){ - $date = get_system_time(); - } - - $datelimit = $date - $period; - $count_data_all = 0; - - foreach ($module_list as $key_module => $value_module) { - if (!is_null($percentil) && $percentil) { - $array_percentil = array(); - } - - if (is_metaconsole() && is_array($value_module)) { - $server = metaconsole_get_connection_by_id ($value_module['server']); - metaconsole_connect($server); - $previous_data = modules_get_previous_data ($value_module['module'], $datelimit); - $data_uncompress = db_uncompress_module_data($value_module['module'], $datelimit, $date); - metaconsole_restore_db(); - } - else{ - $previous_data = modules_get_previous_data ($value_module, $datelimit); - $data_uncompress = db_uncompress_module_data($value_module, $datelimit, $date); - } - - foreach ($data_uncompress as $key_data => $value_data) { - foreach ($value_data['data'] as $k => $v) { - $real_date = $v['utimestamp']; - if(!isset($v['datos'])){ - $v['datos'] = $previous_data; - } - else{ - $previous_data = $v['datos']; - } - - if (!is_null($percentil) && $percentil) { - $array_percentil[] = $v['datos']; - } - - $data_all[$real_date][$key_module] = $v['datos']; - } - } - - if (!is_null($percentil) && $percentil) { - $percentil_value = get_percentile($config['percentil'], $array_percentil); - $percentil_result[$key_module] = array_fill (0, count($data_all), $percentil_value); - if(count($data_all) > $count_data_all){ - $count_data_all = count($data_all); - } - } - } - - if (!is_null($percentil) && $percentil) { - foreach ($percentil_result as $k => $v){ - if(count($v) < $count_data_all){ - $percentil_result[$k] = array_fill (0, $count_data_all, $v[0]); - } - } - } - - $data_prev = array(); - $data_all_rev = array(); - ksort($data_all); - - foreach ($data_all as $key => $value) { - if($flash_charts) { - $real_date = date("Y M d H:i:s", $key); - } - else{ - $real_date = $key; - } - - foreach ($module_list as $key_module => $value_module) { - if(!isset($value[$key_module])){ - $data_all[$key][$key_module] = $data_prev[$key_module]; - } - else{ - $data_prev[$key_module] = $value[$key_module]; - } - } - $data_all_rev[$real_date] = $data_all[$key]; - } - - if (!is_null($percentil) && $percentil) { - $data_all_rev['percentil'] = $percentil_result; - } - - return $data_all_rev; -} - /** * Print a graph with access data of agents - * + * * @param integer id_agent Agent ID * @param integer width pie graph width * @param integer height pie graph height diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 40134e8088..1787ed1635 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -204,8 +204,9 @@ function flot_area_graph ( break; } + ///XXXXXXX los px caca // Parent layer - $return = "
"; + $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "

"; @@ -250,7 +251,7 @@ function flot_area_graph ( //XXXXXX height: ".$format_graph['height']."px;' $return .= "graph" .$format_graph['adapt_key'] ."' style=' width: ".$format_graph['width']."px; - height: 400px;'>
"; + height: ".$format_graph['height']."px;'>
"; if ($show_elements_graph['menu']) { $format_graph['height'] = 100; @@ -260,8 +261,7 @@ function flot_area_graph ( } if (!$vconsole){ - $return .= "
"; } @@ -375,7 +375,7 @@ function menu_graph( $return .= "