Merge branch 'ent-12195-15835-Safe-operation-mode-habilita-modulos-deshabilitados-en-los-modulos-al-recuperarse' into 'develop'

fix safe mode recovery

See merge request 
This commit is contained in:
Rafael Ameijeiras 2024-02-21 07:59:38 +00:00
commit 0224bda78c
3 changed files with 6 additions and 3 deletions
pandora_console
pandora_server/lib/PandoraFMS

@ -53,6 +53,8 @@ ADD COLUMN `id_agent_data` int not null default 0 AFTER `script_type`;
ALTER TABLE `tusuario` CHANGE COLUMN `metaconsole_data_section` `metaconsole_data_section` TEXT NOT NULL DEFAULT '' ;
ALTER TABLE `tmensajes` ADD COLUMN `icon_notification` VARCHAR(250) NULL DEFAULT NULL AFTER `url`;
ALTER TABLE `tagente_modulo` ADD COLUMN `disabled_by_safe_mode` TINYINT UNSIGNED NOT NULL DEFAULT 0;
UPDATE `tncm_template` SET `vendors` = CONCAT('["', TRIM(BOTH '"' FROM TRIM(BOTH ']' FROM TRIM(BOTH '[' FROM vendors))), '"]'), `models` = CONCAT('["', TRIM(BOTH '"' FROM TRIM(BOTH ']' FROM TRIM(BOTH '[' FROM models))), '"]');
UPDATE `tncm_agent_data_template` SET `vendors` = CONCAT('["', TRIM(BOTH '"' FROM TRIM(BOTH ']' FROM TRIM(BOTH '[' FROM vendors))), '"]'), `models` = CONCAT('["', TRIM(BOTH '"' FROM TRIM(BOTH ']' FROM TRIM(BOTH '[' FROM models))), '"]');

@ -219,6 +219,7 @@ CREATE TABLE IF NOT EXISTS `tagente_modulo` (
`flag` TINYINT UNSIGNED DEFAULT 1,
`id_modulo` INT UNSIGNED DEFAULT 0,
`disabled` TINYINT UNSIGNED NOT NULL DEFAULT 0,
`disabled_by_safe_mode` TINYINT UNSIGNED NOT NULL DEFAULT 0,
`id_export` SMALLINT UNSIGNED DEFAULT 0,
`plugin_user` TEXT,
`plugin_pass` TEXT,

@ -7767,12 +7767,12 @@ sub safe_mode($$$$$$) {
# Going to critical. Disable the rest of the modules.
if ($new_status == MODULE_CRITICAL) {
logger($pa_config, "Enabling safe mode for agent " . $agent->{'nombre'}, 10);
db_do($dbh, 'UPDATE tagente_modulo SET disabled=1 WHERE id_agente=? AND id_agente_modulo!=?', $agent->{'id_agente'}, $module->{'id_agente_modulo'});
db_do($dbh, 'UPDATE tagente_modulo SET disabled=1, disabled_by_safe_mode=1 WHERE id_agente=? AND id_agente_modulo!=? AND disabled=0', $agent->{'id_agente'}, $module->{'id_agente_modulo'});
}
# Coming back from critical. Enable the rest of the modules.
elsif ($known_status == MODULE_CRITICAL) {
logger($pa_config, "Disabling safe mode for agent " . $agent->{'nombre'}, 10);
db_do($dbh, 'UPDATE tagente_modulo SET disabled=0 WHERE id_agente=? AND id_agente_modulo!=?', $agent->{'id_agente'}, $module->{'id_agente_modulo'});
db_do($dbh, 'UPDATE tagente_modulo SET disabled=0, disabled_by_safe_mode=0 WHERE id_agente=? AND id_agente_modulo!=? AND disabled_by_safe_mode=1', $agent->{'id_agente'}, $module->{'id_agente_modulo'});
# Prevent the modules from becoming unknown!
db_do ($dbh, 'UPDATE tagente_estado SET utimestamp = ? WHERE id_agente = ? AND id_agente_modulo!=?', time(), $agent->{'id_agente'}, $module->{'id_agente_modulo'});
@ -7798,7 +7798,7 @@ sub pandora_safe_mode_modules_update {
# If status is critical, disable the rest of the modules.
if ($status == MODULE_CRITICAL) {
logger($pa_config, "Update modules for safe mode agent with alias:" . $agent->{'alias'} . ".", 10);
db_do($dbh, 'UPDATE tagente_modulo SET disabled=1 WHERE id_agente=? AND id_agente_modulo!=?', $agent_id, $agent->{'safe_mode_module'});
db_do($dbh, 'UPDATE tagente_modulo SET disabled=1, disabled_by_safe_mode=1 WHERE id_agente=? AND id_agente_modulo!=? AND disabled=0', $agent_id, $agent->{'safe_mode_module'});
}
}