diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
commit | 0915b3ef56dfac3113cce55a59a5765dc94976be (patch) | |
tree | a8fea11d50b4f083e1bf0f90025ece7f0824784a /lib/methods/timeperiodtask.cpp | |
parent | Initial commit. (diff) | |
download | icinga2-upstream.tar.xz icinga2-upstream.zip |
Adding upstream version 2.13.6.upstream/2.13.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/methods/timeperiodtask.cpp')
-rw-r--r-- | lib/methods/timeperiodtask.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/methods/timeperiodtask.cpp b/lib/methods/timeperiodtask.cpp new file mode 100644 index 0000000..bb3f1bb --- /dev/null +++ b/lib/methods/timeperiodtask.cpp @@ -0,0 +1,35 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#include "methods/timeperiodtask.hpp" +#include "base/function.hpp" + +using namespace icinga; + +REGISTER_FUNCTION_NONCONST(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate, "tp:begin:end"); +REGISTER_FUNCTION_NONCONST(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate, "tp:begin:end"); + +Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double, double) +{ + REQUIRE_NOT_NULL(tp); + + Array::Ptr segments = new Array(); + return segments; +} + +Array::Ptr TimePeriodTask::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end) +{ + REQUIRE_NOT_NULL(tp); + + ArrayData segments; + + for (long t = begin / 60 - 1; t * 60 < end; t++) { + if ((t % 2) == 0) { + segments.push_back(new Dictionary({ + { "begin", t * 60 }, + { "end", (t + 1) * 60 } + })); + } + } + + return new Array(std::move(segments)); +} |