Merge branch 'develop' into ent-9893-nuevo-sistema-de-ha

This commit is contained in:
Daniel Maya 2023-03-03 11:47:03 +01:00
commit 52b43410c7
3 changed files with 70 additions and 97 deletions

View File

@ -1,5 +1,4 @@
<?php <?php
/** /**
* Auxiliary functions to manage servers. * Auxiliary functions to manage servers.
* *
@ -45,7 +44,7 @@ function servers_get_server($id_server, $filter=false, $fields=false)
return false; return false;
} }
if (!is_array($filter)) { if (! is_array($filter)) {
$filter = []; $filter = [];
} }
@ -146,6 +145,7 @@ function servers_get_total_modules()
); );
return $modules; return $modules;
} }
@ -1017,57 +1017,40 @@ function servers_get_info($id_server=-1)
// Remote servers LAG Calculation (server_type != 0). // Remote servers LAG Calculation (server_type != 0).
if ($server['server_type'] != 0) { if ($server['server_type'] != 0) {
// MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations.
$sql = sprintf( $result = db_get_row_sql(
'SELECT COUNT(tam.id_agente_modulo) AS module_lag, 'SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag,
AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS "lag"
FROM ( FROM tagente_estado, tagente_modulo, tagente
SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo WHERE utimestamp > 0
FROM tagente_estado AND tagente.disabled = 0
WHERE tagente_estado.current_interval > 0 AND tagente.id_agente = tagente_estado.id_agente
AND tagente_estado.last_execution_try > 0 AND tagente_modulo.disabled = 0
AND tagente_estado.running_by = %d AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
) tae AND current_interval > 0
JOIN ( AND running_by = '.$server['id_server'].'
SELECT tagente_modulo.id_agente_modulo AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
FROM tagente_modulo LEFT JOIN tagente AND (UNIX_TIMESTAMP() - utimestamp) > current_interval'
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 { } else {
// Local/Dataserver server LAG calculation. // Local/Dataserver server LAG calculation.
// MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations.
$sql = sprintf( $result = db_get_row_sql(
'SELECT COUNT(tam.id_agente_modulo) AS module_lag, 'SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag,
AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS "lag"
FROM ( FROM tagente_estado, tagente_modulo, tagente
SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo WHERE utimestamp > 0
FROM tagente_estado AND tagente.disabled = 0
WHERE tagente_estado.current_interval > 0 AND tagente.id_agente = tagente_estado.id_agente
AND tagente_estado.last_execution_try > 0 AND tagente_modulo.disabled = 0
AND tagente_estado.running_by = %d AND tagente_modulo.id_tipo_modulo < 5
) tae AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
JOIN ( AND current_interval > 0
SELECT tagente_modulo.id_agente_modulo AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
FROM tagente_modulo LEFT JOIN tagente AND running_by = '.$server['id_server'].'
ON tagente_modulo.id_agente = tagente.id_agente AND (UNIX_TIMESTAMP() - utimestamp) > (current_interval * 1.1)'
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, // Lag over current_interval * 2 is not lag,
// it's a timed out module. // it's a timed out module.
if (!empty($result['lag'])) { if (!empty($result['lag'])) {
@ -1154,11 +1137,11 @@ function servers_check_remote_config($server_name)
$config['remote_config'] $config['remote_config']
).'/conf/'.$server_md5.'.srv.conf'; ).'/conf/'.$server_md5.'.srv.conf';
if (!isset($filenames['conf'])) { if (! isset($filenames['conf'])) {
return false; return false;
} }
if (!isset($filenames['md5'])) { if (! isset($filenames['md5'])) {
return false; return false;
} }

View File

@ -1,9 +1,9 @@
-- Pandora FMS - the Flexible Monitoring System -- Pandora FMS - the Flexible Monitoring System
-- ============================================ -- ============================================
-- Copyright (c) 2014-2021 Artica Soluciones Tecnologicas, http://www.artica.es -- Copyright (c) 2014-2023 Artica PFMS
-- Please see http://www.pandorafms.org for full contribution list -- Please see http://www.pandorafms.com
-- Database Data for Pandora FMS 5.1 -- Database Data for Pandora FMS NG
-- PLEASE NO NOT USE MULTILINE COMMENTS -- PLEASE NO NOT USE MULTILINE COMMENTS
-- Because Pandora Installer don't understand them -- Because Pandora Installer don't understand them
@ -39,17 +39,18 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('block_size','20'), ('block_size','20'),
('days_purge','45'), ('days_purge','45'),
('days_delete_unknown','0'), ('days_delete_unknown','0'),
('days_delete_not_initialized','0'), ('days_delete_not_initialized','7'),
('days_compact','0'), ('days_compact','0'),
('days_autodisable_deletion','30'), ('days_autodisable_deletion','30'),
('graph_res','5'), ('graph_res','5'),
('step_compact','1'), ('step_compact','1'),
('db_scheme_first_version', '6.0dev'), ('db_scheme_first_version', '7.0NG'),
('db_scheme_version','6.0RC1'), ('db_scheme_version','7.0NG'),
('db_scheme_build','PD150908'), ('db_scheme_build','PD230303'),
('show_unknown','0'), ('show_unknown','0'),
('show_lastalerts','1'), ('show_lastalerts','1'),
('style','pandora'), ('style','pandora'),
('graph_image_height', '250'),
('graph_color1', '#99dd00'), ('graph_color1', '#99dd00'),
('graph_color2', '#336600'), ('graph_color2', '#336600'),
('graph_color3', '#3399cc'), ('graph_color3', '#3399cc'),
@ -104,7 +105,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('enable_refr', 0), ('enable_refr', 0),
('meta_num_elements', 100), ('meta_num_elements', 100),
('update_manager_installed', 1), ('update_manager_installed', 1),
('num_files_attachment', 250), ('num_files_attachment', 500),
('show_vc', 1), ('show_vc', 1),
('inventory_changes_blacklist', '1,2,20,21'), ('inventory_changes_blacklist', '1,2,20,21'),
('custom_report_front', 0), ('custom_report_front', 0),
@ -220,10 +221,10 @@ UNLOCK TABLES;
LOCK TABLES `tlink` WRITE; LOCK TABLES `tlink` WRITE;
INSERT INTO `tlink` VALUES INSERT INTO `tlink` VALUES
(1,'Documentation','https://pandorafms.com/manual'), (1,'Documentation','https://pandorafms.com/manual'),
(2,'Enterprise Edition','http://pandorafms.com'), (2,'Get support','https://pandorafms.com/en/technical-support/'),
(3,'Report a bug','https://github.com/pandorafms/pandorafms/issues'), (3,'Report a bug','https://github.com/pandorafms/pandorafms/issues'),
(4,'Suggest new feature','https://pandorafms.com/community/beta-program/'), (4,'Suggest new feature','https://pandorafms.com/community/beta-program/'),
(5,'Module library','http://library.pandorafms.com/'); (5,'Module library','https://pandorafms.com/library/');
UNLOCK TABLES; UNLOCK TABLES;

View File

@ -5629,48 +5629,37 @@ sub pandora_server_statistics ($$) {
if ($server->{"server_type"} != DATASERVER){ if ($server->{"server_type"} != DATASERVER){
$lag_row = get_db_single_row ($dbh, $lag_row = get_db_single_row ($dbh,
"SELECT COUNT(tam.id_agente_modulo) AS module_lag, "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 (
FROM ( SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo
SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo FROM tagente_estado
FROM tagente_estado WHERE tagente_estado.current_interval > 0
WHERE tagente_estado.current_interval > 0 AND tagente_estado.last_execution_try > 0
AND tagente_estado.last_execution_try > 0 AND tagente_estado.running_by = ?
AND tagente_estado.running_by = ? ) tae
) tae JOIN (
JOIN ( SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag
SELECT tagente_modulo.id_agente_modulo FROM tagente_modulo LEFT JOIN tagente
FROM tagente_modulo LEFT JOIN tagente ON tagente_modulo.id_agente = tagente.id_agente
ON tagente_modulo.id_agente = tagente.id_agente WHERE tagente.disabled = 0
WHERE tagente.disabled = 0 AND tagente_modulo.disabled = 0
AND tagente_modulo.disabled = 0 AND tagente_modulo.id_tipo_modulo < 5
) tam ) tam
ON tae.id_agente_modulo = tam.id_agente_modulo ON tae.id_agente_modulo = tam.id_agente_modulo
WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval) WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)
AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)", $server->{"id_server"}); AND (tam.flag = 1 OR (UNIX_TIMESTAMP() - tae.last_execution_try) > tae.current_interval)", $server->{"id_server"});
} }
# Dataserver LAG calculation: # Dataserver LAG calculation:
else { else {
$lag_row = get_db_single_row ($dbh, "SELECT COUNT(tam.id_agente_modulo) AS module_lag, $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
AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" FROM tagente_estado, tagente_modulo
FROM ( WHERE utimestamp > 0
SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0
FROM tagente_estado AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
WHERE tagente_estado.current_interval > 0 AND current_interval > 0
AND tagente_estado.last_execution_try > 0 AND running_by = ?
AND tagente_estado.running_by = ? AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
) tae AND (UNIX_TIMESTAMP() - utimestamp) > current_interval", $server->{"id_server"});
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'}; $server->{"module_lag"} = $lag_row->{'module_lag'};