mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +02:00
parent
abe583f7d9
commit
764d72a61a
@ -62,14 +62,28 @@ static String LoadAppType(const String& typeSpec)
|
|||||||
return typeSpec.SubStr(index + 1);
|
return typeSpec.SubStr(index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ExecuteExpression(Expression *expression)
|
||||||
|
{
|
||||||
|
Dictionary::Ptr context = new Dictionary();
|
||||||
|
|
||||||
|
try {
|
||||||
|
expression->Evaluate(context);
|
||||||
|
} catch (const ConfigError& ex) {
|
||||||
|
const DebugInfo *di = boost::get_error_info<errinfo_debuginfo>(ex);
|
||||||
|
ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo());
|
||||||
|
} catch (const std::exception& ex) {
|
||||||
|
ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void IncludeZoneDirRecursive(const String& path)
|
static void IncludeZoneDirRecursive(const String& path)
|
||||||
{
|
{
|
||||||
String zoneName = Utility::BaseName(path);
|
String zoneName = Utility::BaseName(path);
|
||||||
|
|
||||||
std::vector<Expression *> expressions;
|
std::vector<Expression *> expressions;
|
||||||
Utility::GlobRecursive(path, "*.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName), GlobFile);
|
Utility::GlobRecursive(path, "*.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName), GlobFile);
|
||||||
Dictionary::Ptr context = new Dictionary();
|
DictExpression expr(expressions);
|
||||||
DictExpression(expressions).Evaluate(context);
|
ExecuteExpression(&expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IncludeNonLocalZone(const String& zonePath)
|
static void IncludeNonLocalZone(const String& zonePath)
|
||||||
@ -93,13 +107,13 @@ static bool LoadConfigFiles(const boost::program_options::variables_map& vm, con
|
|||||||
if (vm.count("config") > 0) {
|
if (vm.count("config") > 0) {
|
||||||
BOOST_FOREACH(const String& configPath, vm["config"].as<std::vector<std::string> >()) {
|
BOOST_FOREACH(const String& configPath, vm["config"].as<std::vector<std::string> >()) {
|
||||||
Expression *expression = ConfigCompiler::CompileFile(configPath);
|
Expression *expression = ConfigCompiler::CompileFile(configPath);
|
||||||
Dictionary::Ptr context = new Dictionary();
|
ExecuteExpression(expression);
|
||||||
expression->Evaluate(context);
|
delete expression;
|
||||||
}
|
}
|
||||||
} else if (!vm.count("no-config")) {
|
} else if (!vm.count("no-config")) {
|
||||||
Expression *expression = ConfigCompiler::CompileFile(Application::GetSysconfDir() + "/icinga2/icinga2.conf");
|
Expression *expression = ConfigCompiler::CompileFile(Application::GetSysconfDir() + "/icinga2/icinga2.conf");
|
||||||
Dictionary::Ptr context = new Dictionary();
|
ExecuteExpression(expression);
|
||||||
expression->Evaluate(context);
|
delete expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load cluster config files - this should probably be in libremote but
|
/* Load cluster config files - this should probably be in libremote but
|
||||||
@ -115,8 +129,8 @@ static bool LoadConfigFiles(const boost::program_options::variables_map& vm, con
|
|||||||
String name, fragment;
|
String name, fragment;
|
||||||
BOOST_FOREACH(boost::tie(name, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
|
BOOST_FOREACH(boost::tie(name, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
|
||||||
Expression *expression = ConfigCompiler::CompileText(name, fragment);
|
Expression *expression = ConfigCompiler::CompileText(name, fragment);
|
||||||
Dictionary::Ptr context = new Dictionary();
|
ExecuteExpression(expression);
|
||||||
expression->Evaluate(context);
|
delete expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder();
|
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder();
|
||||||
|
@ -46,7 +46,7 @@ Value Expression::Evaluate(const Object::Ptr& context, DebugHint *dhint) const
|
|||||||
|
|
||||||
return DoEvaluate(context, dhint);
|
return DoEvaluate(context, dhint);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
if (boost::get_error_info<boost::errinfo_nested_exception>(ex))
|
if (dynamic_cast<const ConfigError *>(&ex) || boost::get_error_info<boost::errinfo_nested_exception>(ex))
|
||||||
throw;
|
throw;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(ConfigError("Error while evaluating expression: " + String(ex.what()))
|
BOOST_THROW_EXCEPTION(ConfigError("Error while evaluating expression: " + String(ex.what()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user