diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 8681c4332..5db3c2ac8 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -1,5 +1,6 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +#include "icinga/apply-utility.hpp" #include "icinga/dependency.hpp" #include "icinga/service.hpp" #include "config/configitembuilder.hpp" @@ -47,10 +48,13 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons if (service) builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "child_service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di)); - String zone = checkable->GetZoneName(); + { + auto expr (ApplyUtility::MakeCommonZone(checkable->GetZoneName(), rule.GetZone(), di)); - if (!zone.IsEmpty()) - builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di)); + if (expr) { + builder.AddExpression(expr.release()); + } + } builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di)); diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index f5b37643b..806858c25 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -1,5 +1,6 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +#include "icinga/apply-utility.hpp" #include "icinga/notification.hpp" #include "icinga/service.hpp" #include "config/configitembuilder.hpp" @@ -46,10 +47,13 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co if (service) builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di)); - String zone = checkable->GetZoneName(); + { + auto expr (ApplyUtility::MakeCommonZone(checkable->GetZoneName(), rule.GetZone(), di)); - if (!zone.IsEmpty()) - builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di)); + if (expr) { + builder.AddExpression(expr.release()); + } + } builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di)); diff --git a/lib/icinga/scheduleddowntime-apply.cpp b/lib/icinga/scheduleddowntime-apply.cpp index 4f8aa471f..9770a08fd 100644 --- a/lib/icinga/scheduleddowntime-apply.cpp +++ b/lib/icinga/scheduleddowntime-apply.cpp @@ -1,5 +1,6 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +#include "icinga/apply-utility.hpp" #include "icinga/scheduleddowntime.hpp" #include "icinga/service.hpp" #include "config/configitembuilder.hpp" @@ -45,10 +46,13 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl if (service) builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di)); - String zone = checkable->GetZoneName(); + { + auto expr (ApplyUtility::MakeCommonZone(checkable->GetZoneName(), rule.GetZone(), di)); - if (!zone.IsEmpty()) - builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di)); + if (expr) { + builder.AddExpression(expr.release()); + } + } builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di)); diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 4419e0b34..b556cb35e 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -1,5 +1,6 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +#include "icinga/apply-utility.hpp" #include "icinga/service.hpp" #include "config/configitembuilder.hpp" #include "config/applyrule.hpp" @@ -40,10 +41,13 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "name"), OpSetLiteral, MakeLiteral(name), di)); - String zone = host->GetZoneName(); + { + auto expr (ApplyUtility::MakeCommonZone(host->GetZoneName(), rule.GetZone(), di)); - if (!zone.IsEmpty()) - builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di)); + if (expr) { + builder.AddExpression(expr.release()); + } + } builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));