Fixed the 'availability' item in report.

This commit is contained in:
mdtrooper 2015-05-26 17:05:54 +02:00
parent 3061a93fea
commit 5d25b7c8e6
4 changed files with 39 additions and 62 deletions

View File

@ -184,12 +184,14 @@ if ($moduleFilter != 0) {
$where .= ' AND id_agent_module = ' . $moduleFilter; $where .= ' AND id_agent_module = ' . $moduleFilter;
} }
/*
// Filter report items created from metaconsole in normal console list and the opposite // Filter report items created from metaconsole in normal console list and the opposite
if (defined('METACONSOLE') and $config['metaconsole'] == 1) { if (defined('METACONSOLE') and $config['metaconsole'] == 1) {
$where .= ' AND ((server_name IS NOT NULL AND length(server_name) != 0) OR type IN (\'general\',\'SLA\',\'exception\',\'top_n\'))'; $where .= ' AND ((server_name IS NOT NULL AND length(server_name) != 0) OR type IN (\'general\',\'SLA\',\'exception\',\'top_n\'))';
} }
else else
$where .= ' AND ((server_name IS NULL OR length(server_name) = 0) OR type IN (\'general\',\'SLA\',\'exception\',\'top_n\'))'; $where .= ' AND ((server_name IS NULL OR length(server_name) = 0) OR type IN (\'general\',\'SLA\',\'exception\',\'top_n\'))';
*/
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":

View File

@ -473,24 +473,14 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large
if ($mins != 0) { if ($mins != 0) {
$seconds = $seconds - ($mins * 60); $seconds = $seconds - ($mins * 60);
if ($hours == 0) { $returnTime .= "$mins $minutesString ";
$returnTime .= "$mins $minutesString ";
}
else {
$returnTime = sprintf("%02d", $hours) . ':' .
sprintf("%02d", $mins);
}
} }
$seconds = (int) $seconds;
if ($seconds != 0) { if ($seconds != 0) {
if ($hours == 0) { $returnTime .= "$seconds $secondsString ";
$returnTime .= "$seconds $secondsString ";
}
else {
$returnTime = sprintf("%02d",$hours) . ':' .
sprintf("%02d",$mins) . ':' .
sprintf("%02d",$seconds);
}
} }
$return = ' '; $return = ' ';

View File

@ -1398,14 +1398,8 @@ function modules_get_count_datas($id_agent_module, $date_init, $date_end) {
return ($diff / $interval); return ($diff / $interval);
} }
function modules_get_data_with_value($id_agent_module, $date_init, function modules_get_count_data_with_value($id_agent_module, $date_init,
$date_end, $value, $split_interval = false) { $date_end, $value) {
global $config;
// TODO REMOVE THE TIME IN PLANNED DOWNTIME
// TODO FOR OTHER KIND OF DATA
if (!is_numeric($date_init)) { if (!is_numeric($date_init)) {
$date_init = strtotime($date_init); $date_init = strtotime($date_init);
@ -1415,56 +1409,47 @@ function modules_get_data_with_value($id_agent_module, $date_init,
$date_end = strtotime($date_end); $date_end = strtotime($date_end);
} }
$sql = " $sql = "SELECT *
SELECT *
FROM tagente_datos FROM tagente_datos
WHERE WHERE
datos = " . (int)$value . " id_agente_modulo = " . (int)$id_agent_module . "
AND id_agente_modulo = " . (int)$id_agent_module . "
AND (utimestamp >= " . $date_init . " AND utimestamp <= " . $date_end . ")"; AND (utimestamp >= " . $date_init . " AND utimestamp <= " . $date_end . ")";
$data = db_get_all_rows_sql($sql, $data = db_get_all_rows_sql($sql, $config['history_db_enabled']);
$config['history_db_enabled']);
if (empty($data)) { if (empty($data)) {
$data = array(); $data = array();
} }
if ($split_interval) { $interval = modules_get_interval($id_agent_module);
$temp = array();
$previous_utimestamp = false;
foreach ($data as $row) {
if ($previous_utimestamp === false) {
$previous_utimestamp = $row['utimestamp'];
$temp[] = $row; $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); $on_value_detected = false;
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;
} }
} }
} }
return $data; if ($on_value_detected && !empty($data)) {
$total_time_with_value
+= $date_end - $timestamp_with_value;
}
return $total_time_with_value / $interval;
} }
/** /**

View File

@ -5700,12 +5700,12 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$item['id_agent_module'], $item['id_agent_module'],
$report["datetime"] - $content['period'], $report["datetime"] - $content['period'],
$report["datetime"]); $report["datetime"]);
$count_fails = count( $count_fails = modules_get_count_data_with_value(
modules_get_data_with_value( $item['id_agent_module'],
$item['id_agent_module'],
$report["datetime"] - $content['period'], $report["datetime"] - $content['period'],
$report["datetime"], $report["datetime"],
0, true)); 0);
$percent_ok = (($count_checks - $count_fails) * 100) / $count_checks; $percent_ok = (($count_checks - $count_fails) * 100) / $count_checks;
$percent_fail = 100 - $percent_ok; $percent_fail = 100 - $percent_ok;