From: Gunnar Beutner Date: Wed, 18 Sep 2013 22:01:18 +0000 (+0200) Subject: Fix timeperiod update bug. X-Git-Tag: v0.0.3~468 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77a945157f8b36b6bc278ec02580acd255cc9d2a;p=icinga2 Fix timeperiod update bug. --- diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index f5d73f5ac..98dc67fd1 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -70,6 +70,8 @@ void TimePeriod::AddSegment(double begin, double end) { ASSERT(OwnsLock()); + Log(LogDebug, "icinga", "Adding segment '" + Utility::FormatDateTime("%c", begin) + "' <-> '" + Utility::FormatDateTime("%c", end) + "' to TimePeriod '" + GetName() + "'"); + if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin) m_ValidBegin = begin; @@ -119,6 +121,8 @@ void TimePeriod::RemoveSegment(double begin, double end) { ASSERT(OwnsLock()); + Log(LogDebug, "icinga", "Removing segment '" + Utility::FormatDateTime("%c", begin) + "' <-> '" + Utility::FormatDateTime("%c", end) + "' from TimePeriod '" + GetName() + "'"); + if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin) m_ValidBegin = begin; @@ -147,22 +151,26 @@ void TimePeriod::RemoveSegment(double begin, double end) } /* Adjust the begin/end timestamps so as to not overlap with the specified range. */ - if (segment->Get("begin") < end) + if (segment->Get("begin") > begin && segment->Get("begin") < end) segment->Set("begin", end); - if (segment->Get("end") > begin) + if (segment->Get("end") > begin && segment->Get("end") < end) segment->Set("end", begin); newSegments->Add(segment); } m_Segments = newSegments; + + Dump(); } void TimePeriod::PurgeSegments(double end) { ASSERT(OwnsLock()); + Log(LogDebug, "icinga", "Purging segments older than '" + Utility::FormatDateTime("%c", end) + "' from TimePeriod '" + GetName() + "'"); + if (m_ValidBegin.IsEmpty() || end < m_ValidBegin) return; @@ -306,6 +314,7 @@ void TimePeriod::Dump(void) Array::Ptr segments = m_Segments; Log(LogDebug, "icinga", "Dumping TimePeriod '" + GetName() + "'"); + Log(LogDebug, "icinga", "Valid from '" + Utility::FormatDateTime("%c", m_ValidBegin) + "' until '" + Utility::FormatDateTime("%c", m_ValidEnd)); if (segments) { ObjectLock dlock(segments);