From 9bc9e6f729c5790e97451a9fe1117ca96f5a38cb Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 21 Jul 2015 18:50:57 +0200 Subject: [PATCH] Fixed the availability item report. TICKET: #2423 --- pandora_console/include/functions_modules.php | 57 +------------------ .../include/functions_reporting.php | 48 ++++++++++------ 2 files changed, 32 insertions(+), 73 deletions(-) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index f828737dfd..40f7f8ec3e 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2156,65 +2156,10 @@ function modules_get_count_datas($id_agent_module, $date_init, $date_end) { $diff = $date_end - $date_init; + return ($diff / $interval); } -function modules_get_count_data_with_value($id_agent_module, $date_init, - $date_end, $value) { - - global $config; - - if (!is_numeric($date_init)) { - $date_init = strtotime($date_init); - } - - if (!is_numeric($date_end)) { - $date_end = strtotime($date_end); - } - - $sql = "SELECT * - FROM tagente_datos - WHERE - id_agente_modulo = " . (int)$id_agent_module . " - AND (utimestamp >= " . $date_init . " AND utimestamp <= " . $date_end . ")"; - - $data = db_get_all_rows_sql($sql, $config['history_db_enabled']); - - if (empty($data)) { - $data = array(); - } - - $interval = modules_get_interval($id_agent_module); - - $total_time_with_value = 0; - $on_value_detected = false; - $timestamp_with_value = null; - - foreach ($data as $row) { - if ($row['datos'] == $value) { - if (!$on_value_detected) { - $timestamp_with_value = $row['utimestamp']; - $on_value_detected = true; - } - } - else { - if ($on_value_detected) { - $total_time_with_value - += $row['utimestamp'] - $timestamp_with_value; - - $on_value_detected = false; - } - } - } - - if ($on_value_detected && !empty($data)) { - $total_time_with_value - += $date_end - $timestamp_with_value; - } - - return $total_time_with_value / $interval; -} - function modules_get_first_contact_date($id_agent_module) { global $config; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index f241e45a6e..4304c89420 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -3704,18 +3704,29 @@ function reporting_availability($report, $content) { $text = $row['availability_item'] = modules_get_agentmodule_name( $item['id_agent_module']); } + $row['agent'] = modules_get_agentmodule_agent_name( $item['id_agent_module']); $text = $row['agent'] . " (" . $text . ")"; + $sla_value = reporting_get_agentmodule_sla( + $item['id_agent_module'], + $content['period'], + 0.50, + 1.50, + $report["datetime"], + null, + $content['time_from'], + $content['time_to']); + $count_checks = modules_get_count_datas( $item['id_agent_module'], $report["datetime"] - $content['period'], $report["datetime"]); - if (empty($count_checks)) { + if ($sla_value === false) { $row['checks'] = __('Unknown'); $row['failed'] = __('Unknown'); $row['fail'] = __('Unknown'); @@ -3726,27 +3737,29 @@ function reporting_availability($report, $content) { $percent_ok = 0; } else { - $count_fails = modules_get_count_data_with_value( - $item['id_agent_module'], - $report["datetime"] - $content['period'], - $report["datetime"], - 0); - $percent_ok = (($count_checks - $count_fails) * 100) / $count_checks; - $percent_fail = 100 - $percent_ok; + $percent_ok = format_numeric($sla_value, 2); + $percent_fail = (100 - $percent_ok); - $row['ok'] = format_numeric($percent_ok, 2) . " %"; - $row['fail'] = format_numeric($percent_fail, 2) . " %"; - $row['checks'] = format_numeric($count_checks, 2); - $row['failed'] = format_numeric($count_fails ,2); - $row['poling_time'] = human_time_description_raw( - ($count_checks - $count_fails) * modules_get_interval($item['id_agent_module']), + $row['checks'] = format_numeric($count_checks, 0); + $row['ok'] = $percent_ok . " %"; + $row['fail'] = $percent_fail . " %"; + $row['failed'] = + format_numeric($percent_fail * $count_checks / 100, 0); + + + $row['poling_time'] = + human_time_description_raw( + ($percent_ok * $count_checks / 100) * modules_get_interval($item['id_agent_module']), true); + $row['time_unavaliable'] = "-"; - if ($count_fails > 0) { - $row['time_unavaliable'] = human_time_description_raw( - $count_fails * modules_get_interval($item['id_agent_module']), + if ($percent_fail > 0) { + $row['time_unavaliable'] = + human_time_description_raw( + ($percent_fail * $count_checks / 100) * modules_get_interval($item['id_agent_module']), true); } + } $data[] = $row; @@ -3774,6 +3787,7 @@ function reporting_availability($report, $content) { } } + //Restore dbconnection if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { metaconsole_restore_db();