Merge branch 'ent-8026-autocreate-group-pandora-server' into 'develop'

Add support for autocreate_group_name.

See merge request artica/pandorafms!4625
This commit is contained in:
Daniel Rodriguez 2022-01-12 15:16:51 +00:00
commit f6f1064cdd
5 changed files with 26 additions and 6 deletions

View File

@ -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).

View File

@ -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).

View File

@ -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);
}

View File

@ -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);

View File

@ -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;