Merge branch 'feature/safe_mode_module' into 'develop'

Add safe-module mode support.

See merge request artica/pandorafms!1103
This commit is contained in:
vgilc 2017-11-21 12:16:05 +01:00
commit 480ebd4c9b
2 changed files with 41 additions and 0 deletions

View File

@ -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

View File

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