mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +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
a13751d972
commit
8c6bb1f46c
@ -79,20 +79,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())
|
||||||
@ -104,10 +101,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;
|
||||||
@ -126,6 +121,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;
|
||||||
}
|
}
|
||||||
|
@ -78,20 +78,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())
|
||||||
@ -103,10 +100,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;
|
||||||
@ -125,6 +120,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;
|
||||||
}
|
}
|
||||||
|
@ -77,20 +77,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())
|
||||||
@ -102,10 +99,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;
|
||||||
@ -124,6 +119,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;
|
||||||
}
|
}
|
||||||
|
@ -66,20 +66,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())
|
||||||
@ -113,6 +110,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