From 5962330b27df2c20c3de6665f0fc7fd38a5eff09 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 10 Oct 2014 11:39:03 +0200 Subject: [PATCH] Improve error messages for apply rules refs #6070 --- lib/icinga/dependency-apply.cpp | 20 ++++++++++++++++---- lib/icinga/notification-apply.cpp | 20 ++++++++++++++++---- lib/icinga/scheduleddowntime-apply.cpp | 20 ++++++++++++++++---- lib/icinga/service-apply.cpp | 11 +++++++++-- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 27d74f04a..f577f94eb 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -21,11 +21,13 @@ #include "icinga/service.hpp" #include "config/configitembuilder.hpp" #include "config/applyrule.hpp" +#include "config/configcompilercontext.hpp" #include "base/initialize.hpp" #include "base/dynamictype.hpp" #include "base/logger_fwd.hpp" #include "base/context.hpp" #include "base/workqueue.hpp" +#include "base/configerror.hpp" #include using namespace icinga; @@ -115,8 +117,13 @@ void Dependency::EvaluateApplyRule(const ApplyRule& rule) BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType()) { CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); - if (EvaluateApplyRuleOne(host, rule)) - apply_count++; + try { + if (EvaluateApplyRuleOne(host, rule)) + apply_count++; + } catch (const ConfigError& ex) { + const DebugInfo *di = boost::get_error_info(ex); + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } } if (apply_count == 0) @@ -128,8 +135,13 @@ void Dependency::EvaluateApplyRule(const ApplyRule& rule) BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjectsByType()) { CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'"); - if (EvaluateApplyRuleOne(service, rule)) - apply_count++; + try { + if (EvaluateApplyRuleOne(service, rule)) + apply_count++; + } catch (const ConfigError& ex) { + const DebugInfo *di = boost::get_error_info(ex); + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } } if (apply_count == 0) diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index 57d9c37bd..9798c355d 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -21,11 +21,13 @@ #include "icinga/service.hpp" #include "config/configitembuilder.hpp" #include "config/applyrule.hpp" +#include "config/configcompilercontext.hpp" #include "base/initialize.hpp" #include "base/dynamictype.hpp" #include "base/logger_fwd.hpp" #include "base/context.hpp" #include "base/workqueue.hpp" +#include "base/configerror.hpp" #include using namespace icinga; @@ -110,8 +112,13 @@ void Notification::EvaluateApplyRule(const ApplyRule& rule) BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType()) { CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); - if (EvaluateApplyRuleOne(host, rule)) - apply_count++; + try { + if (EvaluateApplyRuleOne(host, rule)) + apply_count++; + } catch (const ConfigError& ex) { + const DebugInfo *di = boost::get_error_info(ex); + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } } if (apply_count == 0) @@ -123,8 +130,13 @@ void Notification::EvaluateApplyRule(const ApplyRule& rule) BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjectsByType()) { CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'"); - if (EvaluateApplyRuleOne(service, rule)) - apply_count++; + try { + if (EvaluateApplyRuleOne(service, rule)) + apply_count++; + } catch (const ConfigError& ex) { + const DebugInfo *di = boost::get_error_info(ex); + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } } if (apply_count == 0) diff --git a/lib/icinga/scheduleddowntime-apply.cpp b/lib/icinga/scheduleddowntime-apply.cpp index 778f29833..bcb61e4aa 100644 --- a/lib/icinga/scheduleddowntime-apply.cpp +++ b/lib/icinga/scheduleddowntime-apply.cpp @@ -21,10 +21,12 @@ #include "icinga/service.hpp" #include "config/configitembuilder.hpp" #include "config/applyrule.hpp" +#include "config/configcompilercontext.hpp" #include "base/initialize.hpp" #include "base/dynamictype.hpp" #include "base/logger_fwd.hpp" #include "base/context.hpp" +#include "base/configerror.hpp" #include using namespace icinga; @@ -110,8 +112,13 @@ void ScheduledDowntime::EvaluateApplyRules(const std::vector& rules) BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType()) { CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); - if (EvaluateApplyRule(host, rule)) - apply_count++; + try { + if (EvaluateApplyRule(host, rule)) + apply_count++; + } catch (const ConfigError& ex) { + const DebugInfo *di = boost::get_error_info(ex); + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } } if (apply_count == 0) @@ -123,8 +130,13 @@ void ScheduledDowntime::EvaluateApplyRules(const std::vector& rules) BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjectsByType()) { CONTEXT("Evaluating 'apply' rules for Service '" + service->GetName() + "'"); - if(EvaluateApplyRule(service, rule)) - apply_count++; + try { + if(EvaluateApplyRule(service, rule)) + apply_count++; + } catch (const ConfigError& ex) { + const DebugInfo *di = boost::get_error_info(ex); + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } } if (apply_count == 0) diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 65bc83faa..c3c367c38 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -20,11 +20,13 @@ #include "icinga/service.hpp" #include "config/configitembuilder.hpp" #include "config/applyrule.hpp" +#include "config/configcompilercontext.hpp" #include "base/initialize.hpp" #include "base/dynamictype.hpp" #include "base/logger_fwd.hpp" #include "base/context.hpp" #include "base/workqueue.hpp" +#include "base/configerror.hpp" #include using namespace icinga; @@ -97,8 +99,13 @@ void Service::EvaluateApplyRule(const ApplyRule& rule) BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType()) { CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); - if (EvaluateApplyRuleOne(host, rule)) - apply_count++; + try { + if (EvaluateApplyRuleOne(host, rule)) + apply_count++; + } catch (const ConfigError& ex) { + const DebugInfo *di = boost::get_error_info(ex); + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } } if (apply_count == 0)