From 6f974508f0d01190762af1ed8b40ac553d9202ad Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Fri, 3 Mar 2023 10:11:35 +0000 Subject: [PATCH] Revert "Merge branch..." This reverts merge request !5555 --- pandora_console/include/functions_servers.php | 79 ++++++++----------- pandora_server/lib/PandoraFMS/Core.pm | 67 +++++++--------- 2 files changed, 59 insertions(+), 87 deletions(-) diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index a1dfc32197..3f9fe1a6b2 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -1,5 +1,4 @@ 0 - AND tagente_estado.last_execution_try > 0 - AND tagente_estado.running_by = %d - ) tae - JOIN ( - SELECT tagente_modulo.id_agente_modulo - FROM tagente_modulo LEFT JOIN tagente - ON tagente_modulo.id_agente = tagente.id_agente - WHERE tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - ) tam - ON tae.id_agente_modulo = tam.id_agente_modulo - WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval) - AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)', - $server['id_server'] + $result = db_get_row_sql( + 'SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, + AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS "lag" + FROM tagente_estado, tagente_modulo, tagente + WHERE utimestamp > 0 + AND tagente.disabled = 0 + AND tagente.id_agente = tagente_estado.id_agente + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + AND current_interval > 0 + AND running_by = '.$server['id_server'].' + AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10) + AND (UNIX_TIMESTAMP() - utimestamp) > current_interval' ); } else { // Local/Dataserver server LAG calculation. // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. - $sql = sprintf( - 'SELECT COUNT(tam.id_agente_modulo) AS module_lag, - AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" - FROM ( - SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo - FROM tagente_estado - WHERE tagente_estado.current_interval > 0 - AND tagente_estado.last_execution_try > 0 - AND tagente_estado.running_by = %d - ) tae - JOIN ( - SELECT tagente_modulo.id_agente_modulo - FROM tagente_modulo LEFT JOIN tagente - ON tagente_modulo.id_agente = tagente.id_agente - WHERE tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND tagente_modulo.id_tipo_modulo < 5 - ) tam - ON tae.id_agente_modulo = tam.id_agente_modulo - WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval * 1.1) - AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)', - $server['id_server'] + $result = db_get_row_sql( + 'SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, + AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS "lag" + FROM tagente_estado, tagente_modulo, tagente + WHERE utimestamp > 0 + AND tagente.disabled = 0 + AND tagente.id_agente = tagente_estado.id_agente + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_tipo_modulo < 5 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + AND current_interval > 0 + AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10) + AND running_by = '.$server['id_server'].' + AND (UNIX_TIMESTAMP() - utimestamp) > (current_interval * 1.1)' ); } - $result = db_get_row_sql($sql); // Lag over current_interval * 2 is not lag, // it's a timed out module. if (!empty($result['lag'])) { @@ -1154,11 +1137,11 @@ function servers_check_remote_config($server_name) $config['remote_config'] ).'/conf/'.$server_md5.'.srv.conf'; - if (!isset($filenames['conf'])) { + if (! isset($filenames['conf'])) { return false; } - if (!isset($filenames['md5'])) { + if (! isset($filenames['md5'])) { return false; } diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 234229b5c1..04fd172019 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5629,48 +5629,37 @@ sub pandora_server_statistics ($$) { if ($server->{"server_type"} != DATASERVER){ $lag_row = get_db_single_row ($dbh, - "SELECT COUNT(tam.id_agente_modulo) AS module_lag, - AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" - FROM ( - SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo - FROM tagente_estado - WHERE tagente_estado.current_interval > 0 - AND tagente_estado.last_execution_try > 0 - AND tagente_estado.running_by = ? - ) tae - JOIN ( - SELECT tagente_modulo.id_agente_modulo - FROM tagente_modulo LEFT JOIN tagente - ON tagente_modulo.id_agente = tagente.id_agente - WHERE tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - ) tam - ON tae.id_agente_modulo = tam.id_agente_modulo - WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval) - AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)", $server->{"id_server"}); + "SELECT COUNT(tam.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS lag + FROM ( + SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo + FROM tagente_estado + WHERE tagente_estado.current_interval > 0 + AND tagente_estado.last_execution_try > 0 + AND tagente_estado.running_by = ? + ) tae + JOIN ( + SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag + FROM tagente_modulo LEFT JOIN tagente + ON tagente_modulo.id_agente = tagente.id_agente + WHERE tagente.disabled = 0 + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_tipo_modulo < 5 + ) tam + ON tae.id_agente_modulo = tam.id_agente_modulo + WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10) + AND (tam.flag = 1 OR (UNIX_TIMESTAMP() - tae.last_execution_try) > tae.current_interval)", $server->{"id_server"}); } # Dataserver LAG calculation: else { - $lag_row = get_db_single_row ($dbh, "SELECT COUNT(tam.id_agente_modulo) AS module_lag, - AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" - FROM ( - SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo - FROM tagente_estado - WHERE tagente_estado.current_interval > 0 - AND tagente_estado.last_execution_try > 0 - AND tagente_estado.running_by = ? - ) tae - JOIN ( - SELECT tagente_modulo.id_agente_modulo - FROM tagente_modulo LEFT JOIN tagente - ON tagente_modulo.id_agente = tagente.id_agente - WHERE tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND tagente_modulo.id_tipo_modulo < 5 - ) tam - ON tae.id_agente_modulo = tam.id_agente_modulo - WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval * 1.1) - AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)", $server->{"id_server"}); + $lag_row = get_db_single_row ($dbh, "SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS lag + FROM tagente_estado, tagente_modulo + WHERE utimestamp > 0 + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + AND current_interval > 0 + AND running_by = ? + AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10) + AND (UNIX_TIMESTAMP() - utimestamp) > current_interval", $server->{"id_server"}); } $server->{"module_lag"} = $lag_row->{'module_lag'};