From 23e14342e9c9a68f66f9fd01ac9bb4d909238c15 Mon Sep 17 00:00:00 2001
From: Ramon Novoa <rnovoa@artica.es>
Date: Mon, 27 Apr 2009 16:55:06 +0000
Subject: [PATCH] 2009-04-27  Ramon Novoa  <rnovoa@artica.es>

	* lib/PandoraFMS/Core.pm: Generate one event for each alert (instead
	  of one event for each action).




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1657 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_server/ChangeLog              |  5 ++++
 pandora_server/lib/PandoraFMS/Core.pm | 36 ++++++++++-----------------
 2 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog
index 4338ec6222..70e5282278 100644
--- a/pandora_server/ChangeLog
+++ b/pandora_server/ChangeLog
@@ -1,3 +1,8 @@
+2009-04-27  Ramon Novoa  <rnovoa@artica.es>
+
+	* lib/PandoraFMS/Core.pm: Generate one event for each alert (instead
+	  of one event for each action).
+
 2009-04-27  Ramon Novoa  <rnovoa@artica.es>
 
 	* lib/PandoraFMS/ProducerConsumerServer.pm,
diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm
index 52a86e47e2..4c922e3267 100644
--- a/pandora_server/lib/PandoraFMS/Core.pm
+++ b/pandora_server/lib/PandoraFMS/Core.pm
@@ -390,17 +390,15 @@ sub pandora_execute_alert ($$$$$$$) {
 	# Execute actions
 	foreach my $action (@actions) {
 		logger($pa_config, "Alert (" . $alert->{'name'} . ") executed for agent " . $agent->{'nombre'}, 2);
-		if (pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $dbh) == 1) {
-
-			# Generate an event
-			my $tm_id = (defined ($alert->{'id_template_module'})) ? $alert->{'id_template_module'} : 0;
-			my ($text, $event) = ($alert_mode == 0) ? ('recovered', 'alert_recovered') : ('fired', 'alert_fired');
-
-			pandora_event ($pa_config, "Alert $text (" . $alert->{'description'} . ")",
-				           $agent->{'id_grupo'}, $agent->{'id_agente'}, $alert->{'priority'}, $tm_id,
-				           $alert->{'id_agent_module'}, $event,  $dbh);
-		}
+		pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $dbh);
 	}
+
+	# Generate an event
+	my ($text, $event) = ($alert_mode == 0) ? ('recovered', 'alert_recovered') : ('fired', 'alert_fired');
+
+	pandora_event ($pa_config, "Alert $text (" . $alert->{'description'} . ")",
+		           $agent->{'id_grupo'}, $agent->{'id_agente'}, $alert->{'priority'}, (defined ($alert->{'id_template_module'})) ? $alert->{'id_template_module'} : 0,
+		           $alert->{'id_agent_module'}, $event,  $dbh);
 }
 
 ##########################################################################
@@ -453,9 +451,6 @@ sub pandora_execute_action ($$$$$$$) {
 	} elsif ($action->{'name'} eq "Internal Audit") {
 		$field1 = subst_alert_macros ($field1, \%macros);
 		pandora_audit ($pa_config, $field1, defined ($agent) ? $agent->{'nombre'} : 'N/A', 'Alert (' . $alert->{'description'} . ')', $dbh);
-		
-		# Do not generate an event
-		return 0;
 
 	# Email		
 	} elsif ($action->{'name'} eq "eMail") {
@@ -469,12 +464,7 @@ sub pandora_execute_action ($$$$$$$) {
 	# Unknown
 	} else {
 		logger($pa_config, "Unknown action " . $action->{'name'}, 1);
-
-		# Do not generate an event
-		return 0 ;
 	}
-
-	return 1;
 }
 
 ##########################################################################
@@ -893,12 +883,12 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$) {
 			                                       FROM talert_actions, talert_commands
 			                                       WHERE talert_actions.id_alert_command = talert_commands.id
 			                                         AND talert_actions.id = ?', $alert->{'id_alert'});
-			if (defined ($action) && pandora_execute_action ($pa_config, '', undef, \%alert, 1, $action, $dbh) == 1) {
 
-				# Generate an event
-				pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")",
-					           0, 0, $alert->{'priority'}, 0, 0, 'alert_fired',  $dbh);
-			}
+			pandora_execute_action ($pa_config, '', undef, \%alert, 1, $action, $dbh) if (defined ($action));
+
+			# Generate an event
+			pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")",
+				           0, 0, $alert->{'priority'}, 0, 0, 'alert_fired',  $dbh);
 
 			# Update alert status
 			db_do ($dbh, 'UPDATE talert_snmp SET times_fired = ?, last_fired = ?, internal_counter = ? WHERE id_as = ?',