From 4a4fc60f21a59878c34dc6b9546931e11073dc7b Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Tue, 5 Mar 2013 10:53:17 +0000 Subject: [PATCH] 2013-03-05 Sergio Martin * util/pandora_manage.pl: Add update counts when validate all the alerts of a policy in CLI option. Bug 3606759 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7779 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 +++++ pandora_server/util/pandora_manage.pl | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 4e4daa5dbb..c99dd19366 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2013-03-05 Sergio Martin + + * util/pandora_manage.pl: Add update counts when validate + all the alerts of a policy in CLI option. Bug 3606759 + 2013-03-04 Sergio Martin * lib/PandoraFMS/Core.pm diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 6c13b4e4d3..34df35a6cc 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -2686,20 +2686,29 @@ sub cli_validate_policy_alerts() { if($#policy_alerts_id_array == -1) { print_log "[INFO] No alerts found in the policy '$policy_name'\n\n"; + return; } $policy_alerts_id = join(',',@policy_alerts_id_array); + #Get the fired alerts that match with the filter to update counts after validate it + my @fired_alerts = get_db_rows ($dbh, "SELECT id_agent_module, count(id) alerts FROM talert_template_modules WHERE id_policy_alerts IN (?) AND times_fired > 0 GROUP BY id_agent_module", $policy_alerts_id); + print_log "[INFO] Validating the alerts of the policy '$policy_name'\n\n"; my $res = db_update ($dbh, "UPDATE talert_template_modules SET times_fired = 0, internal_counter = 0 WHERE id_policy_alerts IN (?)", $policy_alerts_id); - + if($res == -1) { print_log "[ERROR] Alerts cannot be validated\n\n"; } else { - # Update fired alerts count in agents - db_update ($dbh, "UPDATE tagente SET fired_count = 0"); + # Update fired alerts count in agents if necessary + if($#fired_alerts > -1) { + foreach my $fired_alert (@fired_alerts) { + my $id_agent = get_module_agent_id($dbh, $fired_alert->{'id_agent_module'}); + db_update ($dbh, 'UPDATE tagente SET fired_count=fired_count-? WHERE id_agente=?', $fired_alert->{'alerts'}, $id_agent); + } + } } }