Fixed the availability item report. TICKET: #2423

This commit is contained in:
mdtrooper 2015-07-21 18:50:57 +02:00
parent 3e7264a470
commit 9bc9e6f729
2 changed files with 32 additions and 73 deletions

View File

@ -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;

View File

@ -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();