From b46f148553203b4e17e9b98dc4eaa9dbb353f0f6 Mon Sep 17 00:00:00 2001 From: javilanz Date: Mon, 9 May 2011 15:20:58 +0000 Subject: [PATCH] 2011-05-09 Javier Lanz * include/graphs/fgraph.php: Added 'period' parameter to slicesbar_graph function * include/graphs/functions_pchart.php: Added 'period' variable and fixed pch_slicebar_graph function * include/functions_graph.php: Added 'date' to function graph_sla_slicebar * include/functions_reporting.php: Fixed get_agentmodule_sla_array function, and get_agentmodule_sla, updated some deprecated printTrucateText calls, and the decimal data for displaying the SLA number git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4322 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 11 + pandora_console/include/functions_graph.php | 11 +- .../include/functions_reporting.php | 208 ++++++++++++++---- pandora_console/include/graphs/fgraph.php | 4 +- .../include/graphs/functions_pchart.php | 17 +- 5 files changed, 190 insertions(+), 61 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 92b39542db..92053f2960 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2011-05-09 Javier Lanz + + * include/graphs/fgraph.php: Added 'period' parameter to slicesbar_graph + function + * include/graphs/functions_pchart.php: Added 'period' variable and fixed + pch_slicebar_graph function + * include/functions_graph.php: Added 'date' to function graph_sla_slicebar + * include/functions_reporting.php: Fixed get_agentmodule_sla_array + function, and get_agentmodule_sla, updated some deprecated + printTrucateText calls, and the decimal data for displaying the SLA number + 2011-05-09 Miguel de Dios * pandoradb.sql, pandoradb.postgreSQL.sql: fixed the default value for diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 39bb2eb9da..25decb8d07 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -33,6 +33,8 @@ function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events, global $config; global $graphic_type; + include_flash_chart_script($homeurl); + // Set variables if ($date == 0) $date = get_system_time(); $datelimit = $date - $period; @@ -773,15 +775,14 @@ function progress_bar2($progress, $width, $height, $title = '', $mode = 1) { "&mode=" . $mode . "&out_of_lim_str=".$out_of_lim_str."&title=".$title."&font=".$config['fontpath']."' />"; } -function graph_sla_slicebar ($id, $period, $sla_min, $sla_max, $daysWeek, - $time_from, $time_to, $sla_limit, $width, $height, $home_url) { +function graph_sla_slicebar ($id, $period, $sla_min, $sla_max, $date, $daysWeek = null, $time_from = null, $time_to = null, $width, $height, $home_url) { global $config; - $days = json_decode ($daysWeek, true); - $data = get_agentmodule_sla_array ($id, $period, $sla_min, $sla_max, $sla_limit, $days, $time_from, $time_to); + + $data = get_agentmodule_sla_array ($id, $period, $sla_min, $sla_max, $date, $daysWeek, $time_from, $time_to); $colors = array(1 => '#38B800', 2 => '#FFFF00', 3 => '#FF0000', 4 => '#C3C3C3'); - return slicesbar_graph($data, $width, $height, $colors, $config['fontpath'], + return slicesbar_graph($data, $period, $width, $height, $colors, $config['fontpath'], $config['round_corner'], $home_url); } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 8b3f3534d4..5cef084c08 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -448,12 +448,11 @@ function get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $ma $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; } - if (!empty($timeFrom)) { - $sql .= ' AND TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '"'; + if ($timeFrom < $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; } - - if (!empty($timeTo)) { - $sql .= ' AND TIME(FROM_UNIXTIME(utimestamp)) <= "' . $timeTo . '"'; + elseif ($timeFrom > $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; } $sql .= ' ORDER BY utimestamp ASC'; $interval_data = db_get_all_rows_sql ($sql, true); @@ -535,50 +534,163 @@ function get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $ma * @return Array with values either 1, 2, 3 or 4 depending if the SLA percentage for this subperiod * is within the sla limits, on the edge, outside or with an unknown value. */ -function get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $sla_limit = 0, $days = null, $timeFrom = null, $timeTo = null) { +function get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { global $config; - // Get date - $date = (string) get_parameter ('date', date ('Y-m-j')); - $time = (string) get_parameter ('time', date ('h:iA')); - $datetime = strtotime ($date.' '.$time); - //Get the module_interval - $interval = get_module_interval ($id_agent_module); + // Initialize variables + if (empty ($date)) { + $date = get_system_time (); + } + if ((empty ($period)) OR ($period == 0)) { + $period = $config["sla_period"]; + } + if ($daysWeek === null) { + $daysWeek = array(); + } + // Limit date to start searching data + $datelimit = $date - $period; - if ($period < 3600) { - $k = 6; - } elseif ($period < 86400) { - $k = 24; - } elseif ($period < 172800) { - $k = 48; - } else { - $k = 100; - } - $slices = $config["graph_res"] * $k; - $sub_period = $period / $slices; - if ($sub_period < $interval) { - $sub_period = $interval; - } - $final_time = $datetime - $period + $sub_period; + // Get interval data + $sql = sprintf ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = %d + AND utimestamp > %d AND utimestamp <= %d', + $id_agent_module, $datelimit, $date); + + //Add the working times (mon - tue - wed ...) and from time to time + $days = array(); + //Translate to mysql week days - $data = array(); - $i = 0; - while ($final_time <= $datetime) { - $sla_value = get_agentmodule_sla ($id_agent_module, $sub_period, $min_value, $max_value, $final_time, - $days, $timeFrom, $timeTo); - if ($sla_value === false || $sla_value < 0) {// 4 for the Unknown value - $data[$i] = 4; - } elseif (($sla_value >= ($sla_limit - 10)) && ($sla_value <= ($sla_limit + 10))) {//2 when value is within the edges - $data[$i] = 2; - } elseif ($sla_value > ($sla_limit + 10)) { //1 when value is OK - $data[$i] = 1; - } elseif ($sla_value < ($sla_limit - 10)) { //3 when value is Wrong - $data[$i] = 3; + if ($daysWeek) { + foreach ($daysWeek as $key => $value) { + if (!$value) { + if ($key == 'monday') { + $days[] = 2; + } + if ($key == 'tuesday') { + $days[] = 3; + } + if ($key == 'wednesday') { + $days[] = 4; + } + if ($key == 'thursday') { + $days[] = 5; + } + if ($key == 'friday') { + $days[] = 6; + } + if ($key == 'saturday') { + $days[] = 7; + } + if ($key == 'sunday') { + $days[] = 1; + } + } } - $final_time += $sub_period; - $i++; } - return $data; + + if (count($days) > 0) { + $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; + } + + if ($timeFrom != $timeTo) { + if ($timeFrom < $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + elseif ($timeFrom > $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + } + + $sql .= ' ORDER BY utimestamp ASC'; + $interval_data = db_get_all_rows_sql ($sql, true); + + if ($interval_data === false) { + $interval_data = array (); + } + + // Get previous data + $previous_data = get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $previous_data['utimestamp'] = $datelimit; + array_unshift ($interval_data, $previous_data); + } + + // Get next data + $next_data = get_next_data ($id_agent_module, $date); + if ($next_data !== false) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + //Get the percentage for the limits + $diff = $max_value - $min_value; + //Getting 10% of $diff --> $percent = ($diff/100)*10, so... + $percent = $diff / 10; + + //Set initial conditions + $first_data = array_shift ($interval_data); + $previous_utimestamp = $date - $period; + + if ($previous_utimestamp == $first_data['utimestamp']) { + $previous_value = $first_data ['datos']; + $previous_status = 0; + + if ($previous_value < 0) {// 4 for the Unknown value + $previous_status = 4; + } elseif ((($previous_value >= ($min_value - $percent)) && ($previous_value <= ($min_value + $percent))) || + (($previous_value >= ($max_value - $percent)) && ($previous_value <= ($max_value + $percent)))) {//2 when value is within the edges + $previous_status = 2; + } elseif (($previous_value > ($min_value + $percent)) && ($previous_value < ($max_value - $percent))) { //1 when value is OK + $previous_status = 1; + } elseif (($previous_value < ($min_value - $percent)) || ($previous_value > ($max_value + $percent))) { //3 when value is Wrong + $previous_status = 3; + } + } + else { + $previous_status = 1; + } + + $data_colors = array(); + $i = 0; + foreach ($interval_data as $data) { + $change = false; + $value = $data['datos']; + if ($value < 0) {// 4 for the Unknown value + $status = 4; + } elseif ((($value >= ($min_value - $percent)) && ($value <= ($min_value + $percent))) || + (($value >= ($max_value - $percent)) && ($value <= ($max_value + $percent)))) {//2 when value is within the edges + $status = 2; + } elseif (($value > ($min_value + $percent)) && ($value < ($max_value - $percent))) { //1 when value is OK + $status = 1; + } elseif (($value < ($min_value - $percent)) || ($value > ($max_value + $percent))) { //3 when value is Wrong + $status = 3; + } + if ($status != $previous_status) { + $change = true; + $data_colors[$i]['data'] = $previous_status; + $data_colors[$i]['utimestamp'] = $data['utimestamp'] - $previous_utimestamp; + $i++; + $previous_status = $status; + $previous_utimestamp = $data['utimestamp']; + } + } + if ($change == false) { + $data_colors[$i]['data'] = $previous_status; + $data_colors[$i]['utimestamp'] = $data['utimestamp'] - $previous_utimestamp; + } + + return $data_colors; } /** @@ -2110,7 +2222,7 @@ function render_report_html_item ($content, $table, $report, $mini = false) { $data[4] = ''; $data[5] = ''.__('Fail').''; } - $data[4] .= format_numeric ($sla_value). "%"; + $data[4] .= format_numeric ($sla_value, 2). "%"; } $data[4] .= ""; @@ -2149,8 +2261,8 @@ function render_report_html_item ($content, $table, $report, $mini = false) { $data[0] .= printSmallFont(get_agentmodule_name ($sla['id_agent_module'])); $data[1] = graph_sla_slicebar ($sla['id_agent_module'], $content['period'], - $sla['sla_min'], $sla['sla_max'], $daysWeek, $content['time_from'], - $content['time_to'], $sla['sla_limit'], 550, 25); + $sla['sla_min'], $sla['sla_max'], $report["datetime"], $content, $content['time_from'], + $content['time_to'], 550, 25,''); array_push ($table2->data, $data); } @@ -2165,7 +2277,7 @@ function render_report_html_item ($content, $table, $report, $mini = false) { //RUNNING $data = array (); $data[0] = $sizh.__('Monitor report').$sizhfin; - $data[1] = $sizh . ui_print_truncate_text($agent_name, 70, false).'
'.printTruncateText($module_name, 70, false).$sizhfin; + $data[1] = $sizh . ui_print_truncate_text($agent_name, 70, false).'
'.ui_print_truncate_text($module_name, 70, false).$sizhfin; $data[2] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); @@ -2199,7 +2311,7 @@ function render_report_html_item ($content, $table, $report, $mini = false) { //RUNNING $data = array (); $data[0] = $sizh.__('Avg. Value').$sizhfin; - $data[1] = $sizh.printTruncateText($agent_name, 75, false).'
'.printTruncateText($module_name, 75, false).$sizhfin; + $data[1] = $sizh.ui_print_truncate_text($agent_name, 75, false).'
'.ui_print_truncate_text($module_name, 75, false).$sizhfin; $data[2] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index aef84a2f48..d4c4ca5872 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -92,10 +92,10 @@ function progressbar($progress, $width, $height, $title, $font, $mode = 1, $out_ } -function slicesbar_graph($chart_data, $width, $height, $colors, $font, - $round_corner, $home_url = '') { +function slicesbar_graph($chart_data, $period, $width, $height, $colors, $font, $round_corner, $home_url = '') { $graph = array(); $graph['data'] = $chart_data; + $graph['period'] = $period; $graph['width'] = $width; $graph['height'] = $height; $graph['font'] = $font; diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index f15a3a721c..b8adb4efbb 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -95,6 +95,9 @@ $force_height = true; if(isset($graph['force_height'])) { $force_height = $graph['force_height']; } +if(isset($graph['period'])) { + $period = $graph['period']; +} if (!$force_height) { if ($height < (count($graph['data']) * 14)) { @@ -266,7 +269,7 @@ switch($graph_type) { $width, $height, $font, $water_mark, $font_size); break; case 'slicebar': - pch_slicebar_graph($graph_type, $data, $width, $height, $colors, $font, $round_corner, $font_size); + pch_slicebar_graph($graph_type, $data, $period, $width, $height, $colors, $font, $round_corner, $font_size); break; case 'polar': case 'radar': @@ -293,7 +296,7 @@ switch($graph_type) { break; } -function pch_slicebar_graph ($graph_type, $data, $width, $height, $colors, $font, $round_corner, $font_size) { +function pch_slicebar_graph ($graph_type, $data, $period, $width, $height, $colors, $font, $round_corner, $font_size) { /* CAT:Slicebar charts */ set_time_limit (0); @@ -311,8 +314,8 @@ function pch_slicebar_graph ($graph_type, $data, $width, $height, $colors, $font $radius = ($height > 18) ? 8 : 0; else $radius = 0; - - $ratio = $width / count($data); + + $thinest_slice = $width / $period; /* Color stuff */ $colorsrgb = array(); @@ -325,7 +328,9 @@ function pch_slicebar_graph ($graph_type, $data, $width, $height, $colors, $font $i = 0; foreach ($data as $d) { - $color = $colorsrgb[$d]; + $color = $d['data']; + $color = $colorsrgb[$color]; + $ratio = $thinest_slice * $d['utimestamp']; $myPicture->drawRoundedFilledRectangle ($i, 0, $ratio+$i, $height, $radius, array('R' => $color['R'], 'G' => $color['G'], 'B' => $color['B'])); $i+=$ratio; @@ -335,7 +340,7 @@ function pch_slicebar_graph ($graph_type, $data, $width, $height, $colors, $font if ($round_corner) { /* Under this value, the rounded rectangle is painted great */ - if ($ratio <= 16) { + if ($thinest_slice <= 16) { /* Clean a bit of pixels */ for ($i = 0; $i < 7; $i++) { $myPicture->drawLine (0, $i, 6 - $i, $i, array('R' => 255, 'G' => 255, 'B' => 255));