Merge branch 'ent-4164-8143-No-funciona-module_interval-en-modulos-de-agente-broker' into 'develop'

module_interval in broker (linux agents)

See merge request artica/pandorafms!2709
This commit is contained in:
Alejandro Fraguas 2019-09-25 15:34:48 +02:00
commit 970cbbb4be
5 changed files with 78 additions and 40 deletions

View File

@ -239,6 +239,15 @@ my $tentacle_pid = undef;
# PID of udp_server
my $udp_server_pid = undef;
# BrokerFlag
my $BrokerFlag = 0;
# Global loop counter.
my $LoopCounter = 0;
# Define a max value for loopCounter to avoid overflow.
use constant MAX_LOOP_COUNTER => 1000000000;
################################################################################
# Print usage information and exit.
################################################################################
@ -1385,6 +1394,7 @@ sub sleep_agent {
exit (0);
}
$LoopCounter = ($LoopCounter + 1) % MAX_LOOP_COUNTER;
return $iter_base_time;
}
@ -1699,6 +1709,14 @@ sub exec_module {
}
# Check module interval
if ($BrokerFlag > 0) {
if ($LoopCounter == 0) {
$module->{'counter'} = $module->{'intensive_interval'};
} else {
$module->{'counter'} = (($LoopCounter -1 ) % $module->{'intensive_interval'});
}
}
if (++($module->{'counter'}) < $module->{'intensive_interval'}) {
$ThreadSem->up () if (defined ($ThreadSem) && $Conf{'agent_threads'} > 1);
return;
@ -2985,7 +3003,6 @@ while (1) {
@BrokerPid = ();
my @broker_agents = read_config ('broker_agent');
foreach my $broker_agent (@broker_agents) {
# Create broker conf file if it does not exist
if (! -e "$ConfDir/${broker_agent}.conf") {
write_broker_conf($broker_agent);
@ -2995,6 +3012,8 @@ while (1) {
# Broker agent
if ($main_agent == 0) {
# Mark broker flag.
$BrokerFlag = 1;
# Set the configuration file
$ConfFile = "${broker_agent}.conf";

View File

@ -1693,4 +1693,18 @@ Pandora_Module::getAsync () {
return this->async;
}
/**
* Get current exections
*/
long
Pandora_Module::getExecutions () {
return this->executions;
}
/**
* Set current execution (global) used for brokers.
*/
void
Pandora_Module::setExecutions (long executions) {
this->executions = executions;
}

View File

@ -234,6 +234,8 @@ namespace Pandora_Modules {
int getTimeout ();
string getSave ();
bool getAsync ();
void setExecutions(long executions=0);
long getExecutions();
virtual string getXml ();

View File

@ -1849,7 +1849,7 @@ Pandora_Windows_Service::sendBufferedXml (string path) {
}
void
Pandora_Windows_Service::pandora_run_broker (string config) {
Pandora_Windows_Service::pandora_run_broker (string config, long executions) {
Pandora_Agent_Conf *conf = NULL;
string server_addr;
unsigned char data_flag = 0;
@ -1877,6 +1877,9 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
module = this->broker_modules->getCurrentValue ();
/* Keep executions matching main agent */
module->setExecutions(executions);
/* Check preconditions */
if (module->evaluatePreconditions () == 0) {
pandoraDebug ("Preconditions not matched for module %s", module->getName ().c_str ());
@ -2074,7 +2077,7 @@ Pandora_Windows_Service::pandora_run (int forced_run) {
check_broker_agents(all_conf);
for (i=0;i<num;i++){
pandora_init_broker(all_conf[i]);
pandora_run_broker(all_conf[i]);
pandora_run_broker(all_conf[i], execution_number);
}
delete []all_conf;

View File

@ -87,7 +87,7 @@ namespace Pandora {
int checkConfig (string file);
void purgeDiskCollections ();
void pandora_init_broker (string file_conf);
void pandora_run_broker (string config);
void pandora_run_broker (string config, long executions=0);
int count_broker_agents();
void check_broker_agents(string *all_conf);
int launchTentacleProxy();