diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 1f78ab8079..7817a40167 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -7010,8 +7010,21 @@ Returns 1 if this server is the current master, 0 otherwise. =cut ########################################################################## -sub pandora_is_master ($) { - my ($pa_config) = @_; +sub pandora_is_master ($;$) { + my ($pa_config, $dbh) = @_; + + # When multiprocess is enabled the variable $Master is not shared between + # servers. + if (defined($dbh) && $pa_config->{'multiprocess'} == 1) { + my $current_master = get_db_value_limit ($dbh, 'SELECT name FROM tserver + WHERE master <> 0 AND status = 1 + ORDER BY master DESC', 1); + if (defined($current_master) && $current_master eq $pa_config->{'servername'}) { + return 1; + } + + return 0; + } if ($Master eq $pa_config->{'servername'}) { return 1; diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 3dc3d44f17..cc9b8fe963 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -143,7 +143,7 @@ sub data_producer ($) { # By default, after create a tasks it takes the utimestamp to 0 # Status -1 means "done". my @rows; - if (pandora_is_master($pa_config) == 0) { + if (pandora_is_master($pa_config, $dbh) == 0) { @rows = get_db_rows ($dbh, 'SELECT * FROM trecon_task WHERE id_recon_server = ? AND disabled = 0 diff --git a/pandora_server/lib/PandoraFMS/InventoryServer.pm b/pandora_server/lib/PandoraFMS/InventoryServer.pm index e6b070f4d8..daab7f624f 100644 --- a/pandora_server/lib/PandoraFMS/InventoryServer.pm +++ b/pandora_server/lib/PandoraFMS/InventoryServer.pm @@ -83,7 +83,7 @@ sub data_producer ($) { my @tasks; my @rows; - if (pandora_is_master($pa_config) == 0) { + if (pandora_is_master($pa_config, $dbh) == 0) { if ($pa_config->{'dbengine'} ne 'oracle') { @rows = get_db_rows ($dbh, 'SELECT tagent_module_inventory.id_agent_module_inventory, tagent_module_inventory.flag, tagent_module_inventory.timestamp diff --git a/pandora_server/lib/PandoraFMS/NetworkServer.pm b/pandora_server/lib/PandoraFMS/NetworkServer.pm index 87ef0fe2c7..6d0b848fb1 100644 --- a/pandora_server/lib/PandoraFMS/NetworkServer.pm +++ b/pandora_server/lib/PandoraFMS/NetworkServer.pm @@ -96,7 +96,7 @@ sub data_producer ($) { my @rows; my $network_filter = enterprise_hook ('get_network_filter', [$pa_config]); - if (pandora_is_master($pa_config) == 0) { + if (pandora_is_master($pa_config, $dbh) == 0) { @rows = get_db_rows ($dbh, 'SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag, tagente_estado.current_interval + tagente_estado.last_execution_try AS time_left, last_execution_try FROM tagente, tagente_modulo, tagente_estado WHERE server_name = ? diff --git a/pandora_server/lib/PandoraFMS/PluginServer.pm b/pandora_server/lib/PandoraFMS/PluginServer.pm index 9751372d04..a8cbd159b5 100644 --- a/pandora_server/lib/PandoraFMS/PluginServer.pm +++ b/pandora_server/lib/PandoraFMS/PluginServer.pm @@ -96,7 +96,7 @@ sub data_producer ($) { my @tasks; my @rows; - if (pandora_is_master($pa_config) == 0) { + if (pandora_is_master($pa_config, $dbh) == 0) { @rows = get_db_rows ($dbh, 'SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag, tagente_estado.current_interval + tagente_estado.last_execution_try AS time_left, last_execution_try FROM tagente, tagente_modulo, tagente_estado WHERE server_name = ? diff --git a/pandora_server/lib/PandoraFMS/PredictionServer.pm b/pandora_server/lib/PandoraFMS/PredictionServer.pm index 282a8eeb20..dfa70f38db 100644 --- a/pandora_server/lib/PandoraFMS/PredictionServer.pm +++ b/pandora_server/lib/PandoraFMS/PredictionServer.pm @@ -93,7 +93,7 @@ sub data_producer ($) { my @tasks; my @rows; - if (pandora_is_master($pa_config) == 0) { + if (pandora_is_master($pa_config, $dbh) == 0) { @rows = get_db_rows ($dbh, 'SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag, last_execution_try FROM tagente, tagente_modulo, tagente_estado diff --git a/pandora_server/lib/PandoraFMS/WMIServer.pm b/pandora_server/lib/PandoraFMS/WMIServer.pm index 2b053c7ce0..2a01cf89dd 100644 --- a/pandora_server/lib/PandoraFMS/WMIServer.pm +++ b/pandora_server/lib/PandoraFMS/WMIServer.pm @@ -94,7 +94,7 @@ sub data_producer ($) { my @tasks; my @rows; - if (pandora_is_master($pa_config) == 0) { + if (pandora_is_master($pa_config, $dbh) == 0) { @rows = get_db_rows ($dbh, 'SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag, tagente_estado.current_interval + tagente_estado.last_execution_try AS time_left, last_execution_try FROM tagente, tagente_modulo, tagente_estado WHERE server_name = ? diff --git a/pandora_server/lib/PandoraFMS/WebServer.pm b/pandora_server/lib/PandoraFMS/WebServer.pm index 7f66d8ad89..40b4af3073 100644 --- a/pandora_server/lib/PandoraFMS/WebServer.pm +++ b/pandora_server/lib/PandoraFMS/WebServer.pm @@ -124,7 +124,7 @@ sub data_producer ($) { my @tasks; my @rows; - if (pandora_is_master($pa_config) == 0) { + if (pandora_is_master($pa_config, $dbh) == 0) { @rows = get_db_rows ($dbh, 'SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag, tagente_estado.current_interval + tagente_estado.last_execution_try AS time_left, last_execution_try FROM tagente, tagente_modulo, tagente_estado WHERE server_name = ?