From 1280425526b8a0d93f38bd2a452e76ef6be06c6a Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Wed, 16 Apr 2008 16:52:34 +0000 Subject: [PATCH] 2008-04-16 Ramon Novoa * lib/PandoraFMS/DB.pm: Small code optimization. Took a couple of prepare statements out of a loop. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@808 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 +++++ pandora_server/lib/PandoraFMS/DB.pm | 27 +++++++++++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 8c7a75f55f..16d6cd9856 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2008-04-16 Ramon Novoa + + * lib/PandoraFMS/DB.pm: Small code optimization. Took a couple + of prepare statements out of a loop. + 2008-04-16 Ramon Novoa * lib/PandoraFMS/DB.pm: Rewrote the alert engine. Small fixes. diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 856e36d954..92ba6dc0da 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -343,23 +343,19 @@ sub pandora_evaluate_compound_alert (%$$) { return 0; } + my $query_alert = "SELECT disable, times_fired FROM + talerta_agente_modulo WHERE id_aam = ? AND disable = 0"; + my $handle_alert = $dbh->prepare($query_alert); + while (my $data_compound = $handle_compound->fetchrow_hashref()) { # Get alert data if enabled - my $query_alert = "SELECT disable, times_fired FROM - talerta_agente_modulo WHERE id_aam = " . - $data_compound->{'id_aam'} . - " AND disable = 0"; - my $handle_alert = $dbh->prepare($query_alert); - - $handle_alert->execute; + $handle_alert->execute($data_compound->{'id_aam'}); if ($handle_alert->rows == 0) { - $handle_alert->finish(); next; } my $data_alert = $handle_alert->fetchrow_hashref(); - $handle_alert->finish(); # Check whether the alert was fired my $fired = $data_alert->{'times_fired'} > 0 ? 1 : 0; @@ -390,6 +386,7 @@ sub pandora_evaluate_compound_alert (%$$) { } } + $handle_alert->finish(); $handle_compound->finish(); return $status; } @@ -424,21 +421,18 @@ sub pandora_generate_compound_alerts (%$$$$$$$) { return; } + my $query_alert = "SELECT * FROM talerta_agente_modulo WHERE id_aam = ?"; + my $handle_alert = $dbh->prepare($query_alert); + while (my $data_compound = $handle_compound->fetchrow_hashref()) { # Get compound alert parameters - my $query_alert = "SELECT * FROM talerta_agente_modulo WHERE id_aam = - '" . $data_compound->{'id'} . "'"; - my $handle_alert = $dbh->prepare($query_alert); - - $handle_alert->execute; + $handle_alert->execute($data_compound->{'id'}); if ($handle_alert->rows == 0) { - $handle_alert->finish(); next; } my $data_alert = $handle_alert->fetchrow_hashref(); - $handle_alert->finish(); # Evaluate the alert my $rc = pandora_evaluate_alert($pa_config, $timestamp, $data_alert, @@ -460,6 +454,7 @@ sub pandora_generate_compound_alerts (%$$$$$$$) { $id_group, $depth + 1, $dbh); } + $handle_alert->finish(); $handle_compound->finish(); }