diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 67b69aef8..2bff8334f 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -25,6 +25,7 @@ #include "base/dynamictype.h" #include "base/logger_fwd.h" #include "base/context.h" +#include "base/workqueue.h" #include using namespace icinga; @@ -39,7 +40,7 @@ void Dependency::RegisterApplyRuleHandler(void) ApplyRule::RegisterType("Dependency", targets, &Dependency::EvaluateApplyRules); } -bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule) +bool Dependency::EvaluateApplyRuleOne(const Checkable::Ptr& checkable, const ApplyRule& rule) { DebugInfo di = rule.GetDebugInfo(); @@ -104,39 +105,48 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR return true; } -void Dependency::EvaluateApplyRules(const std::vector& rules) +void Dependency::EvaluateApplyRule(const ApplyRule& rule) { int apply_count = 0; - BOOST_FOREACH(const ApplyRule& rule, rules) { - if (rule.GetTargetType() == "Host") { - apply_count = 0; + if (rule.GetTargetType() == "Host") { + apply_count = 0; - BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects()) { - CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); + BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects()) { + CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); - if (EvaluateApplyRule(host, rule)) - apply_count++; - } - - if (apply_count == 0) - Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!"); - - } else if (rule.GetTargetType() == "Service") { - apply_count = 0; - - BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { - CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'"); - - if(EvaluateApplyRule(service, rule)) - apply_count++; - } - - if (apply_count == 0) - Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for service does not match anywhere!"); - - } else { - Log(LogWarning, "icinga", "Wrong target type for apply rule '" + rule.GetName() + "'!"); + if (EvaluateApplyRuleOne(host, rule)) + apply_count++; } + + if (apply_count == 0) + Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!"); + + } else if (rule.GetTargetType() == "Service") { + apply_count = 0; + + BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { + CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'"); + + if (EvaluateApplyRuleOne(service, rule)) + apply_count++; + } + + if (apply_count == 0) + Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for service does not match anywhere!"); + + } else { + Log(LogWarning, "icinga", "Wrong target type for apply rule '" + rule.GetName() + "'!"); } } + +void Dependency::EvaluateApplyRules(const std::vector& rules) +{ + ParallelWorkQueue upq; + + BOOST_FOREACH(const ApplyRule& rule, rules) { + upq.Enqueue(boost::bind(&Dependency::EvaluateApplyRule, boost::cref(rule))); + } + + upq.Join(); +} diff --git a/lib/icinga/dependency.h b/lib/icinga/dependency.h index 7cd2f159a..210d8c2e9 100644 --- a/lib/icinga/dependency.h +++ b/lib/icinga/dependency.h @@ -57,7 +57,8 @@ protected: virtual void Stop(void); private: - static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule); + static bool EvaluateApplyRuleOne(const Checkable::Ptr& checkable, const ApplyRule& rule); + static void EvaluateApplyRule(const ApplyRule& rule); static void EvaluateApplyRules(const std::vector& rules); }; diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index 71faecb6c..cada9e887 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -23,6 +23,7 @@ #include "base/logger_fwd.h" #include "base/objectlock.h" #include "base/context.h" +#include "base/workqueue.h" #include using namespace icinga; @@ -36,7 +37,7 @@ void HostGroup::RegisterObjectRuleHandler(void) ObjectRule::RegisterType("HostGroup", &HostGroup::EvaluateObjectRules); } -bool HostGroup::EvaluateObjectRule(const Host::Ptr host, const ObjectRule& rule) +bool HostGroup::EvaluateObjectRuleOne(const Host::Ptr host, const ObjectRule& rule) { DebugInfo di = rule.GetDebugInfo(); @@ -71,15 +72,24 @@ bool HostGroup::EvaluateObjectRule(const Host::Ptr host, const ObjectRule& rule) return true; } +void HostGroup::EvaluateObjectRule(const ObjectRule& rule) +{ + BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects()) { + CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for host '" + host->GetName() + "'"); + + EvaluateObjectRuleOne(host, rule); + } +} + void HostGroup::EvaluateObjectRules(const std::vector& rules) { - BOOST_FOREACH(const ObjectRule& rule, rules) { - BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects()) { - CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for host '" + host->GetName() + "'"); + ParallelWorkQueue upq; - EvaluateObjectRule(host, rule); - } + BOOST_FOREACH(const ObjectRule& rule, rules) { + upq.Enqueue(boost::bind(HostGroup::EvaluateObjectRule, boost::cref(rule))); } + + upq.Join(); } std::set HostGroup::GetMembers(void) const diff --git a/lib/icinga/hostgroup.h b/lib/icinga/hostgroup.h index 453150971..0c7ea97fd 100644 --- a/lib/icinga/hostgroup.h +++ b/lib/icinga/hostgroup.h @@ -52,7 +52,8 @@ private: mutable boost::mutex m_HostGroupMutex; std::set m_Members; - static bool EvaluateObjectRule(const Host::Ptr host, const ObjectRule& rule); + static bool EvaluateObjectRuleOne(const Host::Ptr host, const ObjectRule& rule); + static void EvaluateObjectRule(const ObjectRule& rule); static void EvaluateObjectRules(const std::vector& rules); }; diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index 28b487851..317b8c0cd 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -25,6 +25,7 @@ #include "base/dynamictype.h" #include "base/logger_fwd.h" #include "base/context.h" +#include "base/workqueue.h" #include using namespace icinga; @@ -39,7 +40,7 @@ void Notification::RegisterApplyRuleHandler(void) ApplyRule::RegisterType("Notification", targets, &Notification::EvaluateApplyRules); } -bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule) +bool Notification::EvaluateApplyRuleOne(const Checkable::Ptr& checkable, const ApplyRule& rule) { DebugInfo di = rule.GetDebugInfo(); @@ -99,39 +100,47 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl return true; } -void Notification::EvaluateApplyRules(const std::vector& rules) +void Notification::EvaluateApplyRule(const ApplyRule& rule) { int apply_count = 0; - BOOST_FOREACH(const ApplyRule& rule, rules) { - if (rule.GetTargetType() == "Host") { - apply_count = 0; + if (rule.GetTargetType() == "Host") { + apply_count = 0; - BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects()) { - CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); + BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects()) { + CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); - if (EvaluateApplyRule(host, rule)) - apply_count++; - } - - if (apply_count == 0) - Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!"); - - } else if (rule.GetTargetType() == "Service") { - apply_count = 0; - - BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { - CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'"); - - if(EvaluateApplyRule(service, rule)) - apply_count++; - } - - if (apply_count == 0) - Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for service does not match anywhere!"); - - } else { - Log(LogWarning, "icinga", "Wrong target type for apply rule '" + rule.GetName() + "'!"); + if (EvaluateApplyRuleOne(host, rule)) + apply_count++; } + + if (apply_count == 0) + Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!"); + + } else if (rule.GetTargetType() == "Service") { + apply_count = 0; + + BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { + CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'"); + + if (EvaluateApplyRuleOne(service, rule)) + apply_count++; + } + + if (apply_count == 0) + Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for service does not match anywhere!"); + + } else { + Log(LogWarning, "icinga", "Wrong target type for apply rule '" + rule.GetName() + "'!"); } } +void Notification::EvaluateApplyRules(const std::vector& rules) +{ + ParallelWorkQueue upq; + + BOOST_FOREACH(const ApplyRule& rule, rules) { + upq.Enqueue(boost::bind(&Notification::EvaluateApplyRule, boost::cref(rule))); + } + + upq.Join(); +} diff --git a/lib/icinga/notification.h b/lib/icinga/notification.h index ead05ef67..58db371b6 100644 --- a/lib/icinga/notification.h +++ b/lib/icinga/notification.h @@ -113,7 +113,8 @@ protected: private: void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = ""); - static bool EvaluateApplyRule(const shared_ptr& checkable, const ApplyRule& rule); + static bool EvaluateApplyRuleOne(const shared_ptr& checkable, const ApplyRule& rule); + static void EvaluateApplyRule(const ApplyRule& rule); static void EvaluateApplyRules(const std::vector& rules); }; diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 1892a0929..6a4f4569c 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -24,6 +24,7 @@ #include "base/dynamictype.h" #include "base/logger_fwd.h" #include "base/context.h" +#include "base/workqueue.h" #include using namespace icinga; @@ -37,7 +38,7 @@ void Service::RegisterApplyRuleHandler(void) ApplyRule::RegisterType("Service", targets, &Service::EvaluateApplyRules); } -bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule) +bool Service::EvaluateApplyRuleOne(const Host::Ptr& host, const ApplyRule& rule) { DebugInfo di = rule.GetDebugInfo(); @@ -89,21 +90,28 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule) return true; } -void Service::EvaluateApplyRules(const std::vector& rules) +void Service::EvaluateApplyRule(const ApplyRule& rule) { int apply_count = 0; - BOOST_FOREACH(const ApplyRule& rule, rules) { - apply_count = 0; + BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects()) { + CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); - BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects()) { - CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); - - if (EvaluateApplyRule(host, rule)) - apply_count++; - } - - if (apply_count == 0) - Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!"); + if (EvaluateApplyRuleOne(host, rule)) + apply_count++; } + + if (apply_count == 0) + Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!"); +} + +void Service::EvaluateApplyRules(const std::vector& rules) +{ + ParallelWorkQueue upq; + + BOOST_FOREACH(const ApplyRule& rule, rules) { + upq.Enqueue(boost::bind(&Service::EvaluateApplyRule, boost::cref(rule))); + } + + upq.Join(); } diff --git a/lib/icinga/service.h b/lib/icinga/service.h index f536de0b2..735615001 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -59,7 +59,8 @@ protected: private: Host::Ptr m_Host; - static bool EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule); + static bool EvaluateApplyRuleOne(const Host::Ptr& host, const ApplyRule& rule); + static void EvaluateApplyRule(const ApplyRule& rule); static void EvaluateApplyRules(const std::vector& rules); }; diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index 68b1276da..e1fd62c5a 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -23,6 +23,7 @@ #include "base/objectlock.h" #include "base/logger_fwd.h" #include "base/context.h" +#include "base/workqueue.h" #include using namespace icinga; @@ -36,7 +37,7 @@ void ServiceGroup::RegisterObjectRuleHandler(void) ObjectRule::RegisterType("ServiceGroup", &ServiceGroup::EvaluateObjectRules); } -bool ServiceGroup::EvaluateObjectRule(const Service::Ptr service, const ObjectRule& rule) +bool ServiceGroup::EvaluateObjectRuleOne(const Service::Ptr service, const ObjectRule& rule) { DebugInfo di = rule.GetDebugInfo(); @@ -74,15 +75,24 @@ bool ServiceGroup::EvaluateObjectRule(const Service::Ptr service, const ObjectRu return true; } +void ServiceGroup::EvaluateObjectRule(const ObjectRule& rule) +{ + BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { + CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for service '" + service->GetName() + "'"); + + EvaluateObjectRuleOne(service, rule); + } +} + void ServiceGroup::EvaluateObjectRules(const std::vector& rules) { - BOOST_FOREACH(const ObjectRule& rule, rules) { - BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { - CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for service '" + service->GetName() + "'"); + ParallelWorkQueue upq; - EvaluateObjectRule(service, rule); - } + BOOST_FOREACH(const ObjectRule& rule, rules) { + upq.Enqueue(boost::bind(ServiceGroup::EvaluateObjectRule, boost::cref(rule))); } + + upq.Join(); } std::set ServiceGroup::GetMembers(void) const diff --git a/lib/icinga/servicegroup.h b/lib/icinga/servicegroup.h index 190517c40..82c7d5632 100644 --- a/lib/icinga/servicegroup.h +++ b/lib/icinga/servicegroup.h @@ -52,7 +52,8 @@ private: mutable boost::mutex m_ServiceGroupMutex; std::set m_Members; - static bool EvaluateObjectRule(const Service::Ptr service, const ObjectRule& rule); + static bool EvaluateObjectRuleOne(const Service::Ptr service, const ObjectRule& rule); + static void EvaluateObjectRule(const ObjectRule& rule); static void EvaluateObjectRules(const std::vector& rules); }; diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index c8780010f..c5d31dac7 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -23,6 +23,7 @@ #include "base/objectlock.h" #include "base/logger_fwd.h" #include "base/context.h" +#include "base/workqueue.h" #include using namespace icinga; @@ -36,7 +37,7 @@ void UserGroup::RegisterObjectRuleHandler(void) ObjectRule::RegisterType("UserGroup", &UserGroup::EvaluateObjectRules); } -bool UserGroup::EvaluateObjectRule(const User::Ptr user, const ObjectRule& rule) +bool UserGroup::EvaluateObjectRuleOne(const User::Ptr user, const ObjectRule& rule) { DebugInfo di = rule.GetDebugInfo(); @@ -71,15 +72,24 @@ bool UserGroup::EvaluateObjectRule(const User::Ptr user, const ObjectRule& rule) return true; } +void UserGroup::EvaluateObjectRule(const ObjectRule& rule) +{ + BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects()) { + CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for user '" + user->GetName() + "'"); + + EvaluateObjectRuleOne(user, rule); + } +} + void UserGroup::EvaluateObjectRules(const std::vector& rules) { - BOOST_FOREACH(const ObjectRule& rule, rules) { - BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects()) { - CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for user '" + user->GetName() + "'"); + ParallelWorkQueue upq; - EvaluateObjectRule(user, rule); - } + BOOST_FOREACH(const ObjectRule& rule, rules) { + upq.Enqueue(boost::bind(UserGroup::EvaluateObjectRule, boost::cref(rule))); } + + upq.Join(); } std::set UserGroup::GetMembers(void) const diff --git a/lib/icinga/usergroup.h b/lib/icinga/usergroup.h index ecb319cb9..96a4aabf8 100644 --- a/lib/icinga/usergroup.h +++ b/lib/icinga/usergroup.h @@ -52,7 +52,8 @@ private: mutable boost::mutex m_UserGroupMutex; std::set m_Members; - static bool EvaluateObjectRule(const User::Ptr user, const ObjectRule& rule); + static bool EvaluateObjectRuleOne(const User::Ptr user, const ObjectRule& rule); + static void EvaluateObjectRule(const ObjectRule& rule); static void EvaluateObjectRules(const std::vector& rules); };