diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index 23afdbef4..8f4638526 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -584,6 +584,14 @@ void Downtime::ValidateEndTime(const Lazy& lvalue, const ValidationUt BOOST_THROW_EXCEPTION(ValidationError(this, { "end_time" }, "End time must be greater than 0.")); } +void Downtime::ValidateDuration(const Lazy& lvalue, const ValidationUtils& utils) +{ + ObjectImpl::ValidateDuration(lvalue, utils); + + if (lvalue() < 0) + BOOST_THROW_EXCEPTION(ValidationError(this, { "duration" }, "Duration must be positive.")); +} + DowntimeChildOptions Downtime::ChildOptionsFromValue(const Value& options) { if (options == "DowntimeNoChildren") diff --git a/lib/icinga/downtime.hpp b/lib/icinga/downtime.hpp index 519d78f2b..d9e65fc16 100644 --- a/lib/icinga/downtime.hpp +++ b/lib/icinga/downtime.hpp @@ -84,6 +84,7 @@ protected: void ValidateStartTime(const Lazy& lvalue, const ValidationUtils& utils) override; void ValidateEndTime(const Lazy& lvalue, const ValidationUtils& utils) override; + void ValidateDuration(const Lazy& lvalue, const ValidationUtils& utils) override; private: ObjectImpl::Ptr m_Checkable; diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index 6afdf602c..87b23865d 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -89,6 +89,14 @@ void ScheduledDowntime::Start(bool runtimeCreated) Utility::QueueAsyncCallback([this]() { CreateNextDowntime(); }); } +void ScheduledDowntime::ValidateDuration(const Lazy& lvalue, const ValidationUtils& utils) +{ + ObjectImpl::ValidateDuration(lvalue, utils); + + if (lvalue() < 0) + BOOST_THROW_EXCEPTION(ValidationError(this, { "duration" }, "Duration must be positive.")); +} + void ScheduledDowntime::TimerProc() { for (const ScheduledDowntime::Ptr& sd : ConfigType::GetObjectsByType()) { diff --git a/lib/icinga/scheduleddowntime.hpp b/lib/icinga/scheduleddowntime.hpp index 8ede9666c..fc65c99b2 100644 --- a/lib/icinga/scheduleddowntime.hpp +++ b/lib/icinga/scheduleddowntime.hpp @@ -41,6 +41,7 @@ public: protected: void OnAllConfigLoaded() override; void Start(bool runtimeCreated) override; + void ValidateDuration(const Lazy& lvalue, const ValidationUtils& utils) override; private: static void TimerProc();