mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-25 10:48:20 +02:00
TimePeriod: consult GetIncludes() and GetExcludes() in IsInside(), not UpdateRegion()
refs #7398
This commit is contained in:
parent
e813632ae2
commit
f6f5fd5dda
@ -233,7 +233,6 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
|
||||
|
||||
Array::Ptr segments = GetUpdate()->Invoke({ this, begin, end });
|
||||
|
||||
{
|
||||
ObjectLock olock(this);
|
||||
RemoveSegment(begin, end);
|
||||
|
||||
@ -243,35 +242,6 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
|
||||
AddSegment(segment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool preferInclude = GetPreferIncludes();
|
||||
|
||||
/* First handle the non preferred timeranges */
|
||||
Array::Ptr timeranges = preferInclude ? GetExcludes() : GetIncludes();
|
||||
|
||||
if (timeranges) {
|
||||
ObjectLock olock(timeranges);
|
||||
for (const String& name : timeranges) {
|
||||
const TimePeriod::Ptr timeperiod = TimePeriod::GetByName(name);
|
||||
|
||||
if (timeperiod)
|
||||
Merge(timeperiod, !preferInclude);
|
||||
}
|
||||
}
|
||||
|
||||
/* Preferred timeranges must be handled at the end */
|
||||
timeranges = preferInclude ? GetIncludes() : GetExcludes();
|
||||
|
||||
if (timeranges) {
|
||||
ObjectLock olock(timeranges);
|
||||
for (const String& name : timeranges) {
|
||||
const TimePeriod::Ptr timeperiod = TimePeriod::GetByName(name);
|
||||
|
||||
if (timeperiod)
|
||||
Merge(timeperiod, preferInclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TimePeriod::GetIsInside() const
|
||||
@ -279,10 +249,45 @@ bool TimePeriod::GetIsInside() const
|
||||
return IsInside(Utility::GetTime());
|
||||
}
|
||||
|
||||
static bool IsInsideTimePeriods(double ts, Array::Ptr tps)
|
||||
{
|
||||
if (tps) {
|
||||
ObjectLock oLock (tps);
|
||||
|
||||
for (const String& name : tps) {
|
||||
auto timeperiod (TimePeriod::GetByName(name));
|
||||
|
||||
if (timeperiod && timeperiod->IsInside(ts)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TimePeriod::IsInside(double ts) const
|
||||
{
|
||||
ObjectLock olock(this);
|
||||
|
||||
if (GetPreferIncludes()) {
|
||||
if (IsInsideTimePeriods(ts, GetIncludes())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsInsideTimePeriods(ts, GetExcludes())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (IsInsideTimePeriods(ts, GetExcludes())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsInsideTimePeriods(ts, GetIncludes())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (GetValidBegin().IsEmpty() || ts < GetValidBegin() || GetValidEnd().IsEmpty() || ts > GetValidEnd())
|
||||
return true; /* Assume that all invalid regions are "inside". */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user