From c24aa44ee1a56290b64af4dc2877d6380b3cf694 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 2 Jun 2016 13:07:55 +0200 Subject: [PATCH] Server now can get the agent mode from agent --- pandora_server/lib/PandoraFMS/Core.pm | 8 +++++--- pandora_server/lib/PandoraFMS/DataServer.pm | 12 ++++++++---- pandora_server/lib/PandoraFMS/ReconServer.pm | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 8d44bf4c98..2a634e2db1 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -2786,12 +2786,12 @@ Create a new entry in B optionaly with position information =cut ########################################################################## -sub pandora_create_agent ($$$$$$$$$$;$$$$$$$) { +sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$) { my ($pa_config, $server_name, $agent_name, $address, $group_id, $parent_id, $os_id, $description, $interval, $dbh, $timezone_offset, $longitude, $latitude, $altitude, $position_description, - $custom_id, $url_address) = @_; + $custom_id, $url_address, $agent_mode) = @_; logger ($pa_config, "Server '$server_name' creating agent '$agent_name' address '$address'.", 10); @@ -2802,6 +2802,8 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$) { return; } } + + $agent_mode = 1 unless defined($agent_mode); $description = "Created by $server_name" unless ($description ne ''); my ($columns, $values) = db_insert_get_values ({ 'nombre' => safe_input($agent_name), @@ -2812,7 +2814,7 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$) { 'server_name' => $server_name, 'intervalo' => $interval, 'id_parent' => $parent_id, - 'modo' => 1, + 'modo' => $agent_mode, 'custom_id' => $custom_id, 'url_address' => $url_address, 'timezone_offset' => $timezone_offset diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 92324bed0e..bfbcd900e1 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -249,6 +249,10 @@ sub process_xml_data ($$$$$) { $parent_id = 0; } } + + # Get agent mode + my $agent_mode = 1; # Default value learning mode + $agent_mode = $data->{'agent_mode'} if (defined ($data->{'agent_mode'})); # Unknown agent! if (! defined ($agent_name) || $agent_name eq '') { @@ -331,7 +335,7 @@ sub process_xml_data ($$$$$) { $description = $data->{'description'} if (defined ($data->{'description'})); $agent_id = pandora_create_agent($pa_config, $pa_config->{'servername'}, $agent_name, $address, $group_id, $parent_id, $os, - $description, $interval, $dbh, $timezone_offset, undef, undef, undef, undef, $custom_id, $url_address); + $description, $interval, $dbh, $timezone_offset, undef, undef, undef, undef, $custom_id, $url_address, $agent_mode); if (! defined ($agent_id)) { return; @@ -596,8 +600,8 @@ sub process_module_data ($$$$$$$$$) { return; } - # Is the agent learning? - if ($agent->{'modo'} ne '1') { + # Is the agent not learning? + if ($agent->{'modo'} == 0) { logger($pa_config, "Learning mode disabled. Skipping module '$module_name' agent '$agent_name'.", 10); $ModuleSem->up (); return; @@ -697,7 +701,7 @@ sub process_module_data ($$$$$$$$$) { } # Update module configuration if in learning mode and not a policy module - if ($agent->{'modo'} eq '1' && $policy_linked == 0) { + if ((($agent->{'modo'} eq '1') || ($agent->{'modo'} eq '2')) && $policy_linked == 0) { update_module_configuration ($pa_config, $dbh, $module, $module_conf); } diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index a2453a8dd1..47535c922b 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -184,7 +184,7 @@ sub data_consumer ($$) { if ($agent_id > 0) { # Skip if not in learning mode - next if ($agent->{'modo'} != 1); + next unless (($agent->{'modo'} == 1) || ($agent->{'modo'} == 2)); } # Get the parent host