diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index 336329bc2..4180747ac 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -210,6 +210,10 @@ bool Downtime::IsExpired() const bool Downtime::HasValidConfigOwner() const { + if (!ScheduledDowntime::AllConfigIsLoaded()) { + return true; + } + String configOwner = GetConfigOwner(); return configOwner.IsEmpty() || GetObject(configOwner); } diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index 449507e0c..37c3693bd 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -80,6 +80,8 @@ void ScheduledDowntime::OnAllConfigLoaded() if (!GetCheckable()) BOOST_THROW_EXCEPTION(ScriptError("ScheduledDowntime '" + GetName() + "' references a host/service which doesn't exist.", GetDebugInfo())); + + m_AllConfigLoaded.store(true); } void ScheduledDowntime::Start(bool runtimeCreated) @@ -339,3 +341,10 @@ void ScheduledDowntime::ValidateChildOptions(const Lazy& lvalue, const Va BOOST_THROW_EXCEPTION(ValidationError(this, { "child_options" }, "Invalid child_options specified")); } } + +bool ScheduledDowntime::AllConfigIsLoaded() +{ + return m_AllConfigLoaded.load(); +} + +std::atomic ScheduledDowntime::m_AllConfigLoaded (false); diff --git a/lib/icinga/scheduleddowntime.hpp b/lib/icinga/scheduleddowntime.hpp index 158349291..4322999b7 100644 --- a/lib/icinga/scheduleddowntime.hpp +++ b/lib/icinga/scheduleddowntime.hpp @@ -23,6 +23,7 @@ #include "icinga/i2-icinga.hpp" #include "icinga/scheduleddowntime-ti.hpp" #include "icinga/checkable.hpp" +#include namespace icinga { @@ -47,6 +48,7 @@ public: static void EvaluateApplyRules(const intrusive_ptr& host); static void EvaluateApplyRules(const intrusive_ptr& service); + static bool AllConfigIsLoaded(); void ValidateRanges(const Lazy& lvalue, const ValidationUtils& utils) override; void ValidateChildOptions(const Lazy& lvalue, const ValidationUtils& utils) override; @@ -62,6 +64,8 @@ private: std::pair FindNextSegment(); void CreateNextDowntime(); + static std::atomic m_AllConfigLoaded; + static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule); static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule); };