Send the eHorus key as a custom field (win32).

This commit is contained in:
Ramon Novoa 2016-12-07 15:51:21 +01:00
parent a5cc574061
commit 2ee3225e56
2 changed files with 52 additions and 5 deletions

View File

@ -385,7 +385,7 @@ Pandora_Windows_Service::getXmlHeader () {
char timestamp[20]; char timestamp[20];
string agent_name, os_name, os_version, encoding, value, xml, address, parent_agent_name, agent_name_cmd; string agent_name, os_name, os_version, encoding, value, xml, address, parent_agent_name, agent_name_cmd;
string custom_id, url_address, latitude, longitude, altitude, position_description, gis_exec, gis_result, agent_mode; string custom_id, url_address, latitude, longitude, altitude, position_description, gis_exec, gis_result, agent_mode;
string group_password; string group_password, ehorus_conf;
time_t ctime; time_t ctime;
struct tm *ctime_tm = NULL; struct tm *ctime_tm = NULL;
int pos; int pos;
@ -479,13 +479,12 @@ Pandora_Windows_Service::getXmlHeader () {
xml += url_address; xml += url_address;
} }
// Get Url Address // Get group password
group_password = conf->getValue ("group_password"); group_password = conf->getValue ("group_password");
if (group_password != "") { if (group_password != "") {
xml += "\" group_password=\""; xml += "\" group_password=\"";
xml += group_password; xml += group_password;
} }
// Get Coordinates // Get Coordinates
gis_exec = conf->getValue ("gis_exec"); gis_exec = conf->getValue ("gis_exec");
@ -1634,6 +1633,7 @@ Pandora_Windows_Service::sendXml (Pandora_Module_List *modules) {
string xml_filename, random_integer; string xml_filename, random_integer;
string tmp_filename, tmp_filepath; string tmp_filename, tmp_filepath;
string encoding; string encoding;
string ehorus_conf, eh_key;
static HANDLE mutex = 0; static HANDLE mutex = 0;
ULARGE_INTEGER free_bytes; ULARGE_INTEGER free_bytes;
double min_free_bytes = 0; double min_free_bytes = 0;
@ -1653,6 +1653,12 @@ Pandora_Windows_Service::sendXml (Pandora_Module_List *modules) {
data_xml = getXmlHeader (); data_xml = getXmlHeader ();
/* Get the eHorus key. */
ehorus_conf = conf->getValue ("ehorus_conf");
if (ehorus_conf != "") {
eh_key = getEHKey(ehorus_conf);
}
/* Write custom fields */ /* Write custom fields */
int c = 1; int c = 1;
@ -1662,8 +1668,8 @@ Pandora_Windows_Service::sendXml (Pandora_Module_List *modules) {
sprintf(token_value_token, "custom_field%d_value", c); sprintf(token_value_token, "custom_field%d_value", c);
string token_name = conf->getValue (token_name_token); string token_name = conf->getValue (token_name_token);
string token_value = conf->getValue (token_value_token); string token_value = conf->getValue (token_value_token);
if(token_name != "" && token_value != "") { if((token_name != "" && token_value != "") || eh_key != "") {
data_xml += "<custom_fields>\n"; data_xml += "<custom_fields>\n";
while(token_name != "" && token_value != "") { while(token_name != "" && token_value != "") {
data_xml += " <field>\n"; data_xml += " <field>\n";
@ -1677,6 +1683,15 @@ Pandora_Windows_Service::sendXml (Pandora_Module_List *modules) {
token_name = conf->getValue (token_name_token); token_name = conf->getValue (token_name_token);
token_value = conf->getValue (token_value_token); token_value = conf->getValue (token_value_token);
} }
/* Add the eHorus key as a custom field. */
if (eh_key != "") {
data_xml += " <field>\n";
data_xml += " <name>eHorusID</name>\n";
data_xml += " <value><![CDATA["+ eh_key +"]]></value>\n";
data_xml += " </field>\n";
}
data_xml += "</custom_fields>\n"; data_xml += "</custom_fields>\n";
} }
@ -2034,6 +2049,37 @@ Pandora_Windows_Service::getConf () {
return this->conf; return this->conf;
} }
string
Pandora_Windows_Service::getEHKey (string ehorus_conf) {
string buffer, eh_key;
std::ifstream ifs(ehorus_conf.c_str());
int pos;
if (! ifs.is_open ()) {
pandoraDebug ("Error opening eHorus configuration file %s", ehorus_conf.c_str ());
return eh_key;
}
/* Look for the eHorus key. */
while (ifs.good ()) {
getline (ifs, buffer);
/* Skip comments. */
if (buffer.empty() || buffer.at(0) == '#') {
continue;
}
pos = buffer.find("eh_key");
if (pos != string::npos){
eh_key = buffer.substr(pos + 7); /* pos + strlen("eh_key ") */
eh_key = trim(eh_key);
return eh_key;
}
}
return eh_key;
}
long long
Pandora_Windows_Service::getInterval () { Pandora_Windows_Service::getInterval () {
return this->interval; return this->interval;

View File

@ -114,6 +114,7 @@ namespace Pandora {
int sendXml (Pandora_Module_List *modules); int sendXml (Pandora_Module_List *modules);
void sendBufferedXml (string path); void sendBufferedXml (string path);
Pandora_Agent_Conf *getConf (); Pandora_Agent_Conf *getConf ();
string getEHKey (string ehorus_conf);
long getInterval (); long getInterval ();
long getIntensiveInterval (); long getIntensiveInterval ();