Skip to content

Commit

Permalink
Merge pull request #6826 from Icinga/bugfix/downtimes-recreate-satell…
Browse files Browse the repository at this point in the history
…ite-6542

Downtime#HasValidConfigOwner(): wait for ScheduledDowntimes
  • Loading branch information
Michael Friedrich authored Dec 18, 2018
2 parents 359cb14 + 39e0d78 commit b40400e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/icinga/downtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ bool Downtime::IsExpired() const

bool Downtime::HasValidConfigOwner() const
{
if (!ScheduledDowntime::AllConfigIsLoaded()) {
return true;
}

String configOwner = GetConfigOwner();
return configOwner.IsEmpty() || GetObject<ScheduledDowntime>(configOwner);
}
Expand Down
9 changes: 9 additions & 0 deletions lib/icinga/scheduleddowntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -339,3 +341,10 @@ void ScheduledDowntime::ValidateChildOptions(const Lazy<Value>& lvalue, const Va
BOOST_THROW_EXCEPTION(ValidationError(this, { "child_options" }, "Invalid child_options specified"));
}
}

bool ScheduledDowntime::AllConfigIsLoaded()
{
return m_AllConfigLoaded.load();
}

std::atomic<bool> ScheduledDowntime::m_AllConfigLoaded (false);
4 changes: 4 additions & 0 deletions lib/icinga/scheduleddowntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "icinga/i2-icinga.hpp"
#include "icinga/scheduleddowntime-ti.hpp"
#include "icinga/checkable.hpp"
#include <atomic>

namespace icinga
{
Expand All @@ -47,6 +48,7 @@ class ScheduledDowntime final : public ObjectImpl<ScheduledDowntime>

static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
static bool AllConfigIsLoaded();

void ValidateRanges(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
void ValidateChildOptions(const Lazy<Value>& lvalue, const ValidationUtils& utils) override;
Expand All @@ -62,6 +64,8 @@ class ScheduledDowntime final : public ObjectImpl<ScheduledDowntime>
std::pair<double, double> FindNextSegment();
void CreateNextDowntime();

static std::atomic<bool> 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);
};
Expand Down

0 comments on commit b40400e

Please sign in to comment.