2008-04-16 Ramon Novoa <rnovoa@artica.es>

* 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
This commit is contained in:
Ramon Novoa 2008-04-16 16:52:34 +00:00
parent 86bb8b22fc
commit 1280425526
2 changed files with 16 additions and 16 deletions

View File

@ -1,3 +1,8 @@
2008-04-16 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/DB.pm: Small code optimization. Took a couple
of prepare statements out of a loop.
2008-04-16 Ramon Novoa <rnovoa@artica.es> 2008-04-16 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/DB.pm: Rewrote the alert engine. Small fixes. * lib/PandoraFMS/DB.pm: Rewrote the alert engine. Small fixes.

View File

@ -343,23 +343,19 @@ sub pandora_evaluate_compound_alert (%$$) {
return 0; 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()) { while (my $data_compound = $handle_compound->fetchrow_hashref()) {
# Get alert data if enabled # Get alert data if enabled
my $query_alert = "SELECT disable, times_fired FROM $handle_alert->execute($data_compound->{'id_aam'});
talerta_agente_modulo WHERE id_aam = " .
$data_compound->{'id_aam'} .
" AND disable = 0";
my $handle_alert = $dbh->prepare($query_alert);
$handle_alert->execute;
if ($handle_alert->rows == 0) { if ($handle_alert->rows == 0) {
$handle_alert->finish();
next; next;
} }
my $data_alert = $handle_alert->fetchrow_hashref(); my $data_alert = $handle_alert->fetchrow_hashref();
$handle_alert->finish();
# Check whether the alert was fired # Check whether the alert was fired
my $fired = $data_alert->{'times_fired'} > 0 ? 1 : 0; my $fired = $data_alert->{'times_fired'} > 0 ? 1 : 0;
@ -390,6 +386,7 @@ sub pandora_evaluate_compound_alert (%$$) {
} }
} }
$handle_alert->finish();
$handle_compound->finish(); $handle_compound->finish();
return $status; return $status;
} }
@ -424,21 +421,18 @@ sub pandora_generate_compound_alerts (%$$$$$$$) {
return; 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()) { while (my $data_compound = $handle_compound->fetchrow_hashref()) {
# Get compound alert parameters # Get compound alert parameters
my $query_alert = "SELECT * FROM talerta_agente_modulo WHERE id_aam = $handle_alert->execute($data_compound->{'id'});
'" . $data_compound->{'id'} . "'";
my $handle_alert = $dbh->prepare($query_alert);
$handle_alert->execute;
if ($handle_alert->rows == 0) { if ($handle_alert->rows == 0) {
$handle_alert->finish();
next; next;
} }
my $data_alert = $handle_alert->fetchrow_hashref(); my $data_alert = $handle_alert->fetchrow_hashref();
$handle_alert->finish();
# Evaluate the alert # Evaluate the alert
my $rc = pandora_evaluate_alert($pa_config, $timestamp, $data_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); $id_group, $depth + 1, $dbh);
} }
$handle_alert->finish();
$handle_compound->finish(); $handle_compound->finish();
} }