Skip to content

Commit

Permalink
TimePeriod: consult GetIncludes() and GetExcludes() in IsInside(), no…
Browse files Browse the repository at this point in the history
…t UpdateRegion()

refs #7398
  • Loading branch information
Al2Klimov authored and yhabteab committed Jun 21, 2022
1 parent 441e25f commit 769de8d
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions lib/icinga/timeperiod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,56 +233,61 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)

Array::Ptr segments = GetUpdate()->Invoke({ this, begin, end });

{
ObjectLock olock(this);
RemoveSegment(begin, end);
ObjectLock olock(this);
RemoveSegment(begin, end);

if (segments) {
ObjectLock dlock(segments);
for (const Dictionary::Ptr& segment : segments) {
AddSegment(segment);
}
if (segments) {
ObjectLock dlock(segments);
for (const Dictionary::Ptr& segment : segments) {
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);
}
}
bool TimePeriod::GetIsInside() const
{
return IsInside(Utility::GetTime());
}

/* Preferred timeranges must be handled at the end */
timeranges = preferInclude ? GetIncludes() : GetExcludes();
static bool IsInsideTimePeriods(double ts, Array::Ptr tps)
{
if (tps) {
ObjectLock oLock (tps);

if (timeranges) {
ObjectLock olock(timeranges);
for (const String& name : timeranges) {
const TimePeriod::Ptr timeperiod = TimePeriod::GetByName(name);
for (const String& name : tps) {
auto timeperiod (TimePeriod::GetByName(name));

if (timeperiod)
Merge(timeperiod, preferInclude);
if (timeperiod && timeperiod->IsInside(ts)) {
return true;
}
}
}
}

bool TimePeriod::GetIsInside() const
{
return IsInside(Utility::GetTime());
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". */

Expand Down

0 comments on commit 769de8d

Please sign in to comment.