mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 06:34:42 +02:00
Avoid evaluating the same filter twice for the same target
This commit is contained in:
parent
a698b9c3da
commit
2610fb1285
@ -11,7 +11,7 @@ using namespace icinga;
|
|||||||
/**
|
/**
|
||||||
* @returns All ApplyRules targeting only specific parent objects including the given host. (See AddTargetedRule().)
|
* @returns All ApplyRules targeting only specific parent objects including the given host. (See AddTargetedRule().)
|
||||||
*/
|
*/
|
||||||
const std::vector<ApplyRule::Ptr>& ApplyRule::GetTargetedHostRules(const Type::Ptr& sourceType, const String& host)
|
const std::set<ApplyRule::Ptr>& ApplyRule::GetTargetedHostRules(const Type::Ptr& sourceType, const String& host)
|
||||||
{
|
{
|
||||||
auto perSourceType (m_Rules.find(sourceType.get()));
|
auto perSourceType (m_Rules.find(sourceType.get()));
|
||||||
|
|
||||||
@ -23,14 +23,14 @@ const std::vector<ApplyRule::Ptr>& ApplyRule::GetTargetedHostRules(const Type::P
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::vector<ApplyRule::Ptr> noRules;
|
static const std::set<ApplyRule::Ptr> noRules;
|
||||||
return noRules;
|
return noRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns All ApplyRules targeting only specific parent objects including the given service. (See AddTargetedRule().)
|
* @returns All ApplyRules targeting only specific parent objects including the given service. (See AddTargetedRule().)
|
||||||
*/
|
*/
|
||||||
const std::vector<ApplyRule::Ptr>& ApplyRule::GetTargetedServiceRules(const Type::Ptr& sourceType, const String& host, const String& service)
|
const std::set<ApplyRule::Ptr>& ApplyRule::GetTargetedServiceRules(const Type::Ptr& sourceType, const String& host, const String& service)
|
||||||
{
|
{
|
||||||
auto perSourceType (m_Rules.find(sourceType.get()));
|
auto perSourceType (m_Rules.find(sourceType.get()));
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ const std::vector<ApplyRule::Ptr>& ApplyRule::GetTargetedServiceRules(const Type
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::vector<ApplyRule::Ptr> noRules;
|
static const std::set<ApplyRule::Ptr> noRules;
|
||||||
return noRules;
|
return noRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ bool ApplyRule::AddTargetedRule(const ApplyRule::Ptr& rule, const String& target
|
|||||||
|
|
||||||
if (GetTargetHosts(rule->m_Filter.get(), hosts)) {
|
if (GetTargetHosts(rule->m_Filter.get(), hosts)) {
|
||||||
for (auto host : hosts) {
|
for (auto host : hosts) {
|
||||||
rules.Targeted[*host].ForHost.emplace_back(rule);
|
rules.Targeted[*host].ForHost.emplace(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -77,7 +77,7 @@ bool ApplyRule::AddTargetedRule(const ApplyRule::Ptr& rule, const String& target
|
|||||||
|
|
||||||
if (GetTargetServices(rule->m_Filter.get(), services)) {
|
if (GetTargetServices(rule->m_Filter.get(), services)) {
|
||||||
for (auto service : services) {
|
for (auto service : services) {
|
||||||
rules.Targeted[*service.first].ForServices[*service.second].emplace_back(rule);
|
rules.Targeted[*service.first].ForServices[*service.second].emplace(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -23,8 +23,8 @@ public:
|
|||||||
|
|
||||||
struct PerHost
|
struct PerHost
|
||||||
{
|
{
|
||||||
std::vector<ApplyRule::Ptr> ForHost;
|
std::set<ApplyRule::Ptr> ForHost;
|
||||||
std::unordered_map<String /* service */, std::vector<ApplyRule::Ptr>> ForServices;
|
std::unordered_map<String /* service */, std::set<ApplyRule::Ptr>> ForServices;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PerSourceType
|
struct PerSourceType
|
||||||
@ -36,13 +36,13 @@ public:
|
|||||||
/*
|
/*
|
||||||
* m_Rules[T::TypeInstance.get()].Targeted["H"].ForHost
|
* m_Rules[T::TypeInstance.get()].Targeted["H"].ForHost
|
||||||
* contains all apply rules like apply T "x" to Host { ... }
|
* contains all apply rules like apply T "x" to Host { ... }
|
||||||
* which target only specific hosts incl. "H", e. g. via
|
* which target only specific hosts incl. "H", e.g. via
|
||||||
* assign where host.name == "H" || host.name == "h".
|
* assign where host.name == "H" || host.name == "h".
|
||||||
*
|
*
|
||||||
* m_Rules[T::TypeInstance.get()].Targeted["H"].ForServices["S"]
|
* m_Rules[T::TypeInstance.get()].Targeted["H"].ForServices["S"]
|
||||||
* contains all apply rules like apply T "x" to Service { ... }
|
* contains all apply rules like apply T "x" to Service { ... }
|
||||||
* which target only specific services on specific hosts incl. "H!S",
|
* which target only specific services on specific hosts,
|
||||||
* e. g. via assign where host.name == "H" && service.name == "S".
|
* e.g. via assign where host.name == "H" && service.name == "S".
|
||||||
*
|
*
|
||||||
* m_Rules[T::TypeInstance.get()].Regular[C::TypeInstance.get()]
|
* m_Rules[T::TypeInstance.get()].Regular[C::TypeInstance.get()]
|
||||||
* contains all other apply rules like apply T "x" to C { ... }.
|
* contains all other apply rules like apply T "x" to C { ... }.
|
||||||
@ -70,8 +70,8 @@ public:
|
|||||||
const Expression::Ptr& filter, const String& package, const String& fkvar, const String& fvvar, const Expression::Ptr& fterm,
|
const Expression::Ptr& filter, const String& package, const String& fkvar, const String& fvvar, const Expression::Ptr& fterm,
|
||||||
bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
|
bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||||
static const std::vector<ApplyRule::Ptr>& GetRules(const Type::Ptr& sourceType, const Type::Ptr& targetType);
|
static const std::vector<ApplyRule::Ptr>& GetRules(const Type::Ptr& sourceType, const Type::Ptr& targetType);
|
||||||
static const std::vector<ApplyRule::Ptr>& GetTargetedHostRules(const Type::Ptr& sourceType, const String& host);
|
static const std::set<ApplyRule::Ptr>& GetTargetedHostRules(const Type::Ptr& sourceType, const String& host);
|
||||||
static const std::vector<ApplyRule::Ptr>& GetTargetedServiceRules(const Type::Ptr& sourceType, const String& host, const String& service);
|
static const std::set<ApplyRule::Ptr>& GetTargetedServiceRules(const Type::Ptr& sourceType, const String& host, const String& service);
|
||||||
|
|
||||||
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
|
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
|
||||||
static bool IsValidSourceType(const String& sourceType);
|
static bool IsValidSourceType(const String& sourceType);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user