2011-11-03 Ramon Novoa <rnovoa@artica.es>

* pandora_windows_service.h,
	  pandora_windows_service.cc: Several fixes to the proxy mode and
	  broker agents.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5109 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2011-11-03 19:13:57 +00:00
parent b7ade921b5
commit f2d1a13a85
3 changed files with 54 additions and 26 deletions

View File

@ -1,3 +1,9 @@
2011-11-03 Ramon Novoa <rnovoa@artica.es>
* pandora_windows_service.h,
pandora_windows_service.cc: Several fixes to the proxy mode and
broker agents.
2011-09-23 Sancho Lerena <slerena@artica.es> 2011-09-23 Sancho Lerena <slerena@artica.es>
* installer/pandora.mpi: Updated string version in agent installer. * installer/pandora.mpi: Updated string version in agent installer.

View File

@ -76,6 +76,7 @@ Pandora_Windows_Service::setValues (const char * svc_name,
this->transfer_interval = this->interval; this->transfer_interval = this->interval;
this->elapsed_transfer_time = 0; this->elapsed_transfer_time = 0;
this->udp_server = NULL; this->udp_server = NULL;
this->tentacle_proxy = false;
} }
/** /**
@ -138,9 +139,12 @@ Pandora_Windows_Service::pandora_init_broker (string file_conf) {
this->conf = Pandora::Pandora_Agent_Conf::getInstance (); this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
this->conf->setFile (file_conf); this->conf->setFile (file_conf);
if (this->modules != NULL) {
delete this->modules;
}
this->modules = new Pandora_Module_List (file_conf); this->modules = new Pandora_Module_List (file_conf);
pandoraLog ("Pandora agent started"); pandoraDebug ("Pandora broker agent started");
} }
int int
@ -212,6 +216,7 @@ Pandora_Windows_Service::pandora_init () {
string name_agent, name; string name_agent, name;
string proxy_mode, server_ip; string proxy_mode, server_ip;
int pos, num; int pos, num;
static unsigned char first_run = 0;
setPandoraDebug (true); setPandoraDebug (true);
@ -230,6 +235,9 @@ Pandora_Windows_Service::pandora_init () {
this->conf = Pandora::Pandora_Agent_Conf::getInstance (); this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
this->conf->setFile (all_conf); this->conf->setFile (all_conf);
if (this->modules != NULL) {
delete this->modules;
}
this->modules = new Pandora_Module_List (conf_file); this->modules = new Pandora_Module_List (conf_file);
name = checkAgentName(conf_file); name = checkAgentName(conf_file);
@ -270,13 +278,10 @@ Pandora_Windows_Service::pandora_init () {
/*Check if proxy mode is set*/ /*Check if proxy mode is set*/
proxy_mode = conf->getValue ("proxy_mode"); proxy_mode = conf->getValue ("proxy_mode");
if (proxy_mode != "" && this->tentacle_proxy == false) {
if (proxy_mode != "") { launchTentacleProxy();
lauchTentacleProxy();
} }
pandoraLog ("Pandora agent started");
/* Launch UDP Server */ /* Launch UDP Server */
udp_server_enabled = conf->getValue ("udp_server"); udp_server_enabled = conf->getValue ("udp_server");
if (udp_server_enabled.compare ("1") == 0 && this->udp_server == NULL) { if (udp_server_enabled.compare ("1") == 0 && this->udp_server == NULL) {
@ -286,6 +291,11 @@ Pandora_Windows_Service::pandora_init () {
this->udp_server = new UDP_Server (this, udp_server_addr, udp_server_auth_addr, atoi (udp_server_port.c_str ())); this->udp_server = new UDP_Server (this, udp_server_addr, udp_server_auth_addr, atoi (udp_server_port.c_str ()));
((UDP_Server *)this->udp_server)->start (); ((UDP_Server *)this->udp_server)->start ();
} }
if (first_run == 0) {
first_run = 1;
pandoraLog ("Pandora agent started");
}
} }
int int
@ -294,6 +304,10 @@ Pandora_Windows_Service::killTentacleProxy() {
STARTUPINFO si; STARTUPINFO si;
string kill_cmd; string kill_cmd;
if (this->tentacle_proxy == false) {
return 0;
}
kill_cmd = "taskkill.exe /F /IM tentacle_server.exe"; kill_cmd = "taskkill.exe /F /IM tentacle_server.exe";
ZeroMemory (&si, sizeof (si)); ZeroMemory (&si, sizeof (si));
@ -303,11 +317,11 @@ Pandora_Windows_Service::killTentacleProxy() {
return -1; return -1;
} }
this->tentacle_proxy = false;
} }
int int
Pandora_Windows_Service::lauchTentacleProxy() { Pandora_Windows_Service::launchTentacleProxy() {
string server_ip, server_port, proxy_max_connections, proxy_timeout; string server_ip, server_port, proxy_max_connections, proxy_timeout;
string proxy_cmd; string proxy_cmd;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
@ -345,6 +359,7 @@ Pandora_Windows_Service::lauchTentacleProxy() {
return -1; return -1;
} }
this->tentacle_proxy = true;
pandoraLog("Proxy mode enabled"); pandoraLog("Proxy mode enabled");
} else { } else {
pandoraLog ("[error] You can not proxy to localhost"); pandoraLog ("[error] You can not proxy to localhost");
@ -1105,7 +1120,7 @@ Pandora_Windows_Service::checkAgentName(string filename){
file.close(); file.close();
return name_agent; return name_agent;
} }
void int
Pandora_Windows_Service::checkConfig (string file) { Pandora_Windows_Service::checkConfig (string file) {
int i, conf_size; int i, conf_size;
char *conf_str = NULL, *remote_conf_str = NULL, *remote_conf_md5 = NULL; char *conf_str = NULL, *remote_conf_str = NULL, *remote_conf_md5 = NULL;
@ -1115,7 +1130,7 @@ Pandora_Windows_Service::checkConfig (string file) {
tmp = conf->getValue ("remote_config"); tmp = conf->getValue ("remote_config");
if (tmp != "1") { if (tmp != "1") {
pandoraDebug ("Pandora_Windows_Service::checkConfig: Remote configuration disabled"); pandoraDebug ("Pandora_Windows_Service::checkConfig: Remote configuration disabled");
return; return 0;
} }
/* Get temporal directory */ /* Get temporal directory */
@ -1134,7 +1149,7 @@ Pandora_Windows_Service::checkConfig (string file) {
/* Error getting agent name */ /* Error getting agent name */
if (tmp.empty ()) { if (tmp.empty ()) {
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error getting agent name"); pandoraDebug ("Pandora_Windows_Service::checkConfig: Error getting agent name");
return; return 0;
} }
Pandora_File::md5 (tmp.c_str(), tmp.size(), agent_md5); Pandora_File::md5 (tmp.c_str(), tmp.size(), agent_md5);
@ -1148,7 +1163,7 @@ Pandora_Windows_Service::checkConfig (string file) {
if (conf_str != NULL) { if (conf_str != NULL) {
delete[] conf_str; delete[] conf_str;
} }
return; return 0;
} }
/* Compose file names from the agent name hash */ /* Compose file names from the agent name hash */
@ -1179,7 +1194,7 @@ Pandora_Windows_Service::checkConfig (string file) {
} }
delete[] conf_str; delete[] conf_str;
return; return 0;
} }
delete[] conf_str; delete[] conf_str;
@ -1194,12 +1209,12 @@ Pandora_Windows_Service::checkConfig (string file) {
if (remote_conf_md5 != NULL) { if (remote_conf_md5 != NULL) {
delete[] remote_conf_md5; delete[] remote_conf_md5;
} }
return; return 0;
} }
Pandora_File::removeFile (tmp); Pandora_File::removeFile (tmp);
} catch (...) { } catch (...) {
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error checking remote configuration md5", tmp.c_str()); pandoraDebug ("Pandora_Windows_Service::checkConfig: Error checking remote configuration md5", tmp.c_str());
return; return 0;
} }
/* Check for configuration changes */ /* Check for configuration changes */
@ -1215,7 +1230,7 @@ Pandora_Windows_Service::checkConfig (string file) {
/* Configuration has not changed */ /* Configuration has not changed */
if (flag == 0) { if (flag == 0) {
return; return 0;
} }
pandoraLog("Pandora_Windows_Service::checkConfig: Configuration for agent %s has changed", agent_name.c_str ()); pandoraLog("Pandora_Windows_Service::checkConfig: Configuration for agent %s has changed", agent_name.c_str ());
@ -1234,13 +1249,13 @@ Pandora_Windows_Service::checkConfig (string file) {
if (conf_str != NULL) { if (conf_str != NULL) {
delete[] conf_str; delete[] conf_str;
} }
return; return 0;
} }
delete[] conf_str; delete[] conf_str;
/* Reload configuration */ /* Reload configuration */
this->pandora_init (); return 1;
} }
int int
@ -1388,7 +1403,9 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
/* Check for configuration changes */ /* Check for configuration changes */
if (getPandoraDebug () == false) { if (getPandoraDebug () == false) {
this->checkConfig (config); if (this->checkConfig (config) == 1) {
pandora_init_broker (config);
}
this->checkCollections (); this->checkCollections ();
} }
@ -1449,8 +1466,6 @@ Pandora_Windows_Service::pandora_run () {
pandoraDebug ("Run begin"); pandoraDebug ("Run begin");
pandora_init();
conf = this->getConf (); conf = this->getConf ();
/* Sleep if a startup delay was specified */ /* Sleep if a startup delay was specified */
@ -1466,7 +1481,9 @@ Pandora_Windows_Service::pandora_run () {
conf_file = Pandora::getPandoraInstallDir (); conf_file = Pandora::getPandoraInstallDir ();
conf_file += "pandora_agent.conf"; conf_file += "pandora_agent.conf";
this->checkConfig (conf_file); if (this->checkConfig (conf_file) == 1) {
this->pandora_init ();
}
this->checkCollections (); this->checkCollections ();
} }
@ -1517,16 +1534,20 @@ Pandora_Windows_Service::pandora_run () {
/* Get the interval value (in minutes) */ /* Get the interval value (in minutes) */
pandoraDebug ("Next execution on %d seconds", this->interval / 1000); pandoraDebug ("Next execution on %d seconds", this->interval / 1000);
/* Load and execute brokers */
num = count_broker_agents(); num = count_broker_agents();
string all_conf[num]; string all_conf[num];
check_broker_agents(all_conf); check_broker_agents(all_conf);
for (i=0;i<num;i++){ for (i=0;i<num;i++){
pandora_init_broker(all_conf[i]); pandora_init_broker(all_conf[i]);
pandora_run_broker(all_conf[i]); pandora_run_broker(all_conf[i]);
} }
/* Reload the original configuration */
if (num != 0) {
pandora_init ();
}
return; return;
} }

View File

@ -47,6 +47,7 @@ namespace Pandora {
long transfer_interval; long transfer_interval;
bool started; bool started;
void *udp_server; void *udp_server;
bool tentacle_proxy;
list<string> collection_disk; list<string> collection_disk;
string getXmlHeader (); string getXmlHeader ();
@ -74,13 +75,13 @@ namespace Pandora {
void checkCollections (); void checkCollections ();
void addCollectionsPath(); void addCollectionsPath();
string checkAgentName(string filename); string checkAgentName(string filename);
void checkConfig (string file); int checkConfig (string file);
void purgeDiskCollections (); void purgeDiskCollections ();
void pandora_init_broker (string file_conf); void pandora_init_broker (string file_conf);
void pandora_run_broker (string config); void pandora_run_broker (string config);
int count_broker_agents(); int count_broker_agents();
void check_broker_agents(string *all_conf); void check_broker_agents(string *all_conf);
int lauchTentacleProxy(); int launchTentacleProxy();
int killTentacleProxy(); int killTentacleProxy();
Pandora_Windows_Service (); Pandora_Windows_Service ();