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:
Alexander A. Klimov 2022-11-08 13:26:27 +01:00
parent a13751d972
commit 8c6bb1f46c
4 changed files with 111 additions and 117 deletions

View File

@ -79,20 +79,17 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
if (service)
frame.Locals->Set("service", service);
Value vinstances;
bool match = false;
if (rule.GetFTerm()) {
Value vinstances;
try {
vinstances = rule.GetFTerm()->Evaluate(frame);
} catch (const std::exception&) {
/* Silently ignore errors here and assume there are no instances. */
return false;
}
} else {
vinstances = new Array({ "" });
}
bool match = false;
if (vinstances.IsObjectType<Array>()) {
if (!rule.GetFVVar().IsEmpty())
@ -104,10 +101,8 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
for (const Value& instance : arr) {
String name = rule.GetName();
if (!rule.GetFKVar().IsEmpty()) {
frame.Locals->Set(rule.GetFKVar(), instance);
name += instance;
}
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
match = true;
@ -126,6 +121,9 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
match = true;
}
}
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
match = true;
}
return match;
}

View File

@ -78,20 +78,17 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
if (service)
frame.Locals->Set("service", service);
Value vinstances;
bool match = false;
if (rule.GetFTerm()) {
Value vinstances;
try {
vinstances = rule.GetFTerm()->Evaluate(frame);
} catch (const std::exception&) {
/* Silently ignore errors here and assume there are no instances. */
return false;
}
} else {
vinstances = new Array({ "" });
}
bool match = false;
if (vinstances.IsObjectType<Array>()) {
if (!rule.GetFVVar().IsEmpty())
@ -103,10 +100,8 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
for (const Value& instance : arr) {
String name = rule.GetName();
if (!rule.GetFKVar().IsEmpty()) {
frame.Locals->Set(rule.GetFKVar(), instance);
name += instance;
}
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
match = true;
@ -125,6 +120,9 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
match = true;
}
}
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
match = true;
}
return match;
}

View File

@ -77,20 +77,17 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
if (service)
frame.Locals->Set("service", service);
Value vinstances;
bool match = false;
if (rule.GetFTerm()) {
Value vinstances;
try {
vinstances = rule.GetFTerm()->Evaluate(frame);
} catch (const std::exception&) {
/* Silently ignore errors here and assume there are no instances. */
return false;
}
} else {
vinstances = new Array({ "" });
}
bool match = false;
if (vinstances.IsObjectType<Array>()) {
if (!rule.GetFVVar().IsEmpty())
@ -102,10 +99,8 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
for (const Value& instance : arr) {
String name = rule.GetName();
if (!rule.GetFKVar().IsEmpty()) {
frame.Locals->Set(rule.GetFKVar(), instance);
name += instance;
}
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
match = true;
@ -124,6 +119,9 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
match = true;
}
}
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
match = true;
}
return match;
}

View File

@ -66,20 +66,17 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bo
rule.GetScope()->CopyTo(frame.Locals);
frame.Locals->Set("host", host);
Value vinstances;
bool match = false;
if (rule.GetFTerm()) {
Value vinstances;
try {
vinstances = rule.GetFTerm()->Evaluate(frame);
} catch (const std::exception&) {
/* Silently ignore errors here and assume there are no instances. */
return false;
}
} else {
vinstances = new Array({ "" });
}
bool match = false;
if (vinstances.IsObjectType<Array>()) {
if (!rule.GetFVVar().IsEmpty())
@ -113,6 +110,9 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bo
match = true;
}
}
} else if (EvaluateApplyRuleInstance(host, rule.GetName(), frame, rule, skipFilter)) {
match = true;
}
return match;
}