From 45e1716c512bcc3be6c830c2e9468c277630cf8a Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Wed, 6 Mar 2013 16:50:50 +0000 Subject: [PATCH] 2013-03-06 Sergio Martin * lib/PandoraFMS/Core.pm: Fixed alert fired counts when reset internal counter and fired times in threshold loop git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7797 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 +++++ pandora_server/lib/PandoraFMS/Core.pm | 28 +++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 29f8282b8e..8c5c705009 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2013-03-06 Sergio Martin + + * lib/PandoraFMS/Core.pm: Fixed alert fired counts when + reset internal counter and fired times in threshold loop + 2013-03-06 Sergio Martin * lib/PandoraFMS/Core.pm: Add macros substitution in all the diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 710681d10e..267dc3adad 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -365,6 +365,11 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) { $status = 5; } + # Update fired alert when cesead or recover + if(defined ($agent) && ($status == 3 || $status == 4)) { + db_do ($dbh, 'UPDATE tagente SET fired_count=fired_count-1 WHERE id_agente=?', $agent->{'id_agente'}); + } + # Check for valid data # Simple alert if (defined ($alert->{'id_template_module'})) { @@ -438,6 +443,12 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) { # Check min and max alert limits return 2 if (($alert->{'internal_counter'} < $alert->{'min_alerts'}) || ($alert->{'times_fired'} >= $alert->{'max_alerts'})); + + # Update fired alert first time + # (if is fist time after ceased it was decreased previously and will be compensated) + if(defined ($agent)) { + db_do ($dbh, 'UPDATE tagente SET fired_count=fired_count+1 WHERE id_agente=?', $agent->{'id_agente'}); + } return 0; #Launch the alert } @@ -479,11 +490,6 @@ sub pandora_process_alert ($$$$$$$$;$) { db_do($dbh, 'UPDATE ' . $table . ' SET times_fired = 0, internal_counter = 0 WHERE id = ?', $id); - # Update fired alert count - if (defined ($agent)) { - db_do ($dbh, 'UPDATE tagente SET fired_count=fired_count-1 WHERE id_agente=?', $agent->{'id_agente'}); - } - # Critical_instructions, warning_instructions, unknown_instructions my $critical_instructions = get_db_value ($dbh, 'SELECT critical_instructions FROM tagente_modulo WHERE id_agente_modulo = ?', $alert->{'id_agent_module'}); my $warning_instructions = get_db_value ($dbh, 'SELECT warning_instructions FROM tagente_modulo WHERE id_agente_modulo = ?', $alert->{'id_agent_module'}); @@ -517,11 +523,6 @@ sub pandora_process_alert ($$$$$$$$;$) { db_do($dbh, 'UPDATE talert_template_module_actions SET last_execution = 0 WHERE id_alert_template_module = ?', $id); } - # Update fired alert count - if (defined ($agent)) { - db_do ($dbh, 'UPDATE tagente SET fired_count=fired_count-1 WHERE id_agente=?', $agent->{'id_agente'}); - } - pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 0, $dbh, $timestamp, $extra_macros); return; } @@ -541,7 +542,6 @@ sub pandora_process_alert ($$$$$$$$;$) { # Increment internal counter if ($rc == 2) { - # Update alert status $alert->{'internal_counter'} += 1; @@ -555,7 +555,6 @@ sub pandora_process_alert ($$$$$$$$;$) { # Execute if ($rc == 0) { - # Update alert status $alert->{'times_fired'} += 1; $alert->{'internal_counter'} += 1; @@ -564,11 +563,6 @@ sub pandora_process_alert ($$$$$$$$;$) { last_fired = ?, internal_counter = ? ' . $new_interval . ' WHERE id = ?', $alert->{'times_fired'}, $utimestamp, $alert->{'internal_counter'}, $id); - # Update fired alert count only in first fired time - if (defined ($agent) && $alert->{'times_fired'} == 1) { - db_do ($dbh, 'UPDATE tagente SET fired_count=fired_count+1 WHERE id_agente=?', $agent->{'id_agente'}); - } - pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 1, $dbh, $timestamp, $extra_macros); return; }