diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index a729a043c7..71c277350c 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2240,4 +2240,82 @@ function modules_get_first_contact_date($id_agent_module) { return $first_date; } + +/** + * Get the unknown time status of a module in a period. + * If there is more than 1 days between data, there is some unknown time modules + * + * @param int id_agent_module. + * @param int ending interval timestamp + * @param int interval duration + * + * @return int unknown seconds. + */ +function modules_get_unknown_time ($id_agent_module, $date, $period){ + + // TODO REMOVE THE TIME IN PLANNED DOWNTIME + + if (empty($id_agent_module) || empty($date)) + return false; + + // Set initial conditions + $unknown_seconds = 0; + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + // Get interval data + $sql = sprintf ('SELECT utimestamp + FROM tagente_datos + WHERE id_agente_modulo = %d + AND utimestamp > %d AND utimestamp <= %d', + $id_agent_module, $datelimit, $date); + $sql .= ' ORDER BY utimestamp ASC'; + $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); + + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + + // All alternatives on first data + if ($previous_data === false && $interval_data === false) { + return false; + } else if($previous_data !== false && $interval_data === false) { + if (($date - $previous_data['utimestamp']) <= SECONDS_1DAY) { + return 0; + } + if (($previous_data['utimestamp'] + SECONDS_1DAY) >= $datelimit) { + return $date - ($previous_data['utimestamp'] + SECONDS_1DAY); + } else { + return $period; + } + } else if ($previous_data === false && $interval_data !== false) { + $first_data = array_shift ($interval_data); + $unknown_seconds += $first_data['utimestamp'] - $datelimit; + array_unshift ($interval_data, $first_data); + } else { + $first_data = array_shift ($interval_data); + if (($previous_data['utimestamp'] + SECONDS_1DAY) >= $first_data['utimestamp']) { + if (($previous_data['utimestamp'] + SECONDS_1DAY) >= $datelimit) { + $unknown_seconds += $previous_data['utimestamp'] + SECONDS_1DAY - $first_data['utimestamp']; + } else { + $unknown_seconds += $first_data['utimestamp'] - $datetime; + } + } + array_unshift ($interval_data, $first_data); + } + + // Put utimestamp like last data + $last_data['utimestamp'] = $date; + array_push ($interval_data, $last_data); + $previous_data = array_shift ($previous_data); + + // Check if all datas have data maximum one day before + foreach ($interval_data as $data) { + $previous_1day = $previous_data['utimestamp'] + SECONDS_1DAY; + if ($previous_1day >= $data['utimestamp']) { + $unknown_period += $previous_1day - $data['utimestamp']; + } + $previous_data = $data; + } + + return $unknown_seconds; +} ?> diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index b7115f0c38..2177b6d6af 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -3844,11 +3844,11 @@ function reporting_availability($report, $content) { $content['time_from'], $content['time_to']); - $count_checks = modules_get_count_datas( - $item['id_agent_module'], - $report["datetime"] - $content['period'], - $report["datetime"]); - + $item['interval_agent_module'] = modules_get_interval ($item['id_agent_module']); + $unknown_seconds = modules_get_unknown_time ($item['id_agent_module'], $report["datetime"], $content['period']); + if ($unknown_seconds !== false) { + $count_checks = (int)(($content['period'] - $unknown_seconds)/$item['interval_agent_module']); + } if ($sla_value === false) { $row['checks'] = __('Unknown'); @@ -3872,11 +3872,13 @@ function reporting_availability($report, $content) { $row['failed'] = format_numeric($percent_fail * $count_checks / 100, 0); - + $row['poling_time'] = "-"; + if ($percent_ok > 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 ($percent_fail > 0) {