From 731cc195ecbf7f61c51e61baae54844acead7afb Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 12 Feb 2024 17:47:46 +0100 Subject: [PATCH] fix safe mode recovery --- pandora_console/extras/mr/68.sql | 2 ++ pandora_console/pandoradb.sql | 1 + pandora_server/lib/PandoraFMS/Core.pm | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql index aa815a869a..3b01e115b6 100644 --- a/pandora_console/extras/mr/68.sql +++ b/pandora_console/extras/mr/68.sql @@ -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))), '"]'); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 43da6c72c9..e340dfbf27 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -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, diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 21ba802908..92906b9969 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -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'}); } }