mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 21:55:03 +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,52 +79,50 @@ 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 (!rule.GetFVVar().IsEmpty())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
|
||||||
|
|
||||||
if (vinstances.IsObjectType<Array>()) {
|
Array::Ptr arr = vinstances;
|
||||||
if (!rule.GetFVVar().IsEmpty())
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
|
|
||||||
|
|
||||||
Array::Ptr arr = vinstances;
|
ObjectLock olock(arr);
|
||||||
|
for (const Value& instance : arr) {
|
||||||
|
String name = rule.GetName();
|
||||||
|
|
||||||
ObjectLock olock(arr);
|
|
||||||
for (const Value& instance : arr) {
|
|
||||||
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))
|
||||||
|
match = true;
|
||||||
}
|
}
|
||||||
|
} else if (vinstances.IsObjectType<Dictionary>()) {
|
||||||
|
if (rule.GetFVVar().IsEmpty())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di));
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
Dictionary::Ptr dict = vinstances;
|
||||||
match = true;
|
|
||||||
}
|
for (const String& key : dict->GetKeys()) {
|
||||||
} else if (vinstances.IsObjectType<Dictionary>()) {
|
frame.Locals->Set(rule.GetFKVar(), key);
|
||||||
if (rule.GetFVVar().IsEmpty())
|
frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di));
|
|
||||||
|
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
|
||||||
Dictionary::Ptr dict = vinstances;
|
match = true;
|
||||||
|
}
|
||||||
for (const String& key : dict->GetKeys()) {
|
|
||||||
frame.Locals->Set(rule.GetFKVar(), key);
|
|
||||||
frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
|
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
|
|
||||||
match = true;
|
|
||||||
}
|
}
|
||||||
|
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
|
||||||
|
match = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
|
@ -78,52 +78,50 @@ 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 (!rule.GetFVVar().IsEmpty())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
|
||||||
|
|
||||||
if (vinstances.IsObjectType<Array>()) {
|
Array::Ptr arr = vinstances;
|
||||||
if (!rule.GetFVVar().IsEmpty())
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
|
|
||||||
|
|
||||||
Array::Ptr arr = vinstances;
|
ObjectLock olock(arr);
|
||||||
|
for (const Value& instance : arr) {
|
||||||
|
String name = rule.GetName();
|
||||||
|
|
||||||
ObjectLock olock(arr);
|
|
||||||
for (const Value& instance : arr) {
|
|
||||||
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))
|
||||||
|
match = true;
|
||||||
}
|
}
|
||||||
|
} else if (vinstances.IsObjectType<Dictionary>()) {
|
||||||
|
if (rule.GetFVVar().IsEmpty())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di));
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
Dictionary::Ptr dict = vinstances;
|
||||||
match = true;
|
|
||||||
}
|
for (const String& key : dict->GetKeys()) {
|
||||||
} else if (vinstances.IsObjectType<Dictionary>()) {
|
frame.Locals->Set(rule.GetFKVar(), key);
|
||||||
if (rule.GetFVVar().IsEmpty())
|
frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di));
|
|
||||||
|
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
|
||||||
Dictionary::Ptr dict = vinstances;
|
match = true;
|
||||||
|
}
|
||||||
for (const String& key : dict->GetKeys()) {
|
|
||||||
frame.Locals->Set(rule.GetFKVar(), key);
|
|
||||||
frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
|
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
|
|
||||||
match = true;
|
|
||||||
}
|
}
|
||||||
|
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
|
||||||
|
match = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
|
@ -77,52 +77,50 @@ 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 (!rule.GetFVVar().IsEmpty())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
|
||||||
|
|
||||||
if (vinstances.IsObjectType<Array>()) {
|
Array::Ptr arr = vinstances;
|
||||||
if (!rule.GetFVVar().IsEmpty())
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
|
|
||||||
|
|
||||||
Array::Ptr arr = vinstances;
|
ObjectLock olock(arr);
|
||||||
|
for (const Value& instance : arr) {
|
||||||
|
String name = rule.GetName();
|
||||||
|
|
||||||
ObjectLock olock(arr);
|
|
||||||
for (const Value& instance : arr) {
|
|
||||||
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))
|
||||||
|
match = true;
|
||||||
}
|
}
|
||||||
|
} else if (vinstances.IsObjectType<Dictionary>()) {
|
||||||
|
if (rule.GetFVVar().IsEmpty())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di));
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
|
Dictionary::Ptr dict = vinstances;
|
||||||
match = true;
|
|
||||||
}
|
for (const String& key : dict->GetKeys()) {
|
||||||
} else if (vinstances.IsObjectType<Dictionary>()) {
|
frame.Locals->Set(rule.GetFKVar(), key);
|
||||||
if (rule.GetFVVar().IsEmpty())
|
frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di));
|
|
||||||
|
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
|
||||||
Dictionary::Ptr dict = vinstances;
|
match = true;
|
||||||
|
}
|
||||||
for (const String& key : dict->GetKeys()) {
|
|
||||||
frame.Locals->Set(rule.GetFKVar(), key);
|
|
||||||
frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
|
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
|
|
||||||
match = true;
|
|
||||||
}
|
}
|
||||||
|
} else if (EvaluateApplyRuleInstance(checkable, rule.GetName(), frame, rule, skipFilter)) {
|
||||||
|
match = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
|
@ -66,52 +66,52 @@ 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 (!rule.GetFVVar().IsEmpty())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
|
||||||
|
|
||||||
if (vinstances.IsObjectType<Array>()) {
|
Array::Ptr arr = vinstances;
|
||||||
if (!rule.GetFVVar().IsEmpty())
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di));
|
|
||||||
|
|
||||||
Array::Ptr arr = vinstances;
|
ObjectLock olock(arr);
|
||||||
|
for (const Value& instance : arr) {
|
||||||
|
String name = rule.GetName();
|
||||||
|
|
||||||
ObjectLock olock(arr);
|
if (!rule.GetFKVar().IsEmpty()) {
|
||||||
for (const Value& instance : arr) {
|
frame.Locals->Set(rule.GetFKVar(), instance);
|
||||||
String name = rule.GetName();
|
name += instance;
|
||||||
|
}
|
||||||
|
|
||||||
if (!rule.GetFKVar().IsEmpty()) {
|
if (EvaluateApplyRuleInstance(host, name, frame, rule, skipFilter))
|
||||||
frame.Locals->Set(rule.GetFKVar(), instance);
|
match = true;
|
||||||
name += instance;
|
|
||||||
}
|
}
|
||||||
|
} else if (vinstances.IsObjectType<Dictionary>()) {
|
||||||
|
if (rule.GetFVVar().IsEmpty())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di));
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(host, name, frame, rule, skipFilter))
|
Dictionary::Ptr dict = vinstances;
|
||||||
match = true;
|
|
||||||
}
|
for (const String& key : dict->GetKeys()) {
|
||||||
} else if (vinstances.IsObjectType<Dictionary>()) {
|
frame.Locals->Set(rule.GetFKVar(), key);
|
||||||
if (rule.GetFVVar().IsEmpty())
|
frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di));
|
|
||||||
|
if (EvaluateApplyRuleInstance(host, rule.GetName() + key, frame, rule, skipFilter))
|
||||||
Dictionary::Ptr dict = vinstances;
|
match = true;
|
||||||
|
}
|
||||||
for (const String& key : dict->GetKeys()) {
|
|
||||||
frame.Locals->Set(rule.GetFKVar(), key);
|
|
||||||
frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
|
|
||||||
|
|
||||||
if (EvaluateApplyRuleInstance(host, rule.GetName() + key, frame, rule, skipFilter))
|
|
||||||
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