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
/**
* Auxiliary functions to manage servers.
*
@ -45,7 +44,7 @@ function servers_get_server($id_server, $filter=false, $fields=false)
return false;
}
if (!is_array($filter)) {
if (! is_array($filter)) {
$filter = [];
}
@ -146,6 +145,7 @@ function servers_get_total_modules()
);
return $modules;
}
@ -1017,57 +1017,40 @@ 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.
$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']
$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;
}

View File

@ -1,9 +1,9 @@
-- Pandora FMS - the Flexible Monitoring System
-- ============================================
-- Copyright (c) 2014-2021 Artica Soluciones Tecnologicas, http://www.artica.es
-- Please see http://www.pandorafms.org for full contribution list
-- Copyright (c) 2014-2023 Artica PFMS
-- 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
-- Because Pandora Installer don't understand them
@ -39,17 +39,18 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('block_size','20'),
('days_purge','45'),
('days_delete_unknown','0'),
('days_delete_not_initialized','0'),
('days_delete_not_initialized','7'),
('days_compact','0'),
('days_autodisable_deletion','30'),
('graph_res','5'),
('step_compact','1'),
('db_scheme_first_version', '6.0dev'),
('db_scheme_version','6.0RC1'),
('db_scheme_build','PD150908'),
('db_scheme_first_version', '7.0NG'),
('db_scheme_version','7.0NG'),
('db_scheme_build','PD230303'),
('show_unknown','0'),
('show_lastalerts','1'),
('style','pandora'),
('graph_image_height', '250'),
('graph_color1', '#99dd00'),
('graph_color2', '#336600'),
('graph_color3', '#3399cc'),
@ -104,7 +105,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('enable_refr', 0),
('meta_num_elements', 100),
('update_manager_installed', 1),
('num_files_attachment', 250),
('num_files_attachment', 500),
('show_vc', 1),
('inventory_changes_blacklist', '1,2,20,21'),
('custom_report_front', 0),
@ -220,10 +221,10 @@ UNLOCK TABLES;
LOCK TABLES `tlink` WRITE;
INSERT INTO `tlink` VALUES
(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'),
(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;

View File

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