diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index 7e53d28c39..7dc311915c 100644 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -348,6 +348,9 @@ fsnmp /usr/bin/pandorafsnmp autocreate_group 10 +# Works like autocreate_group, except the name of the group is specified (instead of its id). Do not set both. +#autocreate_group_name Unknown + # If set to 1, new agents will be added to the group specified by autocreate_group (the group specified by the agent will be used as fallback). # If set to 0, new agents will be added to the group specified by the agent (the group specified by autocreate_group will be used as fallback). diff --git a/pandora_server/conf/pandora_server.conf.windows b/pandora_server/conf/pandora_server.conf.windows index 9d953cfa94..0a2717793c 100644 --- a/pandora_server/conf/pandora_server.conf.windows +++ b/pandora_server/conf/pandora_server.conf.windows @@ -274,6 +274,9 @@ dataserver_threads 2 autocreate_group 10 +# Works like autocreate_group, except the name of the group is specified (instead of its id). Do not set both. +#autocreate_group_name Unknown + # If set to 1, new agents will be added to the group specified by autocreate_group (the group specified by the agent will be used as fallback). # If set to 0, new agents will be added to the group specified by the agent (the group specified by autocreate_group will be used as fallback). diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 7ca5b97e62..3f0e36c7ff 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -398,6 +398,7 @@ sub pandora_load_config { $pa_config->{'autocreate_group'} = -1; $pa_config->{'autocreate_group_force'} = 1; + $pa_config->{'autocreate_group_name'} = ''; $pa_config->{'autocreate'} = 1; # max log size (bytes) @@ -942,6 +943,9 @@ sub pandora_load_config { elsif ($parametro =~ m/^autocreate_group_force\s+([0-1])/i) { $pa_config->{'autocreate_group_force'}= clean_blank($1); } + elsif ($parametro =~ m/^autocreate_group_name\s(.*)/i) { + $pa_config->{'autocreate_group_name'}= clean_blank($1); + } elsif ($parametro =~ m/^discovery_threads\s+([0-9]*)/i) { $pa_config->{'discovery_threads'}= clean_blank($1); } diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 9058d83e96..9d1736266f 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -3846,7 +3846,8 @@ sub pandora_get_agent_group { my ($pa_config, $dbh, $agent_name, $agent_group, $agent_group_password) = @_; my $group_id; - my @groups = $pa_config->{'autocreate_group_force'} == 1 ? ($pa_config->{'autocreate_group'}, $agent_group) : ($agent_group, $pa_config->{'autocreate_group'}); + my $auto_group = $pa_config->{'autocreate_group_name'} ne '' ? $pa_config->{'autocreate_group_name'} : $pa_config->{'autocreate_group'}; + my @groups = $pa_config->{'autocreate_group_force'} == 1 ? ($auto_group, $agent_group) : ($agent_group, $auto_group); foreach my $group (@groups) { next unless defined($group); diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index f3b6fd63aa..2bd398cfda 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -89,11 +89,20 @@ sub new ($$;$) { } } - if ($config->{'autocreate_group'} > 0 && !defined(get_group_name ($dbh, $config->{'autocreate_group'}))) { - my $msg = "Group id " . $config->{'autocreate_group'} . " does not exist (check autocreate_group config token)."; - logger($config, $msg, 3); - print_message($config, $msg, 1); - pandora_event ($config, $msg, 0, 0, 0, 0, 0, 'error', 0, $dbh); + if ($config->{'autocreate_group_name'} ne '') { + if (get_group_id($dbh, $config->{'autocreate_group_name'}) == -1) { + my $msg = "Group '" . $config->{'autocreate_group_name'} . "' does not exist (check autocreate_group_name config token)."; + logger($config, $msg, 3); + print_message($config, $msg, 1); + pandora_event ($config, $msg, 0, 0, 0, 0, 0, 'error', 0, $dbh); + } + } elsif ($config->{'autocreate_group'} > 0) { + if (!defined(get_group_name ($dbh, $config->{'autocreate_group'}))) { + my $msg = "Group id " . $config->{'autocreate_group'} . " does not exist (check autocreate_group config token)."; + logger($config, $msg, 3); + print_message($config, $msg, 1); + pandora_event ($config, $msg, 0, 0, 0, 0, 0, 'error', 0, $dbh); + } } bless $self, $class;