mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 00:34:46 +02:00
[Windows Agent] Added cron_interval to XML
This commit is contained in:
parent
ead21b7548
commit
d53e17e118
@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sstream>
|
||||||
#include "cron.h"
|
#include "cron.h"
|
||||||
#include "../pandora.h"
|
#include "../pandora.h"
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ Cron::Cron (string cron_string) {
|
|||||||
|
|
||||||
// Fill the cron structure
|
// Fill the cron structure
|
||||||
this->utimestamp = 0;
|
this->utimestamp = 0;
|
||||||
|
this->cronInterval = 0;
|
||||||
this->isSet = true;
|
this->isSet = true;
|
||||||
// Months in cron are from 1 to 12. For date, are required from 0 to 11.
|
// Months in cron are from 1 to 12. For date, are required from 0 to 11.
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
@ -86,13 +88,32 @@ Cron::Cron (string cron_string) {
|
|||||||
*/
|
*/
|
||||||
bool Cron::getIsSet () { return this->isSet; }
|
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)
|
* @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->utimestamp = date;
|
||||||
|
this->cronInterval = date - now;
|
||||||
Pandora::pandoraDebug(
|
Pandora::pandoraDebug(
|
||||||
"Module with cron %s will be executed at timestamp: %d.",
|
"Module with cron %s will be executed at timestamp: %d.",
|
||||||
this->cronString.c_str(),
|
this->cronString.c_str(),
|
||||||
@ -221,7 +242,7 @@ void Cron::update (time_t date, int interval) {
|
|||||||
|
|
||||||
time_t nex_time = date + interval;
|
time_t nex_time = date + interval;
|
||||||
if (isInCron(nex_time)) {
|
if (isInCron(nex_time)) {
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +260,7 @@ void Cron::update (time_t date, int interval) {
|
|||||||
timeinfo->tm_min = getResetValue(0);
|
timeinfo->tm_min = getResetValue(0);
|
||||||
nex_time = mktime(timeinfo);
|
nex_time = mktime(timeinfo);
|
||||||
if (nex_time >= date && isInCron(nex_time)) {
|
if (nex_time >= date && isInCron(nex_time)) {
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +288,7 @@ void Cron::update (time_t date, int interval) {
|
|||||||
|
|
||||||
// Check the hour
|
// Check the hour
|
||||||
if (isInCron(nex_time)) {
|
if (isInCron(nex_time)) {
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update hour if fails
|
// 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
|
// When an overflow is passed check the hour update again
|
||||||
nex_time = mktime(timeinfo);
|
nex_time = mktime(timeinfo);
|
||||||
if (nex_time >= date && isInCron(nex_time)) {
|
if (nex_time >= date && isInCron(nex_time)) {
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +319,7 @@ void Cron::update (time_t date, int interval) {
|
|||||||
|
|
||||||
// Check the day
|
// Check the day
|
||||||
if (isInCron(nex_time)){
|
if (isInCron(nex_time)){
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
return;
|
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
|
// When an overflow is passed check the day update in the next execution
|
||||||
nex_time = mktime(timeinfo);
|
nex_time = mktime(timeinfo);
|
||||||
if (nex_time >= date && isInCron(nex_time)) {
|
if (nex_time >= date && isInCron(nex_time)) {
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +345,7 @@ void Cron::update (time_t date, int interval) {
|
|||||||
|
|
||||||
// Check the month
|
// Check the month
|
||||||
if (isInCron(nex_time)) {
|
if (isInCron(nex_time)) {
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
return;
|
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
|
// When an overflow is passed check the month update in the next execution
|
||||||
nex_time = mktime(timeinfo);
|
nex_time = mktime(timeinfo);
|
||||||
if (nex_time >= date) {
|
if (nex_time >= date) {
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,5 +363,5 @@ void Cron::update (time_t date, int interval) {
|
|||||||
timeinfo->tm_year++;
|
timeinfo->tm_year++;
|
||||||
nex_time = mktime(timeinfo);
|
nex_time = mktime(timeinfo);
|
||||||
|
|
||||||
setUtimestamp(nex_time);
|
setUtimestamp(nex_time, date);
|
||||||
}
|
}
|
@ -51,9 +51,10 @@ class Cron {
|
|||||||
int params[5][2];
|
int params[5][2];
|
||||||
bool isSet;
|
bool isSet;
|
||||||
string cronString;
|
string cronString;
|
||||||
|
time_t cronInterval;
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
void setUtimestamp(time_t date);
|
void setUtimestamp(time_t date, time_t now);
|
||||||
bool isInCron(time_t date);
|
bool isInCron(time_t date);
|
||||||
bool isWildCard(int position);
|
bool isWildCard(int position);
|
||||||
bool isSingleValue(int position);
|
bool isSingleValue(int position);
|
||||||
@ -66,7 +67,7 @@ class Cron {
|
|||||||
// Getter & setters
|
// Getter & setters
|
||||||
bool getIsSet();
|
bool getIsSet();
|
||||||
string getCronString();
|
string getCronString();
|
||||||
time_t getNextExecution();
|
string getCronIntervalStr();
|
||||||
|
|
||||||
// Other methods
|
// Other methods
|
||||||
void update(time_t date, int interval);
|
void update(time_t date, int interval);
|
||||||
|
@ -740,10 +740,14 @@ Pandora_Module::getXml () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Module Crontab */
|
/* Module Crontab */
|
||||||
if (this->module_crontab != "") {
|
if (this->cron->getIsSet()) {
|
||||||
module_xml += "\t<crontab>";
|
module_xml += "\t<crontab>";
|
||||||
module_xml += this->module_crontab;
|
module_xml += this->cron->getCronString();
|
||||||
module_xml += "</crontab>\n";
|
module_xml += "</crontab>\n";
|
||||||
|
|
||||||
|
module_xml += "\t<cron_interval><![CDATA[";
|
||||||
|
module_xml += this->cron->getCronIntervalStr();
|
||||||
|
module_xml += "]]></cron_interval>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write module data */
|
/* Write module data */
|
||||||
@ -1563,7 +1567,7 @@ Pandora_Module::evaluateIntensiveConditions () {
|
|||||||
/**
|
/**
|
||||||
* Checks the module cron. Returns 1 if the module should run, 0 if not.
|
* 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
|
bool
|
||||||
Pandora_Module::checkCron (int interval) {
|
Pandora_Module::checkCron (int interval) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user