mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-23 09:48:05 +02:00
T::EvaluateApplyRule(): don't squish non-for apply rules into apply-for logic
to K. I. S. S. and avoid malloc().
This commit is contained in:
parent
a6b05059ab
commit
ec704bcf18
@ -81,20 +81,17 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
|
|||||||
if (service)
|
if (service)
|
||||||
frame.Locals->Set("service", service);
|
frame.Locals->Set("service", service);
|
||||||
|
|
||||||
Value vinstances;
|
bool match = false;
|
||||||
|
|
||||||
if (rule.GetFTerm()) {
|
if (rule.GetFTerm()) {
|
||||||
|
Value vinstances;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vinstances = rule.GetFTerm()->Evaluate(frame);
|
vinstances = rule.GetFTerm()->Evaluate(frame);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
/* Silently ignore errors here and assume there are no instances. */
|
/* Silently ignore errors here and assume there are no instances. */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
vinstances = new Array({ "" });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool match = false;
|
|
||||||
|
|
||||||
if (vinstances.IsObjectType<Array>()) {
|
if (vinstances.IsObjectType<Array>()) {
|
||||||
if (!rule.GetFVVar().IsEmpty())
|
if (!rule.GetFVVar().IsEmpty())
|
||||||
@ -106,10 +103,8 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
|
|||||||
for (const Value& instance : arr) {
|
for (const Value& instance : arr) {
|
||||||
String name = rule.GetName();
|
String name = rule.GetName();
|
||||||
|
|
||||||
if (!rule.GetFKVar().IsEmpty()) {
|
|
||||||
frame.Locals->Set(rule.GetFKVar(), instance);
|
frame.Locals->Set(rule.GetFKVar(), instance);
|
||||||
name += instance;
|
name += instance;
|
||||||
}
|
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
||||||
match = true;
|
match = true;
|
||||||
@ -128,6 +123,9 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
|
|||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
@ -80,20 +80,17 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
|
|||||||
if (service)
|
if (service)
|
||||||
frame.Locals->Set("service", service);
|
frame.Locals->Set("service", service);
|
||||||
|
|
||||||
Value vinstances;
|
bool match = false;
|
||||||
|
|
||||||
if (rule.GetFTerm()) {
|
if (rule.GetFTerm()) {
|
||||||
|
Value vinstances;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vinstances = rule.GetFTerm()->Evaluate(frame);
|
vinstances = rule.GetFTerm()->Evaluate(frame);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
/* Silently ignore errors here and assume there are no instances. */
|
/* Silently ignore errors here and assume there are no instances. */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
vinstances = new Array({ "" });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool match = false;
|
|
||||||
|
|
||||||
if (vinstances.IsObjectType<Array>()) {
|
if (vinstances.IsObjectType<Array>()) {
|
||||||
if (!rule.GetFVVar().IsEmpty())
|
if (!rule.GetFVVar().IsEmpty())
|
||||||
@ -105,10 +102,8 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
|
|||||||
for (const Value& instance : arr) {
|
for (const Value& instance : arr) {
|
||||||
String name = rule.GetName();
|
String name = rule.GetName();
|
||||||
|
|
||||||
if (!rule.GetFKVar().IsEmpty()) {
|
|
||||||
frame.Locals->Set(rule.GetFKVar(), instance);
|
frame.Locals->Set(rule.GetFKVar(), instance);
|
||||||
name += instance;
|
name += instance;
|
||||||
}
|
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
||||||
match = true;
|
match = true;
|
||||||
@ -127,6 +122,9 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
|
|||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
@ -79,20 +79,17 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
|
|||||||
if (service)
|
if (service)
|
||||||
frame.Locals->Set("service", service);
|
frame.Locals->Set("service", service);
|
||||||
|
|
||||||
Value vinstances;
|
bool match = false;
|
||||||
|
|
||||||
if (rule.GetFTerm()) {
|
if (rule.GetFTerm()) {
|
||||||
|
Value vinstances;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vinstances = rule.GetFTerm()->Evaluate(frame);
|
vinstances = rule.GetFTerm()->Evaluate(frame);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
/* Silently ignore errors here and assume there are no instances. */
|
/* Silently ignore errors here and assume there are no instances. */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
vinstances = new Array({ "" });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool match = false;
|
|
||||||
|
|
||||||
if (vinstances.IsObjectType<Array>()) {
|
if (vinstances.IsObjectType<Array>()) {
|
||||||
if (!rule.GetFVVar().IsEmpty())
|
if (!rule.GetFVVar().IsEmpty())
|
||||||
@ -104,10 +101,8 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
|
|||||||
for (const Value& instance : arr) {
|
for (const Value& instance : arr) {
|
||||||
String name = rule.GetName();
|
String name = rule.GetName();
|
||||||
|
|
||||||
if (!rule.GetFKVar().IsEmpty()) {
|
|
||||||
frame.Locals->Set(rule.GetFKVar(), instance);
|
frame.Locals->Set(rule.GetFKVar(), instance);
|
||||||
name += instance;
|
name += instance;
|
||||||
}
|
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
||||||
match = true;
|
match = true;
|
||||||
@ -126,6 +121,9 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
|
|||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
@ -68,20 +68,17 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bo
|
|||||||
rule.GetScope()->CopyTo(frame.Locals);
|
rule.GetScope()->CopyTo(frame.Locals);
|
||||||
frame.Locals->Set("host", host);
|
frame.Locals->Set("host", host);
|
||||||
|
|
||||||
Value vinstances;
|
bool match = false;
|
||||||
|
|
||||||
if (rule.GetFTerm()) {
|
if (rule.GetFTerm()) {
|
||||||
|
Value vinstances;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vinstances = rule.GetFTerm()->Evaluate(frame);
|
vinstances = rule.GetFTerm()->Evaluate(frame);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
/* Silently ignore errors here and assume there are no instances. */
|
/* Silently ignore errors here and assume there are no instances. */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
vinstances = new Array({ "" });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool match = false;
|
|
||||||
|
|
||||||
if (vinstances.IsObjectType<Array>()) {
|
if (vinstances.IsObjectType<Array>()) {
|
||||||
if (!rule.GetFVVar().IsEmpty())
|
if (!rule.GetFVVar().IsEmpty())
|
||||||
@ -115,6 +112,9 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bo
|
|||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (EvaluateApplyRuleInstance(host, rule.GetName(), frame, rule, skipFilter)) {
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user