From 17ec8525eae9b1f1bf1eea5b516c117583b10394 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Mon, 1 Dec 2014 12:40:58 +0100 Subject: [PATCH] Mark a module for update after setting its status to prevent race conditions. --- pandora_server/lib/PandoraFMS/Core.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 4448af319c..59425b2dca 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1140,6 +1140,7 @@ sub pandora_process_module ($$$$$$$$$;$) { my $last_known_status = $agent_status->{'last_known_status'}; my $last_error = defined ($module->{'last_error'}) ? $module->{'last_error'} : $agent_status->{'last_error'}; my $ff_start_utimestamp = $agent_status->{'ff_start_utimestamp'}; + my $mark_for_update = 0; # Get new status my $new_status = get_module_status ($processed_data, $module, $module_type); @@ -1194,8 +1195,8 @@ sub pandora_process_module ($$$$$$$$$;$) { $status = $new_status; $last_status = $new_status; - # Update module status count - pandora_mark_agent_for_module_update ($dbh, $agent->{'id_agente'}); + # Update module status count. + $mark_for_update = 1; } # Set not-init modules to normal status even if min_ff_event is not matched the first time they receive data. # if critical or warning status, just pass through here and wait the time min_ff_event will be matched. @@ -1204,8 +1205,8 @@ sub pandora_process_module ($$$$$$$$$;$) { $status = 0; $last_status = $new_status; - # Update module status count - pandora_mark_agent_for_module_update ($dbh, $agent->{'id_agente'}); + # Update module status count. + $mark_for_update = 1; } # If unknown modules receive data, restore status even if min_ff_event is not matched. elsif ($status == 3) { @@ -1214,8 +1215,8 @@ sub pandora_process_module ($$$$$$$$$;$) { generate_status_event ($pa_config, $processed_data, $agent, $module, $new_status, $status, $last_known_status, $dbh); $status = $new_status; - # Update module status count - pandora_mark_agent_for_module_update ($dbh, $agent->{'id_agente'}); + # Update module status count. + $mark_for_update = 1; } else { $last_status = $new_status; } @@ -1260,6 +1261,11 @@ sub pandora_process_module ($$$$$$$$$;$) { else { logger($pa_config, "Alerts inhibited for agent '" . $agent->{'nombre'} . "'.", 10); } + + # Update module status count + if ($mark_for_update == 1) { + pandora_mark_agent_for_module_update ($dbh, $agent->{'id_agente'}); + } } ########################################################################