diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 22b7f22516..cf437d4116 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1530,6 +1530,11 @@ sub pandora_process_module ($$$$$$$$$;$) { # Update module status count. $mark_for_update = 1; + + # Safe mode execution. + if ($agent->{'safe_mode_module'} != 0) { + safe_mode($pa_config, $agent, $module, $new_status, $known_status, $dbh); + } } # Set not-init modules to normal status even if min_ff_event is not matched the first time they receive data. # if critical or warning status, just pass through here and wait the time min_ff_event will be matched. @@ -5473,6 +5478,30 @@ sub pandora_output_password($$) { return $decrypted_password; } +########################################################################## +=head2 C<< safe_mode (I<$pa_config>, I<$agent>, I<$module>, I<$new_status>, I<$known_status>, I<$dbh>) >> + +Execute safe mode for the given agent based on the status of the given module. + +=cut +########################################################################## +sub safe_mode($$$$$$) { + my ($pa_config, $agent, $module, $new_status, $known_status, $dbh) = @_; + + return unless $agent->{'safe_mode_module'} > 0; + + # 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'}); + } + # 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'}); + } +} + # End of function declaration # End of defined Code diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 061e5f03b3..2b31c88796 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -68,6 +68,11 @@ our @EXPORT = qw( $OS_VERSION RECOVERED_ALERT FIRED_ALERT + MODULE_NORMAL + MODULE_CRITICAL + MODULE_WARNING + MODULE_UNKNOWN + MODULE_NOTINIT cron_get_closest_in_range cron_next_execution cron_next_execution_date @@ -127,6 +132,13 @@ use constant MFSERVER => 15; use constant SYNCSERVER => 16; use constant WUXSERVER => 17; +# Module status +use constant MODULE_NORMAL => 0; +use constant MODULE_CRITICAL => 1; +use constant MODULE_WARNING => 2; +use constant MODULE_UNKNOWN => 3; +use constant MODULE_NOTINIT => 4; + # Value for a metaconsole license type use constant METACONSOLE_LICENSE => 0x01;