From 4f91a8f12b0b8ec08cb3c76becff422234742b8c Mon Sep 17 00:00:00 2001 From: danielmaya Date: Mon, 27 Nov 2017 15:01:09 +0100 Subject: [PATCH] Fixed empty agent_name in pandora_agent --- pandora_agents/unix/pandora_agent | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 632452d439..fa0766eeef 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -832,19 +832,23 @@ sub read_config (;$) { config_update('agent_name', $Conf{'agent_name'}); } elsif ($Conf{'agent_name_cmd'} ne '') { my $result = `$Conf{'agent_name_cmd'}`; - - # Use only the first line. - my ($temp_agent_name, $remain) = split(/\n/, $result); - chomp ($temp_agent_name); - - # Remove white spaces of the first and last. - $temp_agent_name =~ s/^ *(.*?) *$/$1/; - - $Conf{'agent_name'} = $temp_agent_name if ($temp_agent_name ne ''); - } else { - $Conf{'agent_name'} = hostname(); + if($result ne '') { + # Use only the first line. + my ($temp_agent_name, $remain) = split(/\n/, $result); + chomp ($temp_agent_name); + + # Remove white spaces of the first and last. + $temp_agent_name =~ s/^ *(.*?) *$/$1/; + + $Conf{'agent_name'} = $temp_agent_name if ($temp_agent_name ne ''); + } } } + + # Fall back to the hostname if agent_name is still empty. + if ($Conf{'agent_name'} eq '') { + $Conf{'agent_name'} = hostname(); + } # Update the agent MD5 since agent_name may have changed $AgentMD5 = md5 ($Conf{'agent_name'});