Merge branch '7248-11618-r-works-rendimiento-module_plugin-en-agente-windows' into 'develop'

Add support for module_wait_timeout.

See merge request artica/pandorafms!4073
This commit is contained in:
Daniel Rodriguez 2021-04-28 09:30:03 +00:00
commit 9790be4f90
4 changed files with 35 additions and 8 deletions

View File

@ -81,6 +81,7 @@ Pandora_Module::Pandora_Module (string name) {
this->module_ff_type = "";
this->module_alert_template = "";
this->module_crontab = "";
this->module_wait_timeout = 500;
}
/**
@ -1722,3 +1723,18 @@ Pandora_Module::isIntensive () {
return true;
}
/**
* Set the WaitForSingleObject timeout.
*
* @param timeout Timeout in milliseconds.
*/
void
Pandora_Module::setWaitTimeout (int timeout) {
if (timeout < 0) {
return;
}
this->module_wait_timeout = timeout;
}

View File

@ -216,6 +216,7 @@ namespace Pandora_Modules {
string getDataOutput (Pandora_Data *data);
void cleanDataList ();
int module_wait_timeout;
public:
Pandora_Module (string name);
virtual ~Pandora_Module ();
@ -231,6 +232,7 @@ namespace Pandora_Modules {
int getInterval ();
int getIntensiveInterval ();
void setTimeout (int timeout);
void setWaitTimeout (int timeout);
int getTimeout ();
string getSave ();
bool getAsync ();

View File

@ -172,7 +172,7 @@ Pandora_Module_Exec::run () {
string output;
int tickbase = GetTickCount();
while ( (dwRet = WaitForSingleObject (pi.hProcess, 500)) != WAIT_ABANDONED ) {
while ( (dwRet = WaitForSingleObject (pi.hProcess, this->module_wait_timeout)) != WAIT_ABANDONED ) {
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
if (avail > 0) {
ReadFile (out_read, buffer, BUFSIZE, &read, NULL);
@ -180,11 +180,6 @@ Pandora_Module_Exec::run () {
output += (char *) buffer;
}
/* Change the output encoding */
if (this->native_encoding != -1){
changeOutputEncoding(&output);
}
if (dwRet == WAIT_OBJECT_0) {
break;
} else if(this->getTimeout() < GetTickCount() - tickbase) {
@ -220,6 +215,10 @@ Pandora_Module_Exec::run () {
}
// Command output mode
else if (!output.empty()) {
/* Change the output encoding */
if (this->native_encoding != -1){
changeOutputEncoding(&output);
}
this->setOutput (output);
} else {
this->setOutput ("");
@ -471,4 +470,3 @@ void Pandora_Module_Exec::changeOutputEncoding(string * string_change){
}
}

View File

@ -124,6 +124,7 @@ using namespace Pandora_Strutils;
#define TOKEN_NATIVE_ENCODING ("module_native_encoding")
#define TOKEN_ALERT_TEMPLATE ("module_alert_template")
#define TOKEN_USER_SESSION ("module_user_session ")
#define TOKEN_WAIT_TIMEOUT ("module_wait_timeout ")
string
parseLine (string line, string token) {
@ -178,7 +179,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
string module_critical_instructions, module_warning_instructions, module_unknown_instructions, module_tags;
string module_critical_inverse, module_warning_inverse, module_quiet, module_ff_interval;
string module_native_encoding, module_alert_template, module_ff_type;
string macro;
string macro, module_wait_timeout;
Pandora_Module *module;
bool numeric;
Module_Type type;
@ -260,6 +261,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module_alert_template = "";
module_user_session = "";
macro = "";
module_wait_timeout = "";
stringtok (tokens, definition, "\n");
@ -291,6 +293,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
if (module_exec == "") {
module_exec = parseLine (line, TOKEN_EXEC);
}
if (module_wait_timeout == "") {
module_wait_timeout = parseLine (line, TOKEN_WAIT_TIMEOUT);
}
if (module_proc == "") {
module_proc = parseLine (line, TOKEN_PROC);
}
@ -1130,6 +1135,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
if (module_timeout != "") {
module->setTimeout (atoi (module_timeout.c_str ()));
}
if (module_wait_timeout != "") {
module->setWaitTimeout (atoi (module_wait_timeout.c_str ()));
}
} else if (module_proc != "") {
module = new Pandora_Module_Proc (module_name,
@ -1230,6 +1238,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
if (module_timeout != ""){
module->setTimeout(atoi(module_timeout.c_str()));
}
if (module_wait_timeout != "") {
module->setWaitTimeout (atoi (module_wait_timeout.c_str ()));
}
} else if (module_ping != "") {
if (module_ping_count == "") {
module_ping_count = "1";