mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Fixed async issues in windows brokers
This commit is contained in:
parent
10e6153574
commit
4b05351df0
@ -1789,5 +1789,9 @@ Pandora_Module::getIntensiveMatch () {
|
|||||||
return this->intensive_match;
|
return this->intensive_match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Pandora_Module::getAsync () {
|
||||||
|
return this->async;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,6 +238,7 @@ namespace Pandora_Modules {
|
|||||||
void setTimeout (int timeout);
|
void setTimeout (int timeout);
|
||||||
int getTimeout ();
|
int getTimeout ();
|
||||||
string getSave ();
|
string getSave ();
|
||||||
|
bool getAsync ();
|
||||||
|
|
||||||
virtual string getXml ();
|
virtual string getXml ();
|
||||||
|
|
||||||
|
@ -52,6 +52,17 @@ Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
|
|||||||
this->retries = 3;
|
this->retries = 3;
|
||||||
this->start_delay = 5000;
|
this->start_delay = 5000;
|
||||||
this->retry_delay = 2000;
|
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
|
string
|
||||||
|
@ -38,6 +38,7 @@ namespace Pandora_Modules {
|
|||||||
int retry_delay;
|
int retry_delay;
|
||||||
public:
|
public:
|
||||||
Pandora_Module_Proc (string name, string process_name);
|
Pandora_Module_Proc (string name, string process_name);
|
||||||
|
~Pandora_Module_Proc ();
|
||||||
|
|
||||||
string getProcessName () const;
|
string getProcessName () const;
|
||||||
string getStartCommand () const;
|
string getStartCommand () const;
|
||||||
|
@ -49,6 +49,16 @@ Pandora_Module_Service::Pandora_Module_Service (string name, string service_name
|
|||||||
this->thread = 0;
|
this->thread = 0;
|
||||||
this->watchdog = false;
|
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
|
string
|
||||||
Pandora_Module_Service::getServiceName () const {
|
Pandora_Module_Service::getServiceName () const {
|
||||||
|
@ -36,6 +36,7 @@ namespace Pandora_Modules {
|
|||||||
bool watchdog;
|
bool watchdog;
|
||||||
public:
|
public:
|
||||||
Pandora_Module_Service (string name, string service_name);
|
Pandora_Module_Service (string name, string service_name);
|
||||||
|
~Pandora_Module_Service ();
|
||||||
|
|
||||||
void run ();
|
void run ();
|
||||||
string getServiceName () const;
|
string getServiceName () const;
|
||||||
|
@ -76,6 +76,7 @@ Pandora_Windows_Service::setValues (const char * svc_name,
|
|||||||
this->service_description = (char *) svc_description;
|
this->service_description = (char *) svc_description;
|
||||||
execution_number = 0;
|
execution_number = 0;
|
||||||
this->modules = NULL;
|
this->modules = NULL;
|
||||||
|
this->broker_modules = NULL;
|
||||||
this->conf = NULL;
|
this->conf = NULL;
|
||||||
this->interval = 60000;
|
this->interval = 60000;
|
||||||
this->timestamp = 0;
|
this->timestamp = 0;
|
||||||
@ -105,6 +106,10 @@ Pandora_Windows_Service::~Pandora_Windows_Service () {
|
|||||||
if (this->modules != NULL) {
|
if (this->modules != NULL) {
|
||||||
delete this->modules;
|
delete this->modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->broker_modules != NULL) {
|
||||||
|
delete this->broker_modules;
|
||||||
|
}
|
||||||
pandoraLog ("Pandora agent stopped");
|
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 = Pandora::Pandora_Agent_Conf::getInstance ();
|
||||||
this->conf->setFile (file_conf);
|
this->conf->setFile (file_conf);
|
||||||
if (this->modules != NULL) {
|
if (this->broker_modules != NULL) {
|
||||||
delete this->modules;
|
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");
|
pandoraDebug ("Pandora broker agent started");
|
||||||
}
|
}
|
||||||
@ -208,9 +213,14 @@ Pandora_Windows_Service::check_broker_agents(string *all_conf){
|
|||||||
|
|
||||||
void
|
void
|
||||||
Pandora_Windows_Service::pandora_init () {
|
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 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 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 proxy_mode, server_ip;
|
||||||
string *all_conf;
|
string *all_conf;
|
||||||
int pos, num;
|
int pos, num;
|
||||||
@ -224,7 +234,7 @@ 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) {
|
if (this->modules != NULL && reload_modules) {
|
||||||
delete this->modules;
|
delete this->modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +265,9 @@ Pandora_Windows_Service::pandora_init () {
|
|||||||
this->setSleepTime (this->intensive_interval);
|
this->setSleepTime (this->intensive_interval);
|
||||||
|
|
||||||
// Read modules
|
// Read modules
|
||||||
this->modules = new Pandora_Module_List (conf_file);
|
if (reload_modules) {
|
||||||
|
this->modules = new Pandora_Module_List (conf_file);
|
||||||
|
}
|
||||||
delete []all_conf;
|
delete []all_conf;
|
||||||
|
|
||||||
// Get the agent alias.
|
// Get the agent alias.
|
||||||
@ -1856,19 +1868,19 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||||||
|
|
||||||
server_addr = conf->getValue ("server_ip");
|
server_addr = conf->getValue ("server_ip");
|
||||||
|
|
||||||
if (this->modules != NULL) {
|
if (this->broker_modules != NULL) {
|
||||||
this->modules->goFirst ();
|
this->broker_modules->goFirst ();
|
||||||
|
|
||||||
while (! this->modules->isLast ()) {
|
while (! this->broker_modules->isLast ()) {
|
||||||
Pandora_Module *module;
|
Pandora_Module *module;
|
||||||
|
|
||||||
module = this->modules->getCurrentValue ();
|
module = this->broker_modules->getCurrentValue ();
|
||||||
|
|
||||||
/* Check preconditions */
|
/* Check preconditions */
|
||||||
if (module->evaluatePreconditions () == 0) {
|
if (module->evaluatePreconditions () == 0) {
|
||||||
pandoraDebug ("Preconditions not matched for module %s", module->getName ().c_str ());
|
pandoraDebug ("Preconditions not matched for module %s", module->getName ().c_str ());
|
||||||
module->setNoOutput ();
|
module->setNoOutput ();
|
||||||
this->modules->goNext ();
|
this->broker_modules->goNext ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1876,7 +1888,15 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||||||
if (module->checkCron (module->getInterval (), atoi (conf->getValue ("interval").c_str())) == 0) {
|
if (module->checkCron (module->getInterval (), atoi (conf->getValue ("interval").c_str())) == 0) {
|
||||||
pandoraDebug ("Cron not matched for module %s", module->getName ().c_str ());
|
pandoraDebug ("Cron not matched for module %s", module->getName ().c_str ());
|
||||||
module->setNoOutput ();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1884,7 +1904,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||||||
module->run ();
|
module->run ();
|
||||||
if (! module->hasOutput ()) {
|
if (! module->hasOutput ()) {
|
||||||
module->setNoOutput ();
|
module->setNoOutput ();
|
||||||
this->modules->goNext ();
|
this->broker_modules->goNext ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1897,7 +1917,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||||||
intensive_match = module->evaluateIntensiveConditions ();
|
intensive_match = module->evaluateIntensiveConditions ();
|
||||||
if (intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
|
if (intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
|
||||||
module->setNoOutput ();
|
module->setNoOutput ();
|
||||||
this->modules->goNext ();
|
this->broker_modules->goNext ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
module->setIntensiveMatch (intensive_match);
|
module->setIntensiveMatch (intensive_match);
|
||||||
@ -1912,7 +1932,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||||||
/* At least one module has data */
|
/* At least one module has data */
|
||||||
data_flag = 1;
|
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
|
// Send the XML
|
||||||
if (!server_addr.empty ()) {
|
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 */
|
/* Reload the original configuration */
|
||||||
if (num != 0) {
|
if (num != 0) {
|
||||||
pandora_init ();
|
pandora_init (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset time reference if necessary */
|
/* Reset time reference if necessary */
|
||||||
|
@ -42,6 +42,7 @@ namespace Pandora {
|
|||||||
private:
|
private:
|
||||||
Pandora_Agent_Conf *conf;
|
Pandora_Agent_Conf *conf;
|
||||||
Pandora_Module_List *modules;
|
Pandora_Module_List *modules;
|
||||||
|
Pandora_Module_List *broker_modules;
|
||||||
long execution_number;
|
long execution_number;
|
||||||
string agent_name;
|
string agent_name;
|
||||||
string alias;
|
string alias;
|
||||||
@ -98,6 +99,7 @@ namespace Pandora {
|
|||||||
void pandora_run (int forced_run);
|
void pandora_run (int forced_run);
|
||||||
void pandora_run ();
|
void pandora_run ();
|
||||||
void pandora_init ();
|
void pandora_init ();
|
||||||
|
void pandora_init (bool reload_modules);
|
||||||
|
|
||||||
long interval;
|
long interval;
|
||||||
long interval_sec;
|
long interval_sec;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user