Fixed the 'availability' item in report. (Merge from 5d25b7c8e6
)
This commit is contained in:
parent
527d5079b3
commit
1160fd800c
|
@ -464,29 +464,19 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large
|
|||
$returnTime .= "$hours $hoursString ";
|
||||
}
|
||||
|
||||
$mins = floor($seconds / SECONDS_1MINUTE);
|
||||
$mins = floor($seconds / 60);
|
||||
|
||||
if ($mins != 0) {
|
||||
$seconds = $seconds - ($mins * SECONDS_1MINUTE);
|
||||
$seconds = $seconds - ($mins * 60);
|
||||
|
||||
$returnTime .= "$mins $minutesString ";
|
||||
|
||||
if ($hours == 0) {
|
||||
$returnTime .= "$mins $minutesString ";
|
||||
}
|
||||
else {
|
||||
$returnTime = sprintf("%02d",$hours) . ':' .
|
||||
sprintf("%02d",$mins);
|
||||
}
|
||||
}
|
||||
|
||||
$seconds = (int) $seconds;
|
||||
|
||||
if ($seconds != 0) {
|
||||
if ($hours == 0) {
|
||||
$returnTime .= "$seconds $secondsString ";
|
||||
}
|
||||
else {
|
||||
$returnTime = sprintf("%02d",$hours) . ':' .
|
||||
sprintf("%02d",$mins) . ':' .
|
||||
sprintf("%02d",$seconds);
|
||||
}
|
||||
$returnTime .= "$seconds $secondsString ";
|
||||
}
|
||||
|
||||
$return = ' ';
|
||||
|
|
|
@ -2141,14 +2141,8 @@ function modules_get_count_datas($id_agent_module, $date_init, $date_end) {
|
|||
return ($diff / $interval);
|
||||
}
|
||||
|
||||
function modules_get_data_with_value($id_agent_module, $date_init,
|
||||
$date_end, $value, $split_interval = false) {
|
||||
|
||||
global $config;
|
||||
|
||||
// TODO REMOVE THE TIME IN PLANNED DOWNTIME
|
||||
|
||||
// TODO FOR OTHER KIND OF DATA
|
||||
function modules_get_count_data_with_value($id_agent_module, $date_init,
|
||||
$date_end, $value) {
|
||||
|
||||
if (!is_numeric($date_init)) {
|
||||
$date_init = strtotime($date_init);
|
||||
|
@ -2158,58 +2152,50 @@ function modules_get_data_with_value($id_agent_module, $date_init,
|
|||
$date_end = strtotime($date_end);
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
$sql = "SELECT *
|
||||
FROM tagente_datos
|
||||
WHERE
|
||||
datos = " . (int)$value . "
|
||||
AND id_agente_modulo = " . (int)$id_agent_module . "
|
||||
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']);
|
||||
$data = db_get_all_rows_sql($sql, $config['history_db_enabled']);
|
||||
|
||||
if (empty($data)) {
|
||||
$data = array();
|
||||
}
|
||||
|
||||
if ($split_interval) {
|
||||
$temp = array();
|
||||
$previous_utimestamp = false;
|
||||
foreach ($data as $row) {
|
||||
if ($previous_utimestamp === false) {
|
||||
$previous_utimestamp = $row['utimestamp'];
|
||||
|
||||
$temp[] = $row;
|
||||
$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 {
|
||||
$diff = $row['utimestamp'] - $previous_utimestamp;
|
||||
}
|
||||
else {
|
||||
if ($on_value_detected) {
|
||||
$total_time_with_value
|
||||
+= $row['utimestamp'] - $timestamp_with_value;
|
||||
|
||||
$interval = modules_get_interval($id_agent_module);
|
||||
|
||||
if ($diff > $interval) {
|
||||
$fake_count = (int)($diff / $interval);
|
||||
|
||||
$fake = $row;
|
||||
for ($iterator = 1; $iterator <= $fake_count; $iterator++) {
|
||||
$fake['utimestamp'] = $previous_utimestamp + ($iterator * $interval);
|
||||
$temp[] = $fake;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$temp[] = $row;
|
||||
}
|
||||
|
||||
$previous_utimestamp = $row['utimestamp'];
|
||||
|
||||
$data = $temp;
|
||||
$on_value_detected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
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;
|
||||
|
||||
|
|
|
@ -3715,12 +3715,11 @@ function reporting_availability($report, $content) {
|
|||
$percent_ok = 0;
|
||||
}
|
||||
else {
|
||||
$count_fails = count(
|
||||
modules_get_data_with_value(
|
||||
$item['id_agent_module'],
|
||||
$report["datetime"] - $content['period'],
|
||||
$report["datetime"],
|
||||
0, true));
|
||||
$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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue