mirror of https://github.com/Icinga/icinga2.git
Log warning if apply rule does not match anywhere.
Fixes #5911 Fixes #5957
This commit is contained in:
parent
fded50632e
commit
aae5f092d4
|
@ -99,6 +99,9 @@ void ApplyRule::EvaluateRules(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cont)
|
||||||
|
continue;
|
||||||
|
|
||||||
completedTypes.insert(sourceType);
|
completedTypes.insert(sourceType);
|
||||||
|
|
||||||
RuleMap::const_iterator it = m_Rules.find(kv.first);
|
RuleMap::const_iterator it = m_Rules.find(kv.first);
|
||||||
|
|
|
@ -39,7 +39,7 @@ void Dependency::RegisterApplyRuleHandler(void)
|
||||||
ApplyRule::RegisterType("Dependency", targets, &Dependency::EvaluateApplyRules);
|
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();
|
DebugInfo di = rule.GetDebugInfo();
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ void Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
|
||||||
locals->Set("service", service);
|
locals->Set("service", service);
|
||||||
|
|
||||||
if (!rule.EvaluateFilter(locals))
|
if (!rule.EvaluateFilter(locals))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
std::ostringstream msgbuf2;
|
std::ostringstream msgbuf2;
|
||||||
msgbuf2 << "Applying dependency '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
|
msgbuf2 << "Applying dependency '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
|
||||||
|
@ -70,13 +70,14 @@ void Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
|
||||||
|
|
||||||
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
|
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
|
||||||
make_shared<AExpression>(&AExpression::OpLiteral, "child_host_name", di),
|
make_shared<AExpression>(&AExpression::OpLiteral, "child_host_name", di),
|
||||||
make_shared<AExpression>(&AExpression::OpLiteral, host->GetName(),
|
make_shared<AExpression>(&AExpression::OpLiteral, host->GetName(), di),
|
||||||
di), di));
|
di));
|
||||||
|
|
||||||
if (service) {
|
if (service) {
|
||||||
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
|
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
|
||||||
make_shared<AExpression>(&AExpression::OpLiteral, "child_service_name", di),
|
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());
|
builder->AddExpression(rule.GetExpression());
|
||||||
|
@ -85,29 +86,43 @@ void Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
|
||||||
dependencyItem->Register();
|
dependencyItem->Register();
|
||||||
DynamicObject::Ptr dobj = dependencyItem->Commit();
|
DynamicObject::Ptr dobj = dependencyItem->Commit();
|
||||||
dobj->OnConfigLoaded();
|
dobj->OnConfigLoaded();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dependency::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
void Dependency::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
int apply_count = 0;
|
||||||
CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
|
|
||||||
|
|
||||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
||||||
if (rule.GetTargetType() != "Host")
|
if (rule.GetTargetType() == "Host") {
|
||||||
continue;
|
apply_count = 0;
|
||||||
|
|
||||||
EvaluateApplyRule(host, rule);
|
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||||
}
|
CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
|
if (EvaluateApplyRule(host, rule))
|
||||||
CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'");
|
apply_count++;
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
if (apply_count == 0)
|
||||||
if (rule.GetTargetType() != "Service")
|
Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!");
|
||||||
continue;
|
|
||||||
|
|
||||||
EvaluateApplyRule(service, rule);
|
} 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() + "'!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ protected:
|
||||||
virtual void Stop(void);
|
virtual void Stop(void);
|
||||||
|
|
||||||
private:
|
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);
|
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ void Notification::RegisterApplyRuleHandler(void)
|
||||||
ApplyRule::RegisterType("Notification", targets, &Notification::EvaluateApplyRules);
|
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();
|
DebugInfo di = rule.GetDebugInfo();
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ void Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
|
||||||
locals->Set("service", service);
|
locals->Set("service", service);
|
||||||
|
|
||||||
if (!rule.EvaluateFilter(locals))
|
if (!rule.EvaluateFilter(locals))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
std::ostringstream msgbuf2;
|
std::ostringstream msgbuf2;
|
||||||
msgbuf2 << "Applying notification '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
|
msgbuf2 << "Applying notification '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
|
||||||
|
@ -85,29 +85,43 @@ void Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
|
||||||
notificationItem->Register();
|
notificationItem->Register();
|
||||||
DynamicObject::Ptr dobj = notificationItem->Commit();
|
DynamicObject::Ptr dobj = notificationItem->Commit();
|
||||||
dobj->OnConfigLoaded();
|
dobj->OnConfigLoaded();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
void Notification::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
int apply_count = 0;
|
||||||
CONTEXT("Evaluating 'apply' rules for Host '" + host->GetName() + "'");
|
|
||||||
|
|
||||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
||||||
if (rule.GetTargetType() != "Host")
|
if (rule.GetTargetType() == "Host") {
|
||||||
continue;
|
apply_count = 0;
|
||||||
|
|
||||||
EvaluateApplyRule(host, rule);
|
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||||
}
|
CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
|
if (EvaluateApplyRule(host, rule))
|
||||||
CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'");
|
apply_count++;
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
if (apply_count == 0)
|
||||||
if (rule.GetTargetType() != "Service")
|
Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!");
|
||||||
continue;
|
|
||||||
|
|
||||||
EvaluateApplyRule(service, rule);
|
} 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() + "'!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ protected:
|
||||||
private:
|
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 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);
|
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ void ScheduledDowntime::RegisterApplyRuleHandler(void)
|
||||||
ApplyRule::RegisterType("ScheduledDowntime", targets, &ScheduledDowntime::EvaluateApplyRules);
|
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();
|
DebugInfo di = rule.GetDebugInfo();
|
||||||
|
|
||||||
|
@ -56,19 +56,15 @@ void ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
|
||||||
locals->Set("service", service);
|
locals->Set("service", service);
|
||||||
|
|
||||||
if (!rule.EvaluateFilter(locals))
|
if (!rule.EvaluateFilter(locals))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
std::ostringstream msgbuf2;
|
std::ostringstream msgbuf2;
|
||||||
msgbuf2 << "Applying scheduled downtime '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
|
msgbuf2 << "Applying scheduled downtime '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
|
||||||
Log(LogDebug, "icinga", msgbuf2.str());
|
Log(LogDebug, "icinga", msgbuf2.str());
|
||||||
|
|
||||||
std::ostringstream namebuf;
|
|
||||||
namebuf << checkable->GetName() << "!" << rule.GetName();
|
|
||||||
String name = namebuf.str();
|
|
||||||
|
|
||||||
ConfigItemBuilder::Ptr builder = make_shared<ConfigItemBuilder>(di);
|
ConfigItemBuilder::Ptr builder = make_shared<ConfigItemBuilder>(di);
|
||||||
builder->SetType("ScheduledDowntime");
|
builder->SetType("ScheduledDowntime");
|
||||||
builder->SetName(name);
|
builder->SetName(rule.GetName());
|
||||||
builder->SetScope(rule.GetScope());
|
builder->SetScope(rule.GetScope());
|
||||||
|
|
||||||
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
|
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
|
||||||
|
@ -89,29 +85,43 @@ void ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
|
||||||
downtimeItem->Register();
|
downtimeItem->Register();
|
||||||
DynamicObject::Ptr dobj = downtimeItem->Commit();
|
DynamicObject::Ptr dobj = downtimeItem->Commit();
|
||||||
dobj->OnConfigLoaded();
|
dobj->OnConfigLoaded();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScheduledDowntime::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
void ScheduledDowntime::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
int apply_count = 0;
|
||||||
CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
|
|
||||||
|
|
||||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
||||||
if (rule.GetTargetType() != "Host")
|
if (rule.GetTargetType() == "Host") {
|
||||||
continue;
|
apply_count = 0;
|
||||||
|
|
||||||
EvaluateApplyRule(host, rule);
|
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||||
}
|
CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'");
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
|
if (EvaluateApplyRule(host, rule))
|
||||||
CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'");
|
apply_count++;
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
if (apply_count == 0)
|
||||||
if (rule.GetTargetType() != "Service")
|
Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!");
|
||||||
continue;
|
|
||||||
|
|
||||||
EvaluateApplyRule(service, rule);
|
} 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() + "'!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ private:
|
||||||
std::pair<double, double> FindNextSegment(void);
|
std::pair<double, double> FindNextSegment(void);
|
||||||
void CreateNextDowntime(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);
|
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ void Service::RegisterApplyRuleHandler(void)
|
||||||
ApplyRule::RegisterType("Service", targets, &Service::EvaluateApplyRules);
|
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();
|
DebugInfo di = rule.GetDebugInfo();
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ void Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
|
||||||
locals->Set("host", host);
|
locals->Set("host", host);
|
||||||
|
|
||||||
if (!rule.EvaluateFilter(locals))
|
if (!rule.EvaluateFilter(locals))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
std::ostringstream msgbuf2;
|
std::ostringstream msgbuf2;
|
||||||
msgbuf2 << "Applying service '" << rule.GetName() << "' to host '" << host->GetName() << "' for rule " << di;
|
msgbuf2 << "Applying service '" << rule.GetName() << "' to host '" << host->GetName() << "' for rule " << di;
|
||||||
|
@ -76,14 +76,25 @@ void Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
|
||||||
serviceItem->Register();
|
serviceItem->Register();
|
||||||
DynamicObject::Ptr dobj = serviceItem->Commit();
|
DynamicObject::Ptr dobj = serviceItem->Commit();
|
||||||
dobj->OnConfigLoaded();
|
dobj->OnConfigLoaded();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
void Service::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
int apply_count = 0;
|
||||||
CONTEXT("Evaluating 'apply' rules for Host '" + host->GetName() + "'");
|
|
||||||
|
|
||||||
BOOST_FOREACH(const ApplyRule& rule, rules)
|
BOOST_FOREACH(const ApplyRule& rule, rules) {
|
||||||
EvaluateApplyRule(host, rule);
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apply_count == 0)
|
||||||
|
Log(LogWarning, "icinga", "Apply rule '" + rule.GetName() + "' for host does not match anywhere!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
Host::Ptr m_Host;
|
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);
|
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue