2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-11-13 09:41:06 +01:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "methods/timeperiodtask.hpp"
|
2015-01-21 08:47:45 +01:00
|
|
|
#include "base/function.hpp"
|
2013-11-13 09:41:06 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2018-08-07 13:55:41 +02:00
|
|
|
REGISTER_FUNCTION_NONCONST(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate, "tp:begin:end");
|
|
|
|
REGISTER_FUNCTION_NONCONST(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate, "tp:begin:end");
|
2013-11-13 09:41:06 +01:00
|
|
|
|
2018-01-30 11:26:07 +01:00
|
|
|
Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double, double)
|
2013-11-13 09:41:06 +01:00
|
|
|
{
|
2018-02-21 13:42:58 +01:00
|
|
|
REQUIRE_NOT_NULL(tp);
|
2018-01-30 11:26:07 +01:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr segments = new Array();
|
2013-11-13 09:41:06 +01:00
|
|
|
return segments;
|
|
|
|
}
|
|
|
|
|
2018-01-30 11:26:07 +01:00
|
|
|
Array::Ptr TimePeriodTask::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end)
|
2013-11-13 09:41:06 +01:00
|
|
|
{
|
2018-02-21 13:42:58 +01:00
|
|
|
REQUIRE_NOT_NULL(tp);
|
2018-01-30 11:26:07 +01:00
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
ArrayData segments;
|
2013-11-13 09:41:06 +01:00
|
|
|
|
|
|
|
for (long t = begin / 60 - 1; t * 60 < end; t++) {
|
|
|
|
if ((t % 2) == 0) {
|
2018-01-11 11:17:38 +01:00
|
|
|
segments.push_back(new Dictionary({
|
|
|
|
{ "begin", t * 60 },
|
|
|
|
{ "end", (t + 1) * 60 }
|
|
|
|
}));
|
2013-11-13 09:41:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
return new Array(std::move(segments));
|
2014-04-08 09:11:54 +02:00
|
|
|
}
|