From c9237bec28eddc2ac22a980c47ff5ac6bb742fa6 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Tue, 18 Sep 2012 09:02:49 +0000 Subject: [PATCH] 2012-09-18 Sergio Martin * include/functions_graph.php include/graphs/functions_flot.php include/graphs/flot/pandora.flot.js operation/agentes/stat_win.php include/functions_modules.php: Added unknown status to graphs and improve some little aesthetic things of flot graphs * include/functions.php include/functions_html.php: Fixed html checkbox issue with get_parameter_checkbox function git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6980 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 14 ++++ pandora_console/include/functions.php | 24 ++++++ pandora_console/include/functions_graph.php | 81 ++++++++++++++----- pandora_console/include/functions_html.php | 1 + pandora_console/include/functions_modules.php | 4 +- .../include/graphs/flot/pandora.flot.js | 6 +- .../include/graphs/functions_flot.php | 2 +- .../operation/agentes/stat_win.php | 15 +++- 8 files changed, 117 insertions(+), 30 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 7850b9837e..60767618db 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,17 @@ +2012-09-18 Sergio Martin + + * include/functions_graph.php + include/graphs/functions_flot.php + include/graphs/flot/pandora.flot.js + operation/agentes/stat_win.php + include/functions_modules.php: Added unknown status + to graphs and improve some little aesthetic things of + flot graphs + + * include/functions.php + include/functions_html.php: Fixed html checkbox issue + with get_parameter_checkbox function + 2012-09-17 Vanessa Gil * operation/events/events_list.php diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 3e21e86076..3c88eea200 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -604,6 +604,30 @@ function get_parameterBetweenListValues ($name, $values, $default) { return $default; } +/** + * Get a parameter from a checkbox. + * + * Is checked if the checkbox is sent to fix html bad design + * + * @param string $name key of the parameter in the $_POST or $_GET array + * @param mixed $default default value if the key wasn't found + * + * @return mixed Whatever was in that parameter, cleaned however + * + */ + +function get_parameter_checkbox ($name, $default = '') { + $sent = get_parameter($name.'_sent', 0); + + // If is not sent, return the default + if(!$sent) { + return $default; + } + + // If sent, get parameter normally + return get_parameter($name, 0); +} + /** * Get a parameter from a request. * diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 7acadc237c..f9dbfbf683 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -28,15 +28,21 @@ define("GRAPH_STACKED_LINE", 3); 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, $baseline = false, + $show_events = false, $show_alerts = false, $show_unknown = false, $baseline = false, $baseline_data = array(), $events = array(), $series_suffix = '') { global $config; - $flash_chart = $config['flash_charts']; + global $chart_extra_data; + global $series_type; + $flash_chart = $config['flash_charts']; + // Event iterator $event_i = 0; - + + // Is unknown flag + $is_unknown = false; + // Calculate chart data for ($i = 0; $i < $resolution; $i++) { $timestamp = $datelimit + ($interval * $i); @@ -74,6 +80,8 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i // Read events and alerts that fall in the current interval $event_value = 0; $alert_value = 0; + $unknown_value = 0; + $event_ids = array(); $alert_ids = array(); while (isset ($events[$event_i]) && $events[$event_i]['utimestamp'] >= $timestamp && $events[$event_i]['utimestamp'] <= ($timestamp + $interval)) { @@ -85,8 +93,19 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i $alert_value++; $alert_ids[] = $events[$event_i]['id_evento']; } + if ($show_unknown) { + if($events[$event_i]['event_type'] == 'going_unknown') { + $is_unknown = true; + } + else if(substr ($events[$event_i]['event_type'], 0, 5) == 'going') { + $is_unknown = false; + } + } $event_i++; } + if($is_unknown) { + $unknown_value++; + } if (!$flash_chart) { // Set the title and time format @@ -137,11 +156,17 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i $series_type['event'.$series_suffix] = 'points'; } if($show_alerts) { - $chart[$timestamp]['alert'.$series_suffix] = $alert_value; - $chart[$timestamp]['alert'.$series_suffix] = $alert_value; $chart[$timestamp]['alert'.$series_suffix] = $alert_value; $series_type['alert'.$series_suffix] = 'points'; } + if($show_unknown) { + $chart[$timestamp]['unknown'.$series_suffix] = $unknown_value; + $series_type['unknown'.$series_suffix] = 'area'; + } + + if($is_unknown) { + $total = $interval_max = $interval_min = $previous_data = 0; + } if ($count > 0) { if ($avg_only) { @@ -205,8 +230,9 @@ 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 = '') { - + $adapt_key = '', $compare = false, $series_suffix = '', $series_suffix_str = '', + $show_unknown = false) { + global $config; global $chart; global $color; @@ -226,7 +252,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, $chart_extra_data = array(); $warning_min = 0; $critical_min = 0; - + // Set variables if ($date == 0) $date = get_system_time(); $datelimit = $date - $period; @@ -246,7 +272,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, // Get event data (contains alert data too) $events = array(); - if ($show_events == 1 || $show_alerts == 1) { + 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", @@ -349,7 +375,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, 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, $baseline, + $show_events, $show_alerts, $show_unknown, $baseline, $baseline_data, $events, $series_suffix); // Return chart data and don't draw @@ -363,13 +389,16 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, $avg_value = round(reporting_get_agentmodule_data_average ($agent_module_id, $period, $date), 2); // Fix event and alert scale - $event_max = $max_value * 1.15; + $event_max = $max_value * 1.05; foreach ($chart as $timestamp => $chart_data) { if ($show_events && $chart_data['event'.$series_suffix] > 0) { - $chart[$timestamp]['event'.$series_suffix] = $event_max * 1.15; + $chart[$timestamp]['event'.$series_suffix] = $event_max * 1.2; } if ($show_alerts && $chart_data['alert'] > 0) { - $chart[$timestamp]['alert'.$series_suffix] = $event_max; + $chart[$timestamp]['alert'.$series_suffix] = $event_max * 1.10; + } + if ($show_unknown && $chart_data['unknown'] > 0) { + $chart[$timestamp]['unknown'.$series_suffix] = $event_max * 1.05; } } @@ -388,6 +417,9 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, if($show_alerts) { $color['alert'.$series_suffix] = array('border' => '#ff7f00', 'color' => '#ff7f00', 'alpha' => 50); } + if($show_unknown) { + $color['unknown'.$series_suffix] = array('border' => '#999999', 'color' => '#999999', 'alpha' => 50); + } $color['max'.$series_suffix] = array('border' => '#000000', 'color' => $config['graph_color3'], 'alpha' => 50); $color['sum'.$series_suffix] = array('border' => '#000000', 'color' => $config['graph_color2'], 'alpha' => 50); $color['min'.$series_suffix] = array('border' => '#000000', 'color' => $config['graph_color1'], 'alpha' => 50); @@ -402,6 +434,10 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, $legend['alert'.$series_suffix] = __('Alerts'); $chart_extra_data['legend_alerts'] = $legend['alert']; } + if($show_unknown) { + $legend['unknown'.$series_suffix] = __('Unknown').$series_suffix_str; + $chart_extra_data['legend_unknown'] = $legend['unknown']; + } if (!$avg_only){ $legend['max'.$series_suffix] = __('Max').$series_suffix_str . ' (' .format_for_graph($max_value) . ') ' . $unit; @@ -413,6 +449,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, if ($baseline) { $legend['baseline'.$series_suffix] = __('Baseline'); } + } function grafico_modulo_sparse ($agent_module_id, $period, $show_events, @@ -420,8 +457,8 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $show_alerts = false, $avg_only = 0, $pure = false, $date = 0, $unit = '', $baseline = 0, $return_data = 0, $show_title = true, $only_image = false, $homeurl = '', $ttl = 1, - $projection = false, $adapt_key = '', $compare = false) { - + $projection = false, $adapt_key = '', $compare = false, $show_unknown = false) { + global $config; global $graphic_type; @@ -442,11 +479,12 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $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, $return_data, $show_title, $projection, $adapt_key, $compare, - $series_suffix, $series_suffix_str); + $series_suffix, $series_suffix_str, $show_unknown); switch($compare) { case 'separated': @@ -467,7 +505,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $data_returned = grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, $width, $height , $title, $unit_name, $show_alerts, $avg_only, $date, $unit, $baseline, - $return_data, $show_title, $projection, $adapt_key, $compare); + $return_data, $show_title, $projection, $adapt_key, $compare, '', '', $show_unknown); if ($return_data) { return $data_returned; @@ -476,6 +514,9 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, if($compare === 'overlapped') { $i = 0; foreach($chart as $k=>$v) { + if(!isset($chart_prev[$i])) { + continue; + } $chart[$k] = array_merge($v,$chart_prev[$i]); $i++; } @@ -2163,7 +2204,7 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, $avg_value = round(reporting_get_agentmodule_data_average ($agent_module_id, $period, $date), 2); // Fix event and alert scale - $event_max = $max_value * 1.25; + $event_max = $max_value * 1.05; foreach ($chart as $timestamp => $chart_data) { if ($show_events) { if ($chart_data['event'] > 0) { @@ -2651,7 +2692,7 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events, $unit = modules_get_unit($agent_module_id); // Fix event and alert scale - $event_max = $max_value * 1.25; + $event_max = $max_value * 1.05; foreach ($chart as $timestamp => $chart_data) { if ($chart_data['event'] > 0) { $chart[$timestamp]['event'] = $event_max; @@ -3150,4 +3191,4 @@ function grafico_modulo_log4x_format_y_axis ( $number , $decimals=2, $dec_point= return ""; } } -?> \ No newline at end of file +?> diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 0873483534..dba7f40f0b 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1230,6 +1230,7 @@ function html_print_checkbox_extended ($name, $value, $checked, $disabled, $scri */ function html_print_checkbox ($name, $value, $checked = false, $return = false, $disabled = false, $script = '') { $output = html_print_checkbox_extended ($name, $value, (bool) $checked, $disabled, $script, '', true); + $output .= html_print_input_hidden($name.'_sent',1,true); if ($return === false) echo $output; diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 8f07837be5..d3d6d83643 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1285,18 +1285,16 @@ function modules_get_status($id_agent_module, $db_status, $data, &$status, &$tit $title = __('NORMAL'); } elseif ($db_status == 3) { + $status = STATUS_AGENT_DOWN; $last_status = modules_get_agentmodule_last_status($id_agent_module); switch($last_status) { case 0: - $status = STATUS_AGENT_DOWN; $title = __('UNKNOWN')." - ".__('Last status')." ".__('NORMAL'); break; case 1: - $status = STATUS_AGENT_DOWN; $title = __('UNKNOWN')." - ".__('Last status')." ".__('CRITICAL'); break; case 2: - $status = STATUS_AGENT_DOWN; $title = __('UNKNOWN')." - ".__('Last status')." ".__('WARNING'); break; } diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 9352f93370..11f99642e6 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -743,8 +743,8 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, else { $('#timestamp_'+graph_id).text(labels_long[j]); } - - $('#timestamp_'+graph_id).css('top', plot.offset().top); + + $('#timestamp_'+graph_id).css('top', plot.offset().top-$('#timestamp_'+graph_id).height()*1.5); var timesize = $('#timestamp_'+graph_id).width(); @@ -1072,4 +1072,4 @@ function number_format(number, force_integer, unit) { } return number+' '+shorts[pos]+unit; -} +} \ No newline at end of file diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 6d8a9ec56d..79602bde09 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -116,9 +116,9 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_in $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "

"; + $return .= ""; $return .= "
"; $return .= ""; - $return .= ""; if ($water_mark != '') { $return .= ""; diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index 9ea3fc9ee8..9e0133fc68 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -200,7 +200,7 @@ $label = base64_decode(get_parameter('label', '')); $show_events_graph = get_parameter ("show_events_graph", 0); $time_compare_separated = get_parameter ("time_compare_separated", 0); $time_compare_overlapped = get_parameter ("time_compare_overlapped", 0); - + $unknown_graph = get_parameter_checkbox ("unknown_graph", 1); $time_compare = false; @@ -237,7 +237,7 @@ $label = base64_decode(get_parameter('label', '')); switch ($graph_type) { case 'boolean': echo grafico_modulo_boolean ($id, $period, $draw_events, $width, $height, - $label, null, $draw_alerts, $avg_only, false, $date, false, $urlImage, 'adapter_'.$graph_type, $time_compare); + $label, null, $draw_alerts, $avg_only, false, $date, false, $urlImage, 'adapter_'.$graph_type, $time_compare, $unknown_graph); echo '


'; if ($show_events_graph) echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom, 'adapted_'.$graph_type); @@ -245,7 +245,7 @@ $label = base64_decode(get_parameter('label', '')); case 'sparse': echo grafico_modulo_sparse ($id, $period, $draw_events, $width, $height, $label, null, $draw_alerts, $avg_only, false, $date, '', $baseline, - 0, true, false, $urlImage, 1, false, 'adapter_'.$graph_type, $time_compare); + 0, true, false, $urlImage, 1, false, 'adapter_'.$graph_type, $time_compare, $unknown_graph); echo '


'; if ($show_events_graph) echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom, 'adapted_'.$graph_type); @@ -410,6 +410,15 @@ $label = base64_decode(get_parameter('label', '')); ?> + + + + + +