}
}
+ if (cont)
+ continue;
+
completedTypes.insert(sourceType);
RuleMap::const_iterator it = m_Rules.find(kv.first);
ApplyRule::RegisterType("Dependency", targets, &Dependency::EvaluateApplyRules);
}
-void Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
+bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
{
DebugInfo di = rule.GetDebugInfo();
locals->Set("service", service);
if (!rule.EvaluateFilter(locals))
- return;
+ return false;
std::ostringstream msgbuf2;
msgbuf2 << "Applying dependency '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
make_shared<AExpression>(&AExpression::OpLiteral, "child_host_name", di),
- make_shared<AExpression>(&AExpression::OpLiteral, host->GetName(),
- di), di));
+ make_shared<AExpression>(&AExpression::OpLiteral, host->GetName(), di),
+ di));
if (service) {
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
make_shared<AExpression>(&AExpression::OpLiteral, "child_service_name", di),
- make_shared<AExpression>(&AExpression::OpLiteral, service->GetShortName(), di), di));
+ make_shared<AExpression>(&AExpression::OpLiteral, service->GetShortName(), di),
+ di));
}
builder->AddExpression(rule.GetExpression());
dependencyItem->Register();
DynamicObject::Ptr dobj = dependencyItem->Commit();
dobj->OnConfigLoaded();
+
+ return true;
}
void Dependency::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
{
- BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
- CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
+ int apply_count = 0;
- BOOST_FOREACH(const ApplyRule& rule, rules) {
- if (rule.GetTargetType() != "Host")
- continue;
+ BOOST_FOREACH(const ApplyRule& rule, rules) {
+ if (rule.GetTargetType() == "Host") {
+ apply_count = 0;
- EvaluateApplyRule(host, rule);
- }
- }
+ 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() + "'");
- BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
- CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'");
+ if(EvaluateApplyRule(service, rule))
+ apply_count++;
+ }
- BOOST_FOREACH(const ApplyRule& rule, rules) {
- if (rule.GetTargetType() != "Service")
- continue;
+ if (apply_count == 0)
+ Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for service does not match anywhere!");
- EvaluateApplyRule(service, rule);
+ } else {
+ Log(LogWarning, "icinga", "Wrong target type for apply rule '" + rule.GetName() + "'!");
}
}
}
virtual void Stop(void);
private:
- static void EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule);
+ static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule);
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
};
ApplyRule::RegisterType("Notification", targets, &Notification::EvaluateApplyRules);
}
-void Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
+bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
{
DebugInfo di = rule.GetDebugInfo();
locals->Set("service", service);
if (!rule.EvaluateFilter(locals))
- return;
+ return false;
std::ostringstream msgbuf2;
msgbuf2 << "Applying notification '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
notificationItem->Register();
DynamicObject::Ptr dobj = notificationItem->Commit();
dobj->OnConfigLoaded();
+
+ return true;
}
void Notification::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
{
- BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
- CONTEXT("Evaluating 'apply' rules for Host '" + host->GetName() + "'");
+ int apply_count = 0;
- BOOST_FOREACH(const ApplyRule& rule, rules) {
- if (rule.GetTargetType() != "Host")
- continue;
+ BOOST_FOREACH(const ApplyRule& rule, rules) {
+ if (rule.GetTargetType() == "Host") {
+ apply_count = 0;
- EvaluateApplyRule(host, rule);
- }
- }
+ 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() + "'");
- BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
- CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'");
+ if(EvaluateApplyRule(service, rule))
+ apply_count++;
+ }
- BOOST_FOREACH(const ApplyRule& rule, rules) {
- if (rule.GetTargetType() != "Service")
- continue;
+ if (apply_count == 0)
+ Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for service does not match anywhere!");
- EvaluateApplyRule(service, rule);
+ } else {
+ Log(LogWarning, "icinga", "Wrong target type for apply rule '" + rule.GetName() + "'!");
}
}
}
private:
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
- static void EvaluateApplyRule(const shared_ptr<Checkable>& checkable, const ApplyRule& rule);
+ static bool EvaluateApplyRule(const shared_ptr<Checkable>& checkable, const ApplyRule& rule);
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
};
ApplyRule::RegisterType("ScheduledDowntime", targets, &ScheduledDowntime::EvaluateApplyRules);
}
-void ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
+bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
{
DebugInfo di = rule.GetDebugInfo();
locals->Set("service", service);
if (!rule.EvaluateFilter(locals))
- return;
+ return false;
std::ostringstream msgbuf2;
msgbuf2 << "Applying scheduled downtime '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
Log(LogDebug, "icinga", msgbuf2.str());
- std::ostringstream namebuf;
- namebuf << checkable->GetName() << "!" << rule.GetName();
- String name = namebuf.str();
-
ConfigItemBuilder::Ptr builder = make_shared<ConfigItemBuilder>(di);
builder->SetType("ScheduledDowntime");
- builder->SetName(name);
+ builder->SetName(rule.GetName());
builder->SetScope(rule.GetScope());
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
downtimeItem->Register();
DynamicObject::Ptr dobj = downtimeItem->Commit();
dobj->OnConfigLoaded();
+
+ return true;
}
void ScheduledDowntime::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
{
- BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
- CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
+ int apply_count = 0;
- BOOST_FOREACH(const ApplyRule& rule, rules) {
- if (rule.GetTargetType() != "Host")
- continue;
+ BOOST_FOREACH(const ApplyRule& rule, rules) {
+ if (rule.GetTargetType() == "Host") {
+ apply_count = 0;
- EvaluateApplyRule(host, rule);
- }
- }
+ 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() + "'");
- BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
- CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'");
+ if(EvaluateApplyRule(service, rule))
+ apply_count++;
+ }
- BOOST_FOREACH(const ApplyRule& rule, rules) {
- if (rule.GetTargetType() != "Service")
- continue;
+ if (apply_count == 0)
+ Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for service does not match anywhere!");
- EvaluateApplyRule(service, rule);
+ } else {
+ Log(LogWarning, "icinga", "Wrong target type for apply rule '" + rule.GetName() + "'!");
}
}
}
std::pair<double, double> FindNextSegment(void);
void CreateNextDowntime(void);
- static void EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule);
+ static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule);
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
};
ApplyRule::RegisterType("Service", targets, &Service::EvaluateApplyRules);
}
-void Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
+bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
{
DebugInfo di = rule.GetDebugInfo();
locals->Set("host", host);
if (!rule.EvaluateFilter(locals))
- return;
+ return false;
std::ostringstream msgbuf2;
msgbuf2 << "Applying service '" << rule.GetName() << "' to host '" << host->GetName() << "' for rule " << di;
serviceItem->Register();
DynamicObject::Ptr dobj = serviceItem->Commit();
dobj->OnConfigLoaded();
+
+ return true;
}
void Service::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
{
- BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
- CONTEXT("Evaluating 'apply' rules for Host '" + host->GetName() + "'");
+ 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() + "'");
+
+ if (EvaluateApplyRule(host, rule))
+ apply_count++;
+ }
- BOOST_FOREACH(const ApplyRule& rule, rules)
- EvaluateApplyRule(host, rule);
+ if (apply_count == 0)
+ Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!");
}
}
private:
Host::Ptr m_Host;
- static void EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule);
+ static bool EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule);
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
};