Merge branch '715-Nueva-feature--agent_alias_cmd-dev' into 'develop'
new feature: added agent_alias_cmd in pandora_agent See merge request !373
This commit is contained in:
commit
fbe59fddc2
|
@ -46,6 +46,12 @@ agent_name_cmd __rand__
|
|||
#Parent agent_name
|
||||
#parent_agent_name caprica
|
||||
|
||||
# By default, agent takes machine alias
|
||||
#agent_alias
|
||||
|
||||
# To define agent alias by specific command, define 'agent_alias_cmd'.
|
||||
#agent_alias_cmd
|
||||
|
||||
# Agent description
|
||||
#description This is a demo agent for Linux
|
||||
|
||||
|
|
|
@ -135,9 +135,10 @@ my %DefaultConf = (
|
|||
'interval' => 300,
|
||||
'debug' => 0,
|
||||
'agent_name' => '',
|
||||
'agent_alias' => hostname(),
|
||||
'agent_alias' => '',
|
||||
'ehorus_conf' => undef,
|
||||
'agent_name_cmd' => '',
|
||||
'agent_alias_cmd' => '',
|
||||
'description' => '',
|
||||
'group' => '',
|
||||
'group_id' => undef,
|
||||
|
@ -803,6 +804,23 @@ sub read_config (;$) {
|
|||
# Module, plugin and collection definitions
|
||||
parse_conf_modules(\@file);
|
||||
|
||||
# If agent_alias_cmd is defined, agent_alias is set by command result.
|
||||
if ($Conf{'agent_alias'} eq '') {
|
||||
if ($Conf{'agent_alias_cmd'} ne '') {
|
||||
my $result = `$Conf{'agent_alias_cmd'}`;
|
||||
# Use only the first line.
|
||||
my ($temp_agent_alias, $remain2) = split(/\n/, $result);
|
||||
chomp ($temp_agent_alias);
|
||||
|
||||
# Remove white spaces of the first and last.
|
||||
$temp_agent_alias =~ s/^ *(.*?) *$/$1/;
|
||||
|
||||
$Conf{'agent_alias'} = $temp_agent_alias if ($temp_agent_alias ne '');
|
||||
} else {
|
||||
$Conf{'agent_alias'} = hostname();
|
||||
}
|
||||
}
|
||||
|
||||
# If agent_name_cmd is defined, agent_name is set by command result.
|
||||
if ($Conf{'agent_name'} eq '') {
|
||||
if ($Conf{'agent_name_cmd'} eq '__rand__') {
|
||||
|
|
|
@ -229,6 +229,15 @@ Pandora::Pandora_Agent_Conf::setFile (string *all_conf){
|
|||
continue;
|
||||
}
|
||||
|
||||
/*Check if is a agent_alias_cmd"*/
|
||||
pos = buffer.find("agent_alias_cmd");
|
||||
if (pos != string::npos){
|
||||
Key_Value kv;
|
||||
kv.parseLineByPosition(buffer, 15);
|
||||
key_values->push_back (kv);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*Check if is a collection*/
|
||||
pos = buffer.find("file_collection");
|
||||
if(pos != string::npos) {
|
||||
|
|
|
@ -258,6 +258,35 @@ Pandora_Windows_Service::pandora_init () {
|
|||
this->modules = new Pandora_Module_List (conf_file);
|
||||
delete []all_conf;
|
||||
|
||||
// Get the agent alias.
|
||||
agent_alias = conf->getValue ("agent_alias");
|
||||
if (agent_alias == "") {
|
||||
agent_alias_cmd = conf->getValue ("agent_alias_cmd");
|
||||
if (agent_alias_cmd != "") {
|
||||
agent_alias_cmd = "cmd.exe /c \"" + agent_alias_cmd + "\"";
|
||||
static string temp_agent_alias = getAgentNameFromCmdExec(agent_alias_cmd);
|
||||
|
||||
// Delete new line and carriage return.
|
||||
pos = temp_agent_alias.find("\n");
|
||||
if(pos != string::npos) {
|
||||
temp_agent_alias.erase(pos, temp_agent_alias.size () - pos);
|
||||
}
|
||||
pos = temp_agent_alias.find("\r");
|
||||
if(pos != string::npos) {
|
||||
temp_agent_alias.erase(pos, temp_agent_alias.size () - pos);
|
||||
}
|
||||
|
||||
// Remove leading and trailing white spaces.
|
||||
temp_agent_alias = trim(temp_agent_alias);
|
||||
if (temp_agent_alias != "") {
|
||||
agent_alias = temp_agent_alias;
|
||||
}
|
||||
} else {
|
||||
agent_alias = Pandora_Windows_Info::getSystemName ();
|
||||
}
|
||||
}
|
||||
this->conf->setValue("agent_alias", agent_alias);
|
||||
|
||||
// Get the agent name.
|
||||
agent_name = conf->getValue ("agent_name");
|
||||
if (agent_name == "") {
|
||||
|
@ -299,13 +328,6 @@ Pandora_Windows_Service::pandora_init () {
|
|||
this->conf->setValue("agent_name", agent_name);
|
||||
}
|
||||
|
||||
// Get the agent alias.
|
||||
agent_alias = conf->getValue ("agent_alias");
|
||||
if (agent_alias == "") {
|
||||
agent_alias = Pandora_Windows_Info::getSystemName ();
|
||||
this->conf->setValue("agent_alias", agent_alias);
|
||||
}
|
||||
|
||||
pandora_agent = "PANDORA_AGENT=" + agent_name;
|
||||
putenv(pandora_agent.c_str());
|
||||
|
||||
|
|
Loading…
Reference in New Issue