mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
new feature: added agent_alias_cmd in pandora_agent
This commit is contained in:
parent
b3e1125526
commit
622edc1369
@ -46,6 +46,12 @@ agent_name_cmd __rand__
|
|||||||
#Parent agent_name
|
#Parent agent_name
|
||||||
#parent_agent_name caprica
|
#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
|
# Agent description
|
||||||
#description This is a demo agent for Linux
|
#description This is a demo agent for Linux
|
||||||
|
|
||||||
|
@ -135,9 +135,10 @@ my %DefaultConf = (
|
|||||||
'interval' => 300,
|
'interval' => 300,
|
||||||
'debug' => 0,
|
'debug' => 0,
|
||||||
'agent_name' => '',
|
'agent_name' => '',
|
||||||
'agent_alias' => hostname(),
|
'agent_alias' => '',
|
||||||
'ehorus_conf' => undef,
|
'ehorus_conf' => undef,
|
||||||
'agent_name_cmd' => '',
|
'agent_name_cmd' => '',
|
||||||
|
'agent_alias_cmd' => '',
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'group' => '',
|
'group' => '',
|
||||||
'group_id' => undef,
|
'group_id' => undef,
|
||||||
@ -802,6 +803,23 @@ sub read_config (;$) {
|
|||||||
|
|
||||||
# Module, plugin and collection definitions
|
# Module, plugin and collection definitions
|
||||||
parse_conf_modules(\@file);
|
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 agent_name_cmd is defined, agent_name is set by command result.
|
||||||
if ($Conf{'agent_name'} eq '') {
|
if ($Conf{'agent_name'} eq '') {
|
||||||
|
@ -228,6 +228,15 @@ Pandora::Pandora_Agent_Conf::setFile (string *all_conf){
|
|||||||
key_values->push_back (kv);
|
key_values->push_back (kv);
|
||||||
continue;
|
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*/
|
/*Check if is a collection*/
|
||||||
pos = buffer.find("file_collection");
|
pos = buffer.find("file_collection");
|
||||||
|
@ -257,7 +257,36 @@ Pandora_Windows_Service::pandora_init () {
|
|||||||
// Read modules
|
// Read modules
|
||||||
this->modules = new Pandora_Module_List (conf_file);
|
this->modules = new Pandora_Module_List (conf_file);
|
||||||
delete []all_conf;
|
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.
|
// Get the agent name.
|
||||||
agent_name = conf->getValue ("agent_name");
|
agent_name = conf->getValue ("agent_name");
|
||||||
if (agent_name == "") {
|
if (agent_name == "") {
|
||||||
@ -299,13 +328,6 @@ Pandora_Windows_Service::pandora_init () {
|
|||||||
this->conf->setValue("agent_name", agent_name);
|
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;
|
pandora_agent = "PANDORA_AGENT=" + agent_name;
|
||||||
putenv(pandora_agent.c_str());
|
putenv(pandora_agent.c_str());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user