From e118729398bc26baa5b7fdec3cbb291b9c6aaf1f Mon Sep 17 00:00:00 2001 From: m-lopez-f Date: Fri, 17 Feb 2017 13:34:30 +0100 Subject: [PATCH] Fixed problems with column 'last contact'. Gitlab: #269 --- pandora_console/include/functions_agents.php | 23 +++++++++++++++++++ pandora_console/include/functions_modules.php | 5 ++++ .../operation/agentes/estado_agente.php | 11 +-------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 17aedf6b87..98a5f9d414 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1391,6 +1391,29 @@ function agents_get_interval ($id_agent) { return (int) db_get_value ('intervalo', 'tagente', 'id_agente', $id_agent); } +/** + * Get all data of agent. + * + * @param Agent object. + * + * @return The interval value and status of last contact + */ +function agents_get_interval_status ($agent) { + + $return = ''; + $last_time = strtotime ($agent["ultimo_contacto"]); + $now = time (); + $diferencia = $now - $last_time; + $time = ui_print_timestamp ($last_time, true, array('style' => 'font-size:6.5pt')); + $min_interval = modules_get_agentmodule_mininterval($agent['id_agente']); + + $return = $time; + if ($diferencia > ($min_interval["min_interval"] * 2)) + $return = ''.$time.''; + + return $return; +} + /** * Get the operating system of an agent. * diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 4da1f3cead..5513ae9401 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2490,6 +2490,11 @@ function modules_get_modules_name ($sql_from , $sql_conditions = '', $meta = fal } } +function modules_get_agentmodule_mininterval($id_agent) { + $sql = sprintf('SELECT min(current_interval) min_interval from tagente_estado where id_agente = %d', $id_agent); + return db_get_row_sql($sql); +} + function get_same_modules ($agents, $modules) { $modules_to_report = array(); if ($modules != "") { diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index d57f56cde3..ad0d5ee8e0 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -606,16 +606,7 @@ foreach ($agents as $agent) { $data[7] = $alert_img; - - $last_time = strtotime ($agent["ultimo_contacto"]); - $now = time (); - $diferencia = $now - $last_time; - $time = ui_print_timestamp ($last_time, true, array('style' => 'font-size:6.5pt')); - $style = ''; - if ($diferencia > ($agent["intervalo"] * 2)) - $data[8] = ''.$time.''; - else - $data[8] = $time; + $data[8] = agents_get_interval_status ($agent); // This old code was returning "never" on agents without modules, BAD !! // And does not print outdated agents in red. WRONG !!!!