Agent remote cmd fixes

This commit is contained in:
fbsanchez 2019-11-14 17:04:47 +01:00
parent 78443a029d
commit 17f324ef8d
1 changed files with 16 additions and 9 deletions

View File

@ -979,6 +979,9 @@ sub read_config (;$) {
$Conf{'secondary_server_opts'} = '-x \'' . $Conf{'secondary_server_pwd'} . '\' ' . $Conf{'secondary_server_opts'} if ($Conf{'secondary_server_pwd'} ne '');
$Conf{'secondary_server_opts'} = '-c ' . $Conf{'secondary_server_opts'} if ($Conf{'secondary_server_ssl'} eq '1');
}
# Check remote commands
prepare_commands();
}
#################################################################################
@ -1421,7 +1424,7 @@ sub check_collections () {
################################################################################
# Check for remote commands defined.
################################################################################
sub prepare_remote_commands {
sub prepare_commands {
if ($YAML == 0) {
log_message(
'error',
@ -3272,24 +3275,28 @@ while (1) {
check_collections () unless ($Conf{'debug'} eq '1');
if ($Conf{'debug'} ne '1') {
# Check remote commands
prepare_remote_commands ();
# Cleanup old .rcmd.done files.
my %registered = map { $_.'.rcmd.done' => 1 } keys %{$Conf{'commands'}};
# Cleanup old .rcmd and .rcmd.done files.
my %registered = map { $_.'.rcmd' => 1 } keys %{$Conf{'commands'}};
if(opendir(my $dir, $ConfDir.'/commands/')) {
while (my $item = readdir($dir)) {
# Skip other files.
next if ($item !~ /\.rcmd\.done$/);
next if ($item !~ /\.rcmd$/);
# Clean .rcmd.done file if its command is not referenced in conf.
if (!defined($registered{$item})) {
if (-e $item) {
unlink ($item);
}
if (-e $item.'.done') {
unlink ($item.'.done');
}
}
}
# Close dir.
closedir($dir);
}
}
# Launch broker agents
@BrokerPid = ();
my @broker_agents = read_config ('broker_agent');