mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-24 18:28:00 +02:00
ScheduledDowntime: create Downtimes earlier
This commit is contained in:
parent
cb30f0357b
commit
6b66ca338a
@ -13,6 +13,7 @@
|
||||
#include "base/logger.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include <boost/thread/once.hpp>
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
|
||||
using namespace icinga;
|
||||
@ -166,25 +167,27 @@ std::pair<double, double> ScheduledDowntime::FindRunningSegment(double minEnd)
|
||||
|
||||
std::pair<double, double> ScheduledDowntime::FindNextSegment()
|
||||
{
|
||||
time_t refts = Utility::GetTime();
|
||||
tm reference = Utility::LocalTime(refts);
|
||||
|
||||
Log(LogDebug, "ScheduledDowntime")
|
||||
<< "Finding next scheduled downtime segment for time " << refts;
|
||||
|
||||
Dictionary::Ptr ranges = GetRanges();
|
||||
|
||||
if (!ranges)
|
||||
return std::make_pair(0, 0);
|
||||
|
||||
Array::Ptr segments = new Array();
|
||||
|
||||
Dictionary::Ptr bestSegment;
|
||||
double bestBegin = 0.0, bestEnd = 0.0;
|
||||
double now = Utility::GetTime();
|
||||
|
||||
tm reference = Utility::LocalTime(now);
|
||||
ObjectLock olock(ranges);
|
||||
|
||||
/* Our next segment finder is limited to reference's month,
|
||||
* so e.g. downtimes for the first day of a month would not be scheduled until that day w/o this workaround:
|
||||
* Advance reference by one day up to 32 times until we've found the next segment.
|
||||
*/
|
||||
for (uint_fast8_t i = 0; i < 32u; ++i) {
|
||||
Log(LogDebug, "ScheduledDowntime")
|
||||
<< "Finding next scheduled downtime segment for time "
|
||||
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", mktime(&reference));
|
||||
|
||||
/* Find the segment starting earliest */
|
||||
for (const Dictionary::Pair& kv : ranges) {
|
||||
Log(LogDebug, "ScheduledDowntime")
|
||||
@ -217,6 +220,12 @@ std::pair<double, double> ScheduledDowntime::FindNextSegment()
|
||||
if (bestSegment)
|
||||
return std::make_pair(bestBegin, bestEnd);
|
||||
|
||||
++reference.tm_mday;
|
||||
reference.tm_hour = 0;
|
||||
reference.tm_min = 0;
|
||||
reference.tm_sec = 0;
|
||||
}
|
||||
|
||||
return std::make_pair(0, 0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user