diff --git a/lib/icinga/dependency.cpp b/lib/icinga/dependency.cpp index 55c9e3786..db7d945c0 100644 --- a/lib/icinga/dependency.cpp +++ b/lib/icinga/dependency.cpp @@ -58,11 +58,9 @@ void Dependency::OnConfigLoaded(void) SetStateFilter(FilterArrayToInt(GetStates(), defaultFilter)); } -void Dependency::OnStateLoaded(void) +void Dependency::OnAllConfigLoaded(void) { - DynamicObject::Start(); - - ASSERT(!OwnsLock()); + DynamicObject::OnAllConfigLoaded(); Host::Ptr childHost = Host::GetByName(GetChildHostName()); @@ -79,10 +77,9 @@ void Dependency::OnStateLoaded(void) } if (!m_Child) - Log(LogWarning, "Dependency") - << "Dependency '" << GetName() << "' references an invalid child object and will be ignored."; - else - m_Child->AddDependency(this); + BOOST_THROW_EXCEPTION(ScriptError("Dependency '" << GetName() << "' references a child host/service which doesn't exist.", GetDebugInfo())); + + m_Child->AddDependency(this); Host::Ptr parentHost = Host::GetByName(GetParentHostName()); @@ -99,30 +96,23 @@ void Dependency::OnStateLoaded(void) } if (!m_Parent) - Log(LogWarning, "Dependency") - << "Dependency '" << GetName() << "' references an invalid parent object and will always fail."; - else - m_Parent->AddReverseDependency(this); + BOOST_THROW_EXCEPTION(ScriptError("Dependency '" << GetName() << "' references a parent host/service which doesn't exist.", GetDebugInfo())); + + m_Parent->AddReverseDependency(this); } void Dependency::Stop(void) { DynamicObject::Stop(); - if (GetChild()) - GetChild()->RemoveDependency(this); - - if (GetParent()) - GetParent()->RemoveReverseDependency(this); + GetChild()->RemoveDependency(this); + GetParent()->RemoveReverseDependency(this); } bool Dependency::IsAvailable(DependencyType dt) const { Checkable::Ptr parent = GetParent(); - if (!parent) - return false; - Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(parent); diff --git a/lib/icinga/dependency.hpp b/lib/icinga/dependency.hpp index 04352d3c4..e19594bcd 100644 --- a/lib/icinga/dependency.hpp +++ b/lib/icinga/dependency.hpp @@ -58,7 +58,7 @@ public: protected: virtual void OnConfigLoaded(void); - virtual void OnStateLoaded(void); + virtual void OnAllConfigLoaded(void); virtual void Stop(void); private: diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 95dafb175..799b60ae5 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -85,8 +85,10 @@ void Notification::OnAllConfigLoaded(void) { Checkable::Ptr obj = GetCheckable(); - if (obj) - obj->AddNotification(this); + if (!obj) + BOOST_THROW_EXCEPTION(ScriptError("Notification object refers to a host/service which doesn't exist.", GetDebugInfo())); + + obj->AddNotification(this); } void Notification::Start(void) diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index 544f31fb5..a1f9492bf 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -64,6 +64,14 @@ void ScheduledDowntime::StaticInitialize(void) l_Timer->Start(); } +void ScheduledDowntime::OnAllConfigLoaded(void) +{ + CustomVarObject::OnAllConfigLoaded(); + + if (!GetCheckable()) + BOOST_THROW_EXCEPTION(ScriptError("ScheduledDowntime '" + GetName() + "' references a host/service which doesn't exist.", GetDebugInfo())); +} + void ScheduledDowntime::Start(void) { DynamicObject::Start(); diff --git a/lib/icinga/scheduleddowntime.hpp b/lib/icinga/scheduleddowntime.hpp index bc82d059c..8d2ad8768 100644 --- a/lib/icinga/scheduleddowntime.hpp +++ b/lib/icinga/scheduleddowntime.hpp @@ -54,6 +54,7 @@ public: static void EvaluateApplyRules(const intrusive_ptr& service); protected: + virtual void OnAllConfigLoaded(void); virtual void Start(void); private: