mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-25 18:48:50 +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 });
|
Array::Ptr segments = GetUpdate()->Invoke({ this, begin, end });
|
||||||
|
|
||||||
{
|
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
RemoveSegment(begin, end);
|
RemoveSegment(begin, end);
|
||||||
|
|
||||||
@ -245,44 +244,50 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
bool TimePeriod::GetIsInside() const
|
||||||
{
|
{
|
||||||
return IsInside(Utility::GetTime());
|
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
|
bool TimePeriod::IsInside(double ts) const
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
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())
|
if (GetValidBegin().IsEmpty() || ts < GetValidBegin() || GetValidEnd().IsEmpty() || ts > GetValidEnd())
|
||||||
return true; /* Assume that all invalid regions are "inside". */
|
return true; /* Assume that all invalid regions are "inside". */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user