Targeted apply rules: don't unnecessarily eval filter

This commit is contained in:
Alexander A. Klimov 2022-10-27 16:15:35 +02:00
parent dacd6a206d
commit a907c2ac9a
8 changed files with 35 additions and 35 deletions

View File

@ -17,9 +17,9 @@ INITIALIZE_ONCE([]() {
ApplyRule::RegisterType("Dependency", { "Host", "Service" }); ApplyRule::RegisterType("Dependency", { "Host", "Service" });
}); });
bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter)
{ {
if (!rule.EvaluateFilter(frame)) if (!skipFilter && !rule.EvaluateFilter(frame))
return false; return false;
DebugInfo di = rule.GetDebugInfo(); DebugInfo di = rule.GetDebugInfo();
@ -62,7 +62,7 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
return true; return true;
} }
bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule) bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter)
{ {
DebugInfo di = rule.GetDebugInfo(); DebugInfo di = rule.GetDebugInfo();
@ -111,7 +111,7 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
name += instance; name += instance;
} }
if (EvaluateApplyRuleInstance(checkable, name, frame, rule)) if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
match = true; match = true;
} }
} else if (vinstances.IsObjectType<Dictionary>()) { } else if (vinstances.IsObjectType<Dictionary>()) {
@ -124,7 +124,7 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
frame.Locals->Set(rule.GetFKVar(), key); frame.Locals->Set(rule.GetFKVar(), key);
frame.Locals->Set(rule.GetFVVar(), dict->Get(key)); frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule)) if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
match = true; match = true;
} }
} }
@ -142,7 +142,7 @@ void Dependency::EvaluateApplyRules(const Host::Ptr& host)
} }
for (auto& rule : ApplyRule::GetTargetedHostRules(Dependency::TypeInstance, Host::TypeInstance, host->GetName())) { for (auto& rule : ApplyRule::GetTargetedHostRules(Dependency::TypeInstance, Host::TypeInstance, host->GetName())) {
if (EvaluateApplyRule(host, *rule)) if (EvaluateApplyRule(host, *rule, true))
rule->AddMatch(); rule->AddMatch();
} }
} }
@ -157,7 +157,7 @@ void Dependency::EvaluateApplyRules(const Service::Ptr& service)
} }
for (auto& rule : ApplyRule::GetTargetedServiceRules(Dependency::TypeInstance, Service::TypeInstance, service->GetHost()->GetName(), service->GetName())) { for (auto& rule : ApplyRule::GetTargetedServiceRules(Dependency::TypeInstance, Service::TypeInstance, service->GetHost()->GetName(), service->GetName())) {
if (EvaluateApplyRule(service, *rule)) if (EvaluateApplyRule(service, *rule, true))
rule->AddMatch(); rule->AddMatch();
} }
} }

View File

@ -50,8 +50,8 @@ private:
Checkable::Ptr m_Parent; Checkable::Ptr m_Parent;
Checkable::Ptr m_Child; Checkable::Ptr m_Child;
static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule); static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter);
static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule); static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter = false);
}; };
} }

View File

@ -17,9 +17,9 @@ INITIALIZE_ONCE([]() {
ApplyRule::RegisterType("Notification", { "Host", "Service" }); ApplyRule::RegisterType("Notification", { "Host", "Service" });
}); });
bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter)
{ {
if (!rule.EvaluateFilter(frame)) if (!skipFilter && !rule.EvaluateFilter(frame))
return false; return false;
DebugInfo di = rule.GetDebugInfo(); DebugInfo di = rule.GetDebugInfo();
@ -61,7 +61,7 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
return true; return true;
} }
bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule) bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter)
{ {
DebugInfo di = rule.GetDebugInfo(); DebugInfo di = rule.GetDebugInfo();
@ -110,7 +110,7 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
name += instance; name += instance;
} }
if (EvaluateApplyRuleInstance(checkable, name, frame, rule)) if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
match = true; match = true;
} }
} else if (vinstances.IsObjectType<Dictionary>()) { } else if (vinstances.IsObjectType<Dictionary>()) {
@ -123,7 +123,7 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
frame.Locals->Set(rule.GetFKVar(), key); frame.Locals->Set(rule.GetFKVar(), key);
frame.Locals->Set(rule.GetFVVar(), dict->Get(key)); frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule)) if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
match = true; match = true;
} }
} }
@ -142,7 +142,7 @@ void Notification::EvaluateApplyRules(const Host::Ptr& host)
} }
for (auto& rule : ApplyRule::GetTargetedHostRules(Notification::TypeInstance, Host::TypeInstance, host->GetName())) { for (auto& rule : ApplyRule::GetTargetedHostRules(Notification::TypeInstance, Host::TypeInstance, host->GetName())) {
if (EvaluateApplyRule(host, *rule)) if (EvaluateApplyRule(host, *rule, true))
rule->AddMatch(); rule->AddMatch();
} }
} }
@ -157,7 +157,7 @@ void Notification::EvaluateApplyRules(const Service::Ptr& service)
} }
for (auto& rule : ApplyRule::GetTargetedServiceRules(Notification::TypeInstance, Service::TypeInstance, service->GetHost()->GetName(), service->GetName())) { for (auto& rule : ApplyRule::GetTargetedServiceRules(Notification::TypeInstance, Service::TypeInstance, service->GetHost()->GetName(), service->GetName())) {
if (EvaluateApplyRule(service, *rule)) if (EvaluateApplyRule(service, *rule, true))
rule->AddMatch(); rule->AddMatch();
} }
} }

View File

@ -118,8 +118,8 @@ private:
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = ""); void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule); static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter);
static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule); static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule, bool skipFilter = false);
static std::map<String, int> m_StateFilterMap; static std::map<String, int> m_StateFilterMap;
static std::map<String, int> m_TypeFilterMap; static std::map<String, int> m_TypeFilterMap;

View File

@ -16,9 +16,9 @@ INITIALIZE_ONCE([]() {
ApplyRule::RegisterType("ScheduledDowntime", { "Host", "Service" }); ApplyRule::RegisterType("ScheduledDowntime", { "Host", "Service" });
}); });
bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter)
{ {
if (!rule.EvaluateFilter(frame)) if (!skipFilter && !rule.EvaluateFilter(frame))
return false; return false;
DebugInfo di = rule.GetDebugInfo(); DebugInfo di = rule.GetDebugInfo();
@ -60,7 +60,7 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
return true; return true;
} }
bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule) bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter)
{ {
DebugInfo di = rule.GetDebugInfo(); DebugInfo di = rule.GetDebugInfo();
@ -109,7 +109,7 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
name += instance; name += instance;
} }
if (EvaluateApplyRuleInstance(checkable, name, frame, rule)) if (EvaluateApplyRuleInstance(checkable, name, frame, rule, skipFilter))
match = true; match = true;
} }
} else if (vinstances.IsObjectType<Dictionary>()) { } else if (vinstances.IsObjectType<Dictionary>()) {
@ -122,7 +122,7 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
frame.Locals->Set(rule.GetFKVar(), key); frame.Locals->Set(rule.GetFKVar(), key);
frame.Locals->Set(rule.GetFVVar(), dict->Get(key)); frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule)) if (EvaluateApplyRuleInstance(checkable, rule.GetName() + key, frame, rule, skipFilter))
match = true; match = true;
} }
} }
@ -140,7 +140,7 @@ void ScheduledDowntime::EvaluateApplyRules(const Host::Ptr& host)
} }
for (auto& rule : ApplyRule::GetTargetedHostRules(ScheduledDowntime::TypeInstance, Host::TypeInstance, host->GetName())) { for (auto& rule : ApplyRule::GetTargetedHostRules(ScheduledDowntime::TypeInstance, Host::TypeInstance, host->GetName())) {
if (EvaluateApplyRule(host, *rule)) if (EvaluateApplyRule(host, *rule, true))
rule->AddMatch(); rule->AddMatch();
} }
} }
@ -155,7 +155,7 @@ void ScheduledDowntime::EvaluateApplyRules(const Service::Ptr& service)
} }
for (auto& rule : ApplyRule::GetTargetedServiceRules(ScheduledDowntime::TypeInstance, Service::TypeInstance, service->GetHost()->GetName(), service->GetName())) { for (auto& rule : ApplyRule::GetTargetedServiceRules(ScheduledDowntime::TypeInstance, Service::TypeInstance, service->GetHost()->GetName(), service->GetName())) {
if (EvaluateApplyRule(service, *rule)) if (EvaluateApplyRule(service, *rule, true))
rule->AddMatch(); rule->AddMatch();
} }
} }

View File

@ -51,8 +51,8 @@ private:
static std::atomic<bool> m_AllConfigLoaded; static std::atomic<bool> m_AllConfigLoaded;
static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule); static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter);
static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule); static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter = false);
}; };
} }

View File

@ -16,9 +16,9 @@ INITIALIZE_ONCE([]() {
ApplyRule::RegisterType("Service", { "Host" }); ApplyRule::RegisterType("Service", { "Host" });
}); });
bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule) bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter)
{ {
if (!rule.EvaluateFilter(frame)) if (!skipFilter && !rule.EvaluateFilter(frame))
return false; return false;
DebugInfo di = rule.GetDebugInfo(); DebugInfo di = rule.GetDebugInfo();
@ -55,7 +55,7 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
return true; return true;
} }
bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule) bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bool skipFilter)
{ {
DebugInfo di = rule.GetDebugInfo(); DebugInfo di = rule.GetDebugInfo();
@ -98,7 +98,7 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
name += instance; name += instance;
} }
if (EvaluateApplyRuleInstance(host, name, frame, rule)) if (EvaluateApplyRuleInstance(host, name, frame, rule, skipFilter))
match = true; match = true;
} }
} else if (vinstances.IsObjectType<Dictionary>()) { } else if (vinstances.IsObjectType<Dictionary>()) {
@ -111,7 +111,7 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
frame.Locals->Set(rule.GetFKVar(), key); frame.Locals->Set(rule.GetFKVar(), key);
frame.Locals->Set(rule.GetFVVar(), dict->Get(key)); frame.Locals->Set(rule.GetFVVar(), dict->Get(key));
if (EvaluateApplyRuleInstance(host, rule.GetName() + key, frame, rule)) if (EvaluateApplyRuleInstance(host, rule.GetName() + key, frame, rule, skipFilter))
match = true; match = true;
} }
} }
@ -129,7 +129,7 @@ void Service::EvaluateApplyRules(const Host::Ptr& host)
} }
for (auto& rule : ApplyRule::GetTargetedHostRules(Service::TypeInstance, Host::TypeInstance, host->GetName())) { for (auto& rule : ApplyRule::GetTargetedHostRules(Service::TypeInstance, Host::TypeInstance, host->GetName())) {
if (EvaluateApplyRule(host, *rule)) if (EvaluateApplyRule(host, *rule, true))
rule->AddMatch(); rule->AddMatch();
} }
} }

View File

@ -54,8 +54,8 @@ protected:
private: private:
Host::Ptr m_Host; Host::Ptr m_Host;
static bool EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule); static bool EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter);
static bool EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule); static bool EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bool skipFilter = false);
}; };
std::pair<Host::Ptr, Service::Ptr> GetHostService(const Checkable::Ptr& checkable); std::pair<Host::Ptr, Service::Ptr> GetHostService(const Checkable::Ptr& checkable);