From 351dfc8ee1696edd8e6b2411be2d2c87b002b3eb Mon Sep 17 00:00:00 2001 From: Esteban Sanchez Date: Sat, 8 Nov 2008 10:57:40 +0000 Subject: [PATCH] 2008-11-08 Esteban Sanchez * godmode/reporting/reporting_builder.php: Fixed value of 1 week period. * include/functions.php: Moved all human_time_* functionallity to human_time_description_raw(). * include/functions_reporting.php: Fixed a bug in SLA calculation that affects small periods of time (less than 24 hours) due to data compression in the database. * operation/reporting/reporting_viewer.php: Style correction. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1225 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 14 +++++++++ .../godmode/reporting/reporting_builder.php | 2 +- pandora_console/include/functions.php | 31 +++++++------------ pandora_console/include/functions_db.php | 30 ++++++++++++++++++ .../include/functions_reporting.php | 29 ++++++++++------- .../operation/reporting/reporting_viewer.php | 6 ++-- 6 files changed, 77 insertions(+), 35 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 165c50718c..7cd8000621 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,17 @@ +2008-11-08 Esteban Sanchez + + * godmode/reporting/reporting_builder.php: Fixed value of 1 week + period. + + * include/functions.php: Moved all human_time_* functionallity to + human_time_description_raw(). + + * include/functions_reporting.php: Fixed a bug in SLA calculation that + affects small periods of time (less than 24 hours) due to data + compression in the database. + + * operation/reporting/reporting_viewer.php: Style correction. + 2008-11-07 Esteban Sanchez * include/functions_db.php: Style corrections ins give_acl(). Show diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index d9bccbbdb8..d96c82997c 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -390,7 +390,7 @@ if ($edit_sla_report_content) { $periods[12] = '12 '.__('hours'); $periods[24] = __('1 day'); $periods[48] = __('2 days'); - $periods[180] = __('1 week'); + $periods[168] = __('1 week'); $periods[360] = __('2 weeks'); $periods[720] = __('1 month'); $periods[4320] = __('6 months'); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 7b62dd522b..dcfa9f4eb3 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -481,6 +481,18 @@ function human_time_comparation ($timestamp) { $seconds = time () - $timestamp; + return human_time_description_raw ($seconds); +} + +/** + * Transform an amount of time in seconds into a human readable + * strings of minutes, hours or days. + * + * @param seconds Seconds elapsed time + * + * @return A human readable translation of minutes. + */ +function human_time_description_raw ($seconds) { if ($seconds < 60) return format_numeric ($seconds, 0)." ".__('seconds'); @@ -504,25 +516,6 @@ function human_time_comparation ($timestamp) { return " +6 ".__('months'); } -/** - * Transform an amount of time in seconds into a human readable - * strings of minutes, hours or days. - * - * @param seconds Seconds elapsed time - * - * @return A human readable translation of minutes. - */ -function human_time_description_raw ($seconds) { - global $lang_label; - if ($seconds < 3600) - return format_numeric ($seconds / 60, 2)." ".__('minutes'); - - if ($seconds >= 3600 && $seconds < 86400) - return format_numeric ($seconds / 3600, 2)." ".__('hours'); - - return format_numeric ($seconds / 86400, 2)." ".__('days'); -} - /** * Get a human readable label for a period of time. * diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 93bbaf4401..546ed5c7e8 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -569,6 +569,36 @@ function get_monitors_in_group ($id_group) { return get_db_all_rows_sql ($sql); } +/** + * Get all the events happened in a group during a period of time. + * + * The returned events will be in the time interval ($date - $period, $date] + * + * @param id_group Group id to get events. + * @param period Period of time in seconds to get events. + * @param date Beginning date to get events. + * + * @return An array with all the events happened. + */ +function get_events_in_group ($id_group, $period, $date) { + $datelimit = $date - $period; + + if ($id_group == 1) { + $sql = sprintf ('SELECT * FROM tevento + WHERE utimestamp > %d AND utimestamp <= %d + ORDER BY utimestamp ASC', + $datelimit, $date); + } else { + $sql = sprintf ('SELECT * FROM tevento + WHERE utimestamp > %d AND utimestamp <= %d + AND id_grupo = %d + ORDER BY utimestamp ASC', + $datelimit, $date, $id_group); + } + + return get_db_all_rows_sql ($sql); +} + /** * Get all the monitors defined in an agent. * diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index b99ca626bb..acdc5bcf16 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -35,7 +35,6 @@ function get_agent_module_sla ($id_agent_module, $period, $min_value, $max_value if (empty ($period)) return false; //We can't calculate a 0 period (division by zero) - $datelimit = $date - $period; // start date $id_agent = get_db_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', (int) $id_agent_module); @@ -50,10 +49,23 @@ function get_agent_module_sla ($id_agent_module, $period, $min_value, $max_value ORDER BY utimestamp ASC', $id_agent, $id_agent_module, $datelimit, $date); $datas = get_db_all_rows_sql ($sql); - if ($datas === false) { - //No data to calculate on so we return 0. - return 0; + + /* Try to get data from tagente_estado. It may found nothing because of + data compression */ + $sql = sprintf ('SELECT datos, utimestamp FROM tagente_estado + WHERE id_agente = %d AND id_agente_modulo = %d + AND utimestamp > %d AND utimestamp <= %d + ORDER BY utimestamp ASC', + $id_agent, $id_agent_module, $datelimit, $date); + $data = get_db_sql ($sql); + + if ($data === false) { + //No data to calculate on so we return 0. + return 0; + } + $datas = array (); + array_push ($datas, $data); } $last_data = ""; @@ -247,7 +259,6 @@ function event_reporting ($id_group, $period, $date = 0, $return = false) { if (! $date) $date = time (); - $datelimit = $date - $period; $table->data = array (); $table->head = array (); @@ -256,13 +267,7 @@ function event_reporting ($id_group, $period, $date = 0, $return = false) { $table->head[2] = __('User ID'); $table->head[3] = __('Timestamp'); - $sql = sprintf ('SELECT * FROM tevento - WHERE id_agente = %d - AND utimestamp > %d AND utimestamp <= %d - AND id_grupo = %d - ORDER BY utimestamp ASC', - $id_group, $datelimit, $date, $id_group); - $events = get_db_all_rows_sql ($sql); + $events = get_events_in_group ($id_group, $period, $date); if ($events === false) { if (!$return) print_table ($table); diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 268840d077..41773c7dfc 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -147,7 +147,7 @@ foreach ($contents as $content) { $data = array (); $data[0] = '

'.__('Simple graph').'

'; $data[1] = '

'.$agent_name.' - '.$module_name.'

'; - $data[2] = '

'.human_time_description($content['period']).'

'; + $data[2] = '

'.human_time_description ($content['period']).'

'; array_push ($table->data, $data); $data = array (); @@ -293,9 +293,9 @@ foreach ($contents as $content) { $monitor_value = format_numeric (get_agent_module_sla ($content['id_agent_module'], $content['period'], 1, 1, $datetime)); $data[0] = '

'; $data[0] .= $monitor_value.' %

'; - $monitor_value2 = format_numeric (100 - $monitor_value, 2) ; + $monitor_value = format_numeric (100 - $monitor_value, 2) ; $data[1] = '

'; - $data[1] .= $monitor_value2.' %

'; + $data[1] .= $monitor_value.' %

'; array_push ($table->data, $data); break;