From f69f7d61f247a35e1cbe1832ba21a555ed58368b Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 6 Nov 2014 19:26:44 +0100 Subject: [PATCH] Fix variable scope for object rules --- lib/config/objectrule.cpp | 5 +---- lib/icinga/hostgroup.cpp | 1 + lib/icinga/servicegroup.cpp | 1 + lib/icinga/usergroup.cpp | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/config/objectrule.cpp b/lib/config/objectrule.cpp index 36525ff0b..de6247a4a 100644 --- a/lib/config/objectrule.cpp +++ b/lib/config/objectrule.cpp @@ -65,10 +65,7 @@ void ObjectRule::AddRule(const String& sourceType, const String& name, bool ObjectRule::EvaluateFilter(const Dictionary::Ptr& scope) const { - scope->Set("__parent", m_Scope); - bool result = m_Filter->Evaluate(scope); - scope->Remove("__parent"); - return result; + return m_Filter->Evaluate(scope); } void ObjectRule::EvaluateRules(bool clear) diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index dc88c06be..312378df6 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -46,6 +46,7 @@ bool HostGroup::EvaluateObjectRuleOne(const Host::Ptr& host, const ObjectRule& r CONTEXT(msgbuf.str()); Dictionary::Ptr locals = make_shared(); + locals->Set("__parent", rule.GetScope()); locals->Set("host", host); if (!rule.EvaluateFilter(locals)) diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index 1bb570fb3..de084c5b7 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -48,6 +48,7 @@ bool ServiceGroup::EvaluateObjectRuleOne(const Service::Ptr& service, const Obje Host::Ptr host = service->GetHost(); Dictionary::Ptr locals = make_shared(); + locals->Set("__parent", rule.GetScope()); locals->Set("host", host); locals->Set("service", service); diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index 53d0d476a..a8b56c8a3 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -46,6 +46,7 @@ bool UserGroup::EvaluateObjectRuleOne(const User::Ptr& user, const ObjectRule& r CONTEXT(msgbuf.str()); Dictionary::Ptr locals = make_shared(); + locals->Set("__parent", rule.GetScope()); locals->Set("user", user); if (!rule.EvaluateFilter(locals))