Merge branch 'ent-894-fallos-broker-asincronos-windows' into 'develop'
Fixed async issues in windows brokers See merge request !485
This commit is contained in:
commit
51538db187
|
@ -1789,5 +1789,9 @@ Pandora_Module::getIntensiveMatch () {
|
|||
return this->intensive_match;
|
||||
}
|
||||
|
||||
bool
|
||||
Pandora_Module::getAsync () {
|
||||
return this->async;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace Pandora_Modules {
|
|||
MODULE_TCPCHECK, /**< The module checks whether a tcp port is open */
|
||||
MODULE_REGEXP, /**< The module searches a file for matches of a regular expression */
|
||||
MODULE_PLUGIN, /**< Plugin */
|
||||
MODULE_PING, /**< Ping module */
|
||||
MODULE_PING, /**< Ping module */
|
||||
MODULE_SNMPGET /**< SNMP get module */
|
||||
} Module_Kind;
|
||||
|
||||
|
@ -238,6 +238,7 @@ namespace Pandora_Modules {
|
|||
void setTimeout (int timeout);
|
||||
int getTimeout ();
|
||||
string getSave ();
|
||||
bool getAsync ();
|
||||
|
||||
virtual string getXml ();
|
||||
|
||||
|
|
|
@ -52,6 +52,17 @@ Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
|
|||
this->retries = 3;
|
||||
this->start_delay = 5000;
|
||||
this->retry_delay = 2000;
|
||||
this->thread = 0;
|
||||
}
|
||||
/**
|
||||
* Destroys a Pandora_Module_Service object.
|
||||
*/
|
||||
Pandora_Module_Proc::~Pandora_Module_Proc () {
|
||||
|
||||
// Close the thread if module is async
|
||||
if (this->thread) {
|
||||
TerminateThread(this->thread, 0);
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace Pandora_Modules {
|
|||
int retry_delay;
|
||||
public:
|
||||
Pandora_Module_Proc (string name, string process_name);
|
||||
~Pandora_Module_Proc ();
|
||||
|
||||
string getProcessName () const;
|
||||
string getStartCommand () const;
|
||||
|
|
|
@ -49,6 +49,16 @@ Pandora_Module_Service::Pandora_Module_Service (string name, string service_name
|
|||
this->thread = 0;
|
||||
this->watchdog = false;
|
||||
}
|
||||
/**
|
||||
* Destroys a Pandora_Module_Service object.
|
||||
*/
|
||||
Pandora_Module_Service::~Pandora_Module_Service () {
|
||||
|
||||
// Close the thread if module is async
|
||||
if (this->thread) {
|
||||
TerminateThread(this->thread, 0);
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
Pandora_Module_Service::getServiceName () const {
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace Pandora_Modules {
|
|||
bool watchdog;
|
||||
public:
|
||||
Pandora_Module_Service (string name, string service_name);
|
||||
~Pandora_Module_Service ();
|
||||
|
||||
void run ();
|
||||
string getServiceName () const;
|
||||
|
|
|
@ -76,6 +76,7 @@ Pandora_Windows_Service::setValues (const char * svc_name,
|
|||
this->service_description = (char *) svc_description;
|
||||
execution_number = 0;
|
||||
this->modules = NULL;
|
||||
this->broker_modules = NULL;
|
||||
this->conf = NULL;
|
||||
this->interval = 60000;
|
||||
this->timestamp = 0;
|
||||
|
@ -105,6 +106,10 @@ Pandora_Windows_Service::~Pandora_Windows_Service () {
|
|||
if (this->modules != NULL) {
|
||||
delete this->modules;
|
||||
}
|
||||
|
||||
if (this->broker_modules != NULL) {
|
||||
delete this->broker_modules;
|
||||
}
|
||||
pandoraLog ("Pandora agent stopped");
|
||||
}
|
||||
|
||||
|
@ -136,10 +141,10 @@ Pandora_Windows_Service::pandora_init_broker (string file_conf) {
|
|||
|
||||
this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
|
||||
this->conf->setFile (file_conf);
|
||||
if (this->modules != NULL) {
|
||||
delete this->modules;
|
||||
if (this->broker_modules != NULL) {
|
||||
delete this->broker_modules;
|
||||
}
|
||||
this->modules = new Pandora_Module_List (file_conf);
|
||||
this->broker_modules = new Pandora_Module_List (file_conf);
|
||||
|
||||
pandoraDebug ("Pandora broker agent started");
|
||||
}
|
||||
|
@ -208,9 +213,14 @@ Pandora_Windows_Service::check_broker_agents(string *all_conf){
|
|||
|
||||
void
|
||||
Pandora_Windows_Service::pandora_init () {
|
||||
pandora_init(true);
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Windows_Service::pandora_init (bool reload_modules) {
|
||||
string conf_file, interval, debug, disable_logfile, intensive_interval, util_dir, path, env;
|
||||
string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr;
|
||||
string agent_name, agent_name_cmd, agent_alias, pandora_agent;
|
||||
string agent_name, agent_name_cmd, agent_alias, agent_alias_cmd, pandora_agent;
|
||||
string proxy_mode, server_ip;
|
||||
string *all_conf;
|
||||
int pos, num;
|
||||
|
@ -224,7 +234,7 @@ Pandora_Windows_Service::pandora_init () {
|
|||
|
||||
this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
|
||||
this->conf->setFile (all_conf);
|
||||
if (this->modules != NULL) {
|
||||
if (this->modules != NULL && reload_modules) {
|
||||
delete this->modules;
|
||||
}
|
||||
|
||||
|
@ -255,7 +265,9 @@ Pandora_Windows_Service::pandora_init () {
|
|||
this->setSleepTime (this->intensive_interval);
|
||||
|
||||
// Read modules
|
||||
this->modules = new Pandora_Module_List (conf_file);
|
||||
if (reload_modules) {
|
||||
this->modules = new Pandora_Module_List (conf_file);
|
||||
}
|
||||
delete []all_conf;
|
||||
|
||||
// Get the agent alias.
|
||||
|
@ -1856,19 +1868,19 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||
|
||||
server_addr = conf->getValue ("server_ip");
|
||||
|
||||
if (this->modules != NULL) {
|
||||
this->modules->goFirst ();
|
||||
if (this->broker_modules != NULL) {
|
||||
this->broker_modules->goFirst ();
|
||||
|
||||
while (! this->modules->isLast ()) {
|
||||
while (! this->broker_modules->isLast ()) {
|
||||
Pandora_Module *module;
|
||||
|
||||
module = this->modules->getCurrentValue ();
|
||||
module = this->broker_modules->getCurrentValue ();
|
||||
|
||||
/* Check preconditions */
|
||||
if (module->evaluatePreconditions () == 0) {
|
||||
pandoraDebug ("Preconditions not matched for module %s", module->getName ().c_str ());
|
||||
module->setNoOutput ();
|
||||
this->modules->goNext ();
|
||||
this->broker_modules->goNext ();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1876,15 +1888,23 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||
if (module->checkCron (module->getInterval (), atoi (conf->getValue ("interval").c_str())) == 0) {
|
||||
pandoraDebug ("Cron not matched for module %s", module->getName ().c_str ());
|
||||
module->setNoOutput ();
|
||||
this->modules->goNext ();
|
||||
this->broker_modules->goNext ();
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check async */
|
||||
if (module->getAsync()) {
|
||||
pandoraDebug ("Forbidden async module %s in broker agents", module->getName ().c_str ());
|
||||
module->setNoOutput ();
|
||||
this->broker_modules->goNext ();
|
||||
continue;
|
||||
}
|
||||
|
||||
pandoraDebug ("Run %s", module->getName ().c_str ());
|
||||
module->run ();
|
||||
if (! module->hasOutput ()) {
|
||||
module->setNoOutput ();
|
||||
this->modules->goNext ();
|
||||
this->broker_modules->goNext ();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1897,7 +1917,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||
intensive_match = module->evaluateIntensiveConditions ();
|
||||
if (intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
|
||||
module->setNoOutput ();
|
||||
this->modules->goNext ();
|
||||
this->broker_modules->goNext ();
|
||||
continue;
|
||||
}
|
||||
module->setIntensiveMatch (intensive_match);
|
||||
|
@ -1912,7 +1932,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||
/* At least one module has data */
|
||||
data_flag = 1;
|
||||
|
||||
this->modules->goNext ();
|
||||
this->broker_modules->goNext ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1920,7 +1940,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||
|
||||
// Send the XML
|
||||
if (!server_addr.empty ()) {
|
||||
this->sendXml (this->modules);
|
||||
this->sendXml (this->broker_modules);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2059,7 +2079,7 @@ Pandora_Windows_Service::pandora_run (int forced_run) {
|
|||
|
||||
/* Reload the original configuration */
|
||||
if (num != 0) {
|
||||
pandora_init ();
|
||||
pandora_init (false);
|
||||
}
|
||||
|
||||
/* Reset time reference if necessary */
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace Pandora {
|
|||
private:
|
||||
Pandora_Agent_Conf *conf;
|
||||
Pandora_Module_List *modules;
|
||||
Pandora_Module_List *broker_modules;
|
||||
long execution_number;
|
||||
string agent_name;
|
||||
string alias;
|
||||
|
@ -98,6 +99,7 @@ namespace Pandora {
|
|||
void pandora_run (int forced_run);
|
||||
void pandora_run ();
|
||||
void pandora_init ();
|
||||
void pandora_init (bool reload_modules);
|
||||
|
||||
long interval;
|
||||
long interval_sec;
|
||||
|
|
Loading…
Reference in New Issue