From 5fb43198eabaac3819ea147b511a2cefc7951971 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 3 Mar 2023 11:22:39 +0100 Subject: [PATCH 1/3] Fix quores error --- pandora_server/lib/PandoraFMS/Core.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 234229b5c1..40196329d1 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5630,7 +5630,7 @@ sub pandora_server_statistics ($$) { $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" + 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 @@ -5652,7 +5652,7 @@ sub pandora_server_statistics ($$) { # 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" + 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 From 2386b87c1d2cb43a2c7eea9e13c6a12f69bc8b2b Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 3 Mar 2023 11:34:01 +0100 Subject: [PATCH 2/3] Functions servers lag query updated --- pandora_console/include/functions_servers.php | 72 ++++++++++++------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index 3f9fe1a6b2..14c8d31813 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -1017,40 +1017,58 @@ function servers_get_info($id_server=-1) // Remote servers LAG Calculation (server_type != 0). if ($server['server_type'] != 0) { // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. - $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' + $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 + ) 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'] ); } else { // Local/Dataserver server LAG calculation. // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. - $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)' + $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($sql); + // Lag over current_interval * 2 is not lag, // it's a timed out module. if (!empty($result['lag'])) { From 4b31bc340e86e23828f20eb29aece2dbc368d8ac Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 3 Mar 2023 11:50:21 +0100 Subject: [PATCH 3/3] Fix code style --- pandora_console/include/functions_servers.php | 56 ++++++------ pandora_server/lib/PandoraFMS/Core.pm | 90 ++++++++++--------- 2 files changed, 76 insertions(+), 70 deletions(-) diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index 14c8d31813..3f4071ccf2 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -1021,22 +1021,22 @@ function servers_get_info($id_server=-1) '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 + 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 ( + 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 + 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)', + 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'] ); } else { @@ -1044,25 +1044,25 @@ function servers_get_info($id_server=-1) // 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" + 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 + FROM tagente_estado + WHERE tagente_estado.current_interval > 0 + AND tagente_estado.last_execution_try > 0 + AND tagente_estado.running_by = %d ) tae - JOIN ( + 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)', + 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'] ); } diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 40196329d1..b911f05b50 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5627,50 +5627,56 @@ sub pandora_server_statistics ($$) { # Non-dataserver LAG calculation: 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"}); - } + $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"} + ); +} # 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(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"} + ); } $server->{"module_lag"} = $lag_row->{'module_lag'};