Cron bug and crontab and alert template is sended in win32 TICKETS #3355

This commit is contained in:
fermin831 2016-03-01 19:12:27 +01:00
parent 68b8570db0
commit 5dcb313522
4 changed files with 89 additions and 12 deletions

View File

@ -78,6 +78,8 @@ Pandora_Module::Pandora_Module (string name) {
this->warning_inverse = "";
this->quiet = "";
this->module_ff_interval = "";
this->module_alert_template = "";
this->module_crontab = "";
}
/**
@ -726,6 +728,20 @@ Pandora_Module::getXml () {
module_xml += "</module_ff_interval>\n";
}
/* Module Alert template */
if (this->module_alert_template != "") {
module_xml += "\t<alert_template>";
module_xml += this->module_alert_template;
module_xml += "</alert_template>\n";
}
/* Module Crontab */
if (this->module_crontab != "") {
module_xml += "\t<crontab>";
module_xml += this->module_crontab;
module_xml += "</crontab>\n";
}
/* Write module data */
if (this->data_list && this->data_list->size () > 1) {
list<Pandora_Data *>::iterator iter;
@ -1002,6 +1018,26 @@ Pandora_Module::setModuleFFInterval (string value) {
this->module_ff_interval = value;
}
/**
* Set the module Alert template for the module.
*
* @param value module Alert template value to set.
*/
void
Pandora_Module::setModuleAlertTemplate (string value) {
this->module_alert_template = value;
}
/**
* Set the module Crontab for the module.
*
* @param value module Crontab value to set.
*/
void
Pandora_Module::setModuleCrontab (string value) {
this->module_crontab = value;
}
/**
* Set the async flag to the module.
*
@ -1526,7 +1562,7 @@ Pandora_Module::evaluateIntensiveConditions () {
* @return 1 if the module should run, 0 if not.
*/
int
Pandora_Module::checkCron () {
Pandora_Module::checkCron (int module_interval, int agent_interval) {
int i, time_params[5];
time_t current_time, offset;
struct tm *time_struct;
@ -1568,13 +1604,28 @@ Pandora_Module::checkCron () {
continue;
}
// Check if next execution will overflow the cron (only minutes overflow)
// If overflow, execute the module
bool overflow_cron = false;
if (i == 0) {
int start_cron_seconds = cron->params[i][0]*60;
int current_exec_seconds = time_params[i]*60;
int next_exec_seconds = time_params[i]*60 + module_interval*agent_interval;
if (current_exec_seconds > start_cron_seconds && current_exec_seconds > next_exec_seconds) {
start_cron_seconds += 3600;
}
if ((current_exec_seconds <= start_cron_seconds) && (start_cron_seconds <= next_exec_seconds)) {
overflow_cron = true;
}
}
// Check interval
if (cron->params[i][0] <= cron->params[i][1]) {
if (time_params[i] < cron->params[i][0] || time_params[i] > cron->params[i][1]) {
if ((time_params[i] < cron->params[i][0] || time_params[i] > cron->params[i][1]) && !overflow_cron) {
return 0;
}
} else {
if (time_params[i] < cron->params[i][0] && time_params[i] > cron->params[i][1]) {
if ((time_params[i] < cron->params[i][0] && time_params[i] > cron->params[i][1]) && !overflow_cron) {
return 0;
}
}

View File

@ -177,7 +177,8 @@ namespace Pandora_Modules {
unsigned char intensive_match;
int intensive_interval;
string unit, custom_id, str_warning, str_critical;
string module_group, warning_inverse, critical_inverse, quiet, module_ff_interval;
string module_group, warning_inverse, critical_inverse, quiet;
string module_ff_interval, module_alert_template, module_crontab;
string critical_instructions, warning_instructions, unknown_instructions, tags;
protected:
@ -278,6 +279,8 @@ namespace Pandora_Modules {
void setWarningInverse (string value);
void setQuiet (string value);
void setModuleFFInterval (string value);
void setModuleAlertTemplate (string value);
void setModuleCrontab (string value);
void setAsync (bool async);
void setSave (string save);
@ -289,7 +292,7 @@ namespace Pandora_Modules {
void addIntensiveCondition (string intensivecondition);
int evaluatePreconditions ();
void evaluateConditions ();
int checkCron ();
int checkCron (int module_interval, int agent_interval);
void setCron (string cron_string);
void setCronInterval (int interval);
int evaluateCondition (string string_value, double double_value, Condition *condition);

View File

@ -119,6 +119,7 @@ using namespace Pandora_Strutils;
#define TOKEN_MODULE_FF_INTERVAL ("module_ff_interval ")
#define TOKEN_MACRO ("module_macro")
#define TOKEN_NATIVE_ENCODING ("module_native_encoding")
#define TOKEN_ALERT_TEMPLATE ("module_alert_template")
string
parseLine (string line, string token) {
@ -171,7 +172,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
string module_unit, module_group, module_custom_id, module_str_warning, module_str_critical;
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;
string module_native_encoding, module_alert_template;
string macro;
Pandora_Module *module;
bool numeric;
@ -250,6 +251,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module_quiet = "";
module_ff_interval = "";
module_native_encoding = "";
module_alert_template = "";
macro = "";
stringtok (tokens, definition, "\n");
@ -500,6 +502,12 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
if (module_ff_interval == "") {
module_ff_interval = parseLine (line, TOKEN_MODULE_FF_INTERVAL);
}
if (module_alert_template == "") {
module_alert_template = parseLine (line, TOKEN_ALERT_TEMPLATE);
module_alert_template.erase (0,1);
}
if (macro == "") {
macro = parseLine (line, TOKEN_MACRO);
@ -1069,6 +1077,13 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module_ff_interval.replace(pos_macro, macro_name.size(), macro_value);
}
}
if (module_alert_template != "") {
pos_macro = module_alert_template.find(macro_name);
if (pos_macro != string::npos){
module_alert_template.replace(pos_macro, macro_name.size(), macro_value);
}
}
}
}
}
@ -1405,5 +1420,13 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module->setModuleFFInterval (module_ff_interval);
}
if (module_alert_template != "") {
module->setModuleAlertTemplate (module_alert_template);
}
if (module_crontab != "") {
module->setModuleCrontab (module_crontab);
}
return module;
}

View File

@ -1808,7 +1808,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
}
/* Check preconditions */
if (module->checkCron () == 0) {
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 ();
@ -1928,7 +1928,7 @@ Pandora_Windows_Service::pandora_run (int forced_run) {
}
/* Check preconditions */
if (module->checkCron () == 0) {
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 ();