mirror of
https://github.com/Icinga/icinga2.git
synced 2025-06-13 02:00:17 +02:00
TimePeriod update function should return an array of time segments
Fixes #3857
This commit is contained in:
parent
0f9acdffbb
commit
4e7c43c8c8
@ -104,6 +104,11 @@ void TimePeriod::AddSegment(double begin, double end)
|
|||||||
Touch("segments");
|
Touch("segments");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimePeriod::AddSegment(const Dictionary::Ptr& segment)
|
||||||
|
{
|
||||||
|
AddSegment(segment->Get("begin"), segment->Get("end"));
|
||||||
|
}
|
||||||
|
|
||||||
void TimePeriod::RemoveSegment(double begin, double end)
|
void TimePeriod::RemoveSegment(double begin, double end)
|
||||||
{
|
{
|
||||||
ASSERT(OwnsLock());
|
ASSERT(OwnsLock());
|
||||||
@ -199,7 +204,16 @@ void TimePeriod::UpdateRegion(double begin, double end)
|
|||||||
}
|
}
|
||||||
|
|
||||||
task->Start();
|
task->Start();
|
||||||
task->GetResult();
|
Array::Ptr segments = task->GetResult();
|
||||||
|
|
||||||
|
{
|
||||||
|
ObjectLock olock(this);
|
||||||
|
RemoveSegment(begin, end);
|
||||||
|
|
||||||
|
BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
|
||||||
|
AddSegment(segment);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimePeriod::IsInside(double ts) const
|
bool TimePeriod::IsInside(double ts) const
|
||||||
@ -274,10 +288,8 @@ void TimePeriod::EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const vector
|
|||||||
double begin = arguments[1];
|
double begin = arguments[1];
|
||||||
double end = arguments[2];
|
double end = arguments[2];
|
||||||
|
|
||||||
ObjectLock olock(tp);
|
Array::Ptr segments = boost::make_shared<Array>();
|
||||||
tp->RemoveSegment(begin, end);
|
task->FinishResult(segments);
|
||||||
|
|
||||||
task->FinishResult(Empty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const vector<Value>& arguments)
|
void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const vector<Value>& arguments)
|
||||||
@ -289,16 +301,17 @@ void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const
|
|||||||
double begin = arguments[1];
|
double begin = arguments[1];
|
||||||
double end = arguments[2];
|
double end = arguments[2];
|
||||||
|
|
||||||
{
|
Array::Ptr segments = boost::make_shared<Array>();
|
||||||
ObjectLock olock(tp);
|
|
||||||
|
|
||||||
tp->RemoveSegment(begin, end);
|
for (long t = begin; t < end; t += 60) {
|
||||||
|
if ((t / 60) % 2 == 0) {
|
||||||
|
Dictionary::Ptr segment = boost::make_shared<Dictionary>();
|
||||||
|
segment->Set("begin", t);
|
||||||
|
segment->Set("end", t + 60);
|
||||||
|
|
||||||
for (long t = begin; t < end; t += 60) {
|
segments->Add(segment);
|
||||||
if ((t / 60) % 2 == 0)
|
|
||||||
tp->AddSegment(t, t + 60);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task->FinishResult(Empty);
|
task->FinishResult(segments);
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,6 @@ public:
|
|||||||
|
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
|
|
||||||
void AddSegment(double s, double end);
|
|
||||||
void RemoveSegment(double begin, double end);
|
|
||||||
void PurgeSegments(double end);
|
|
||||||
|
|
||||||
void UpdateRegion(double begin, double end);
|
void UpdateRegion(double begin, double end);
|
||||||
|
|
||||||
bool IsInside(double ts) const;
|
bool IsInside(double ts) const;
|
||||||
@ -57,6 +53,11 @@ private:
|
|||||||
Attribute<double> m_ValidEnd;
|
Attribute<double> m_ValidEnd;
|
||||||
Attribute<Array::Ptr> m_Segments;
|
Attribute<Array::Ptr> m_Segments;
|
||||||
|
|
||||||
|
void AddSegment(double s, double end);
|
||||||
|
void AddSegment(const Dictionary::Ptr& segment);
|
||||||
|
void RemoveSegment(double begin, double end);
|
||||||
|
void PurgeSegments(double end);
|
||||||
|
|
||||||
static Timer::Ptr m_UpdateTimer;
|
static Timer::Ptr m_UpdateTimer;
|
||||||
static void UpdateTimerHandler(void);
|
static void UpdateTimerHandler(void);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user