From fa2f98f2abe5f9d7fffd247b4fc776118f4e4290 Mon Sep 17 00:00:00 2001
From: Daniel Maya <daniel.maya@artica.es>
Date: Tue, 5 Jul 2016 11:53:43 +0200
Subject: [PATCH] alerts disabled agents, return to normal state. Ticket #3806.

(cherry picked from commit 68ad5319186fbe254f5f057dfe21666111648c71)
---
 pandora_server/util/pandora_db.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl
index 5a452380e0..09c78172a4 100644
--- a/pandora_server/util/pandora_db.pl
+++ b/pandora_server/util/pandora_db.pl
@@ -165,6 +165,12 @@ 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 JOIN talert_template_modules t2 ON 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;
 		$ulimit_timestamp = time() - (86400 * $conf->{'_days_purge'});