Set host/service variable in apply rules

fixes #7479
This commit is contained in:
Gunnar Beutner 2014-10-29 10:09:40 +01:00
parent 93da4baf8f
commit 75b599c801
5 changed files with 14 additions and 4 deletions

View File

@ -21,3 +21,9 @@ template Service "agent-service" {
}
apply Dependency "agent-host" to Host {
parent_host_name = host.zone
assign where host.zone != "" && "agent-host" in host.templates
}

View File

@ -55,6 +55,7 @@ bool Dependency::EvaluateApplyRuleOne(const Checkable::Ptr& checkable, const App
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr locals = make_shared<Dictionary>();
locals->Set("__parent", rule.GetScope());
locals->Set("host", host);
if (service)
locals->Set("service", service);
@ -68,7 +69,7 @@ bool Dependency::EvaluateApplyRuleOne(const Checkable::Ptr& checkable, const App
ConfigItemBuilder::Ptr builder = make_shared<ConfigItemBuilder>(di);
builder->SetType("Dependency");
builder->SetName(rule.GetName());
builder->SetScope(rule.GetScope());
builder->SetScope(locals);
builder->AddExpression(make_shared<Expression>(&Expression::OpSet,
make_shared<Expression>(&Expression::OpLiteral, "parent_host_name", di),

View File

@ -55,6 +55,7 @@ bool Notification::EvaluateApplyRuleOne(const Checkable::Ptr& checkable, const A
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr locals = make_shared<Dictionary>();
locals->Set("__parent", rule.GetScope());
locals->Set("host", host);
if (service)
locals->Set("service", service);
@ -68,7 +69,7 @@ bool Notification::EvaluateApplyRuleOne(const Checkable::Ptr& checkable, const A
ConfigItemBuilder::Ptr builder = make_shared<ConfigItemBuilder>(di);
builder->SetType("Notification");
builder->SetName(rule.GetName());
builder->SetScope(rule.GetScope());
builder->SetScope(locals);
builder->AddExpression(make_shared<Expression>(&Expression::OpSet,
make_shared<Expression>(&Expression::OpLiteral, "host_name", di),

View File

@ -54,6 +54,7 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr locals = make_shared<Dictionary>();
locals->Set("__parent", rule.GetScope());
locals->Set("host", host);
if (service)
locals->Set("service", service);
@ -67,7 +68,7 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
ConfigItemBuilder::Ptr builder = make_shared<ConfigItemBuilder>(di);
builder->SetType("ScheduledDowntime");
builder->SetName(rule.GetName());
builder->SetScope(rule.GetScope());
builder->SetScope(locals);
builder->AddExpression(make_shared<Expression>(&Expression::OpSet,
make_shared<Expression>(&Expression::OpLiteral, "host_name", di),

View File

@ -49,6 +49,7 @@ bool Service::EvaluateApplyRuleOne(const Host::Ptr& host, const ApplyRule& rule)
CONTEXT(msgbuf.str());
Dictionary::Ptr locals = make_shared<Dictionary>();
locals->Set("__parent", rule.GetScope());
locals->Set("host", host);
if (!rule.EvaluateFilter(locals))
@ -60,7 +61,7 @@ bool Service::EvaluateApplyRuleOne(const Host::Ptr& host, const ApplyRule& rule)
ConfigItemBuilder::Ptr builder = make_shared<ConfigItemBuilder>(di);
builder->SetType("Service");
builder->SetName(rule.GetName());
builder->SetScope(rule.GetScope());
builder->SetScope(locals);
builder->AddExpression(make_shared<Expression>(&Expression::OpSet,
make_shared<Expression>(&Expression::OpLiteral, "host_name", di),