From bbcf469af1c584a92d028446c6ff1f558950cd97 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 6 Dec 2018 12:41:49 +0100 Subject: [PATCH 1/2] Implement ScheduledDowntime::AllConfigIsLoaded() refs #6542 --- lib/icinga/scheduleddowntime.cpp | 9 +++++++++ lib/icinga/scheduleddowntime.hpp | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index c092ca9f0d7..054f63628bf 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) @@ -331,3 +333,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 15834929119..4322999b7d3 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 @@ class ScheduledDowntime final : public ObjectImpl 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 @@ class ScheduledDowntime final : public ObjectImpl 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); }; From 39e0d787e82c187de64b29e4979f4caac0907441 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 6 Dec 2018 12:50:48 +0100 Subject: [PATCH 2/2] Downtime#HasValidConfigOwner(): wait for ScheduledDowntimes refs #6542 --- lib/icinga/downtime.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index 336329bc2a0..4180747ac94 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); }