diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index fab0ad7637..7b39f806d0 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -868,6 +868,11 @@ if ($update_agent) { // if modified some agent paramenter 'config_agents_update_config_token', array($id_agente, 'standby', $disabled ? "1" : "0") ); + + // Validate alerts for disabled agents. + if ($disabled) { + alerts_validate_alert_agent($id_agente); + } } if($tpolicy_group_old){ diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index eb6dc869f3..362a820d62 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -159,6 +159,11 @@ if ($update_agents) { 'config_agents_update_config_token', array($id_agent, 'standby', $values['disabled']) ); + + // Validate alerts for disabled agents. + if ($values['disabled'] == 1) { + alerts_validate_alert_agent($id_agent); + } } if($group_old || $result){ diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 57677b8dea..e8203b3530 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1431,6 +1431,32 @@ function alerts_get_effective_alert_actions($id_agent_module) { return $return; } +/** + * Validate alerts for the given module. + * + * @param int agent_module_id ID of the module + */ +function alerts_validate_alert_module ($agent_module_id) { + + db_process_sql(sprintf('UPDATE talert_template_modules + SET times_fired=0, internal_counter=0 + WHERE id_agent_module = %d', + $agent_module_id)); +} + +/** + * Validate alerts for the given agent. + * + * @param int agent_id ID of the agent + */ +function alerts_validate_alert_agent ($agent_id) { + db_process_sql(sprintf('UPDATE talert_template_modules tm + INNER JOIN tagente_modulo am ON tm.id_agent_module = am.id_agente_modulo + SET tm.times_fired=0, tm.internal_counter=0 + WHERE am.id_agente = %d', + $agent_id)); +} + /** * Validates an alert id or an array of alert id's. * diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 78cb1e8c96..4cc0e4a3b6 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -262,6 +262,11 @@ function modules_change_disabled($id_agent_module, $new_value = 1) { if ($current_disabled == $new_value) { continue; } + + // Validate alerts for disabled modules. + if ($new_value == 1) { + alerts_validate_alert_module($id_module); + } $id_agent_changed[] = modules_get_agentmodule_agent($id_module); $id_agent_module_changed[] = $id_module; @@ -2817,4 +2822,4 @@ function modules_get_state_condition($state, $prefix = "tae") { // If the state is not an expected state, return no condition return "1=1"; } -?> \ No newline at end of file +?> diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 8c9df508ca..ec683bbc30 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -171,11 +171,6 @@ sub pandora_purgedb ($$) { if (!defined($conf->{'_string_purge'})){ $conf->{'_string_purge'} = 7; } - # Update alert with last_fired older than today - time_threshold - my @templates = get_db_rows ($dbh, 'SELECT t1.id,t1.time_threshold FROM talert_templates t1 WHERE EXISTS ( SELECT * FROM talert_template_modules t2 WHERE t1.id = t2.id_alert_template );'); - foreach my $template(@templates) { - db_do($dbh, 'UPDATE talert_template_modules SET times_fired = 0 WHERE id_alert_template = ? AND times_fired > 0 AND last_fired < (? - ?)',$template->{'id'},time(),$template->{'time_threshold'}); - } if ($conf->{'_string_purge'} > 0) { $ulimit_access_timestamp = time() - 86400;