From 6b8c399f7db2a3fe42e504b316740da65380371f Mon Sep 17 00:00:00 2001 From: Junichi Satoh Date: Sun, 16 Nov 2014 07:46:43 +0900 Subject: [PATCH] Improved to be able to define agent name using external command. --- pandora_agents/unix/pandora_agent | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index c15fe50068..207d9eb93c 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -126,6 +126,7 @@ my %DefaultConf = ( 'interval' => 300, 'debug' => 0, 'agent_name' => hostname (), + 'agent_name_cmd' => '', 'description' => '', 'group' => '', 'encoding' => 'UTF-8', @@ -732,6 +733,20 @@ sub read_config (;$) { # Module, plugin and collection definitions parse_conf_modules(\@file); + # If agent_name_cmd is defined, agent_name is set by command result. + if ($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 ''); + } + # Update the agent MD5 since agent_name may have changed $AgentMD5 = md5 ($Conf{'agent_name'}); $RemoteConfFile = "$AgentMD5.conf";