Fix validation for service names in Notification, Dependency and ScheduledDowntime objects

fixes #8122
This commit is contained in:
Gunnar Beutner 2014-12-19 10:56:34 +01:00
parent 2e9944f4bd
commit 06052c0539
5 changed files with 24 additions and 23 deletions

View File

@ -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);

View File

@ -58,7 +58,7 @@ public:
protected:
virtual void OnConfigLoaded(void);
virtual void OnStateLoaded(void);
virtual void OnAllConfigLoaded(void);
virtual void Stop(void);
private:

View File

@ -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)

View File

@ -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();

View File

@ -54,6 +54,7 @@ public:
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
protected:
virtual void OnAllConfigLoaded(void);
virtual void Start(void);
private: