mirror of https://github.com/Icinga/icinga2.git
parent
bbb2fb62dd
commit
f26b37e763
|
@ -25,6 +25,7 @@
|
|||
#include "base/dynamictype.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include "base/context.h"
|
||||
#include "base/workqueue.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
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<ApplyRule>& 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<Host>()) {
|
||||
CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
|
||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||
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<Service>()) {
|
||||
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<Service>()) {
|
||||
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<ApplyRule>& rules)
|
||||
{
|
||||
ParallelWorkQueue upq;
|
||||
|
||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
||||
upq.Enqueue(boost::bind(&Dependency::EvaluateApplyRule, boost::cref(rule)));
|
||||
}
|
||||
|
||||
upq.Join();
|
||||
}
|
||||
|
|
|
@ -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<ApplyRule>& rules);
|
||||
};
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "base/logger_fwd.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/context.h"
|
||||
#include "base/workqueue.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
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<Host>()) {
|
||||
CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for host '" + host->GetName() + "'");
|
||||
|
||||
EvaluateObjectRuleOne(host, rule);
|
||||
}
|
||||
}
|
||||
|
||||
void HostGroup::EvaluateObjectRules(const std::vector<ObjectRule>& rules)
|
||||
{
|
||||
BOOST_FOREACH(const ObjectRule& rule, rules) {
|
||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||
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<Host::Ptr> HostGroup::GetMembers(void) const
|
||||
|
|
|
@ -52,7 +52,8 @@ private:
|
|||
mutable boost::mutex m_HostGroupMutex;
|
||||
std::set<Host::Ptr> 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<ObjectRule>& rules);
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "base/dynamictype.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include "base/context.h"
|
||||
#include "base/workqueue.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
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<ApplyRule>& 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<Host>()) {
|
||||
CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
|
||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||
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<Service>()) {
|
||||
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<Service>()) {
|
||||
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<ApplyRule>& rules)
|
||||
{
|
||||
ParallelWorkQueue upq;
|
||||
|
||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
||||
upq.Enqueue(boost::bind(&Notification::EvaluateApplyRule, boost::cref(rule)));
|
||||
}
|
||||
|
||||
upq.Join();
|
||||
}
|
||||
|
|
|
@ -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>& checkable, const ApplyRule& rule);
|
||||
static bool EvaluateApplyRuleOne(const shared_ptr<Checkable>& checkable, const ApplyRule& rule);
|
||||
static void EvaluateApplyRule(const ApplyRule& rule);
|
||||
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
|
||||
};
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "base/dynamictype.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include "base/context.h"
|
||||
#include "base/workqueue.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
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<ApplyRule>& 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<Host>()) {
|
||||
CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
|
||||
|
||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||
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<ApplyRule>& rules)
|
||||
{
|
||||
ParallelWorkQueue upq;
|
||||
|
||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
||||
upq.Enqueue(boost::bind(&Service::EvaluateApplyRule, boost::cref(rule)));
|
||||
}
|
||||
|
||||
upq.Join();
|
||||
}
|
||||
|
|
|
@ -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<ApplyRule>& rules);
|
||||
};
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "base/objectlock.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include "base/context.h"
|
||||
#include "base/workqueue.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
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<Service>()) {
|
||||
CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for service '" + service->GetName() + "'");
|
||||
|
||||
EvaluateObjectRuleOne(service, rule);
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceGroup::EvaluateObjectRules(const std::vector<ObjectRule>& rules)
|
||||
{
|
||||
BOOST_FOREACH(const ObjectRule& rule, rules) {
|
||||
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
|
||||
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<Service::Ptr> ServiceGroup::GetMembers(void) const
|
||||
|
|
|
@ -52,7 +52,8 @@ private:
|
|||
mutable boost::mutex m_ServiceGroupMutex;
|
||||
std::set<Service::Ptr> 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<ObjectRule>& rules);
|
||||
};
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "base/objectlock.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include "base/context.h"
|
||||
#include "base/workqueue.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
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<User>()) {
|
||||
CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for user '" + user->GetName() + "'");
|
||||
|
||||
EvaluateObjectRuleOne(user, rule);
|
||||
}
|
||||
}
|
||||
|
||||
void UserGroup::EvaluateObjectRules(const std::vector<ObjectRule>& rules)
|
||||
{
|
||||
BOOST_FOREACH(const ObjectRule& rule, rules) {
|
||||
BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects<User>()) {
|
||||
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<User::Ptr> UserGroup::GetMembers(void) const
|
||||
|
|
|
@ -52,7 +52,8 @@ private:
|
|||
mutable boost::mutex m_UserGroupMutex;
|
||||
std::set<User::Ptr> 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<ObjectRule>& rules);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue