diff --git a/pandora_agents/win32/misc/cron.cc b/pandora_agents/win32/misc/cron.cc index 46f02f8a34..b51c6cab11 100644 --- a/pandora_agents/win32/misc/cron.cc +++ b/pandora_agents/win32/misc/cron.cc @@ -19,6 +19,7 @@ */ #include #include +#include #include "cron.h" #include "../pandora.h" @@ -48,6 +49,7 @@ Cron::Cron (string cron_string) { // Fill the cron structure this->utimestamp = 0; + this->cronInterval = 0; this->isSet = true; // Months in cron are from 1 to 12. For date, are required from 0 to 11. for (int i = 0; i < 5; i++) { @@ -86,13 +88,32 @@ Cron::Cron (string cron_string) { */ bool Cron::getIsSet () { return this->isSet; } +/** + * @brief Getter of cronString property + * + */ +string Cron::getCronString() { return this->cronString; } + +/** + * @brief Getter of cronInterval property casting in string + * + */ +string Cron::getCronIntervalStr() { + stringstream ss; + ss << this->cronInterval; + return ss.str(); +} + + /** * @brief Set utimestamp (private set) * - * @param date + * @param date when module will be executed next time + * @param now current timestamp. Required to update interval */ -void Cron::setUtimestamp(time_t date) { +void Cron::setUtimestamp(time_t date, time_t now) { this->utimestamp = date; + this->cronInterval = date - now; Pandora::pandoraDebug( "Module with cron %s will be executed at timestamp: %d.", this->cronString.c_str(), @@ -221,7 +242,7 @@ void Cron::update (time_t date, int interval) { time_t nex_time = date + interval; if (isInCron(nex_time)) { - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); return; } @@ -239,7 +260,7 @@ void Cron::update (time_t date, int interval) { timeinfo->tm_min = getResetValue(0); nex_time = mktime(timeinfo); if (nex_time >= date && isInCron(nex_time)) { - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); return; } @@ -267,7 +288,7 @@ void Cron::update (time_t date, int interval) { // Check the hour if (isInCron(nex_time)) { - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); } // Update hour if fails @@ -276,7 +297,7 @@ void Cron::update (time_t date, int interval) { // When an overflow is passed check the hour update again nex_time = mktime(timeinfo); if (nex_time >= date && isInCron(nex_time)) { - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); return; } @@ -298,7 +319,7 @@ void Cron::update (time_t date, int interval) { // Check the day if (isInCron(nex_time)){ - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); return; } @@ -308,7 +329,7 @@ void Cron::update (time_t date, int interval) { // When an overflow is passed check the day update in the next execution nex_time = mktime(timeinfo); if (nex_time >= date && isInCron(nex_time)) { - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); return; } @@ -324,7 +345,7 @@ void Cron::update (time_t date, int interval) { // Check the month if (isInCron(nex_time)) { - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); return; } @@ -334,7 +355,7 @@ void Cron::update (time_t date, int interval) { // When an overflow is passed check the month update in the next execution nex_time = mktime(timeinfo); if (nex_time >= date) { - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); return; } @@ -342,5 +363,5 @@ void Cron::update (time_t date, int interval) { timeinfo->tm_year++; nex_time = mktime(timeinfo); - setUtimestamp(nex_time); + setUtimestamp(nex_time, date); } \ No newline at end of file diff --git a/pandora_agents/win32/misc/cron.h b/pandora_agents/win32/misc/cron.h index 876abf010a..e27d81062b 100644 --- a/pandora_agents/win32/misc/cron.h +++ b/pandora_agents/win32/misc/cron.h @@ -51,9 +51,10 @@ class Cron { int params[5][2]; bool isSet; string cronString; + time_t cronInterval; // Methods - void setUtimestamp(time_t date); + void setUtimestamp(time_t date, time_t now); bool isInCron(time_t date); bool isWildCard(int position); bool isSingleValue(int position); @@ -66,7 +67,7 @@ class Cron { // Getter & setters bool getIsSet(); string getCronString(); - time_t getNextExecution(); + string getCronIntervalStr(); // Other methods void update(time_t date, int interval); diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index 3b7e57df03..57a2c26b15 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -740,10 +740,14 @@ Pandora_Module::getXml () { } /* Module Crontab */ - if (this->module_crontab != "") { + if (this->cron->getIsSet()) { module_xml += "\t"; - module_xml += this->module_crontab; + module_xml += this->cron->getCronString(); module_xml += "\n"; + + module_xml += "\tcron->getCronIntervalStr(); + module_xml += "]]>\n"; } /* Write module data */ @@ -1563,7 +1567,7 @@ Pandora_Module::evaluateIntensiveConditions () { /** * Checks the module cron. Returns 1 if the module should run, 0 if not. * - * @return true if the module should run. + * @return 1 if the module should run, 0 if not. */ bool Pandora_Module::checkCron (int interval) {