mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
parent
13b5acec90
commit
0f5287c2b1
@ -73,6 +73,7 @@ abstract class ConfigObject : ConfigObjectBase
|
|||||||
};
|
};
|
||||||
[config, internal, get_protected] String type (TypeNameV);
|
[config, internal, get_protected] String type (TypeNameV);
|
||||||
[config] name(Zone) zone (ZoneName);
|
[config] name(Zone) zone (ZoneName);
|
||||||
|
[config] String module;
|
||||||
[config, internal, get_protected] Array::Ptr templates;
|
[config, internal, get_protected] Array::Ptr templates;
|
||||||
[get_protected] bool active;
|
[get_protected] bool active;
|
||||||
[get_protected] bool paused {
|
[get_protected] bool paused {
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
bool ExecuteExpression(Expression *expression)
|
static bool ExecuteExpression(Expression *expression)
|
||||||
{
|
{
|
||||||
if (!expression)
|
if (!expression)
|
||||||
return false;
|
return false;
|
||||||
@ -44,7 +44,7 @@ bool ExecuteExpression(Expression *expression)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IncludeZoneDirRecursive(const String& path, bool& success)
|
static void IncludeZoneDirRecursive(const String& path, const String& module, bool& success)
|
||||||
{
|
{
|
||||||
String zoneName = Utility::BaseName(path);
|
String zoneName = Utility::BaseName(path);
|
||||||
|
|
||||||
@ -52,20 +52,35 @@ void IncludeZoneDirRecursive(const String& path, bool& success)
|
|||||||
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
|
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
|
||||||
|
|
||||||
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, module), GlobFile);
|
||||||
DictExpression expr(expressions);
|
DictExpression expr(expressions);
|
||||||
if (!ExecuteExpression(&expr))
|
if (!ExecuteExpression(&expr))
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IncludeNonLocalZone(const String& zonePath, bool& success)
|
static void IncludeNonLocalZone(const String& zonePath, const String& module, bool& success)
|
||||||
{
|
{
|
||||||
String etcPath = Application::GetZonesDir() + "/" + Utility::BaseName(zonePath);
|
String etcPath = Application::GetZonesDir() + "/" + Utility::BaseName(zonePath);
|
||||||
|
|
||||||
if (Utility::PathExists(etcPath) || Utility::PathExists(zonePath + "/.authoritative"))
|
if (Utility::PathExists(etcPath) || Utility::PathExists(zonePath + "/.authoritative"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IncludeZoneDirRecursive(zonePath, success);
|
IncludeZoneDirRecursive(zonePath, module, success);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void IncludeModule(const String& modulePath, bool& success)
|
||||||
|
{
|
||||||
|
String moduleName = Utility::BaseName(modulePath);
|
||||||
|
|
||||||
|
if (Utility::PathExists(modulePath + "/include.conf")) {
|
||||||
|
Expression *expr = ConfigCompiler::CompileFile(modulePath + "/include.conf",
|
||||||
|
true, String(), moduleName);
|
||||||
|
|
||||||
|
if (!ExecuteExpression(expr))
|
||||||
|
success = false;
|
||||||
|
|
||||||
|
delete expr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs, const String& objectsFile)
|
bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs, const String& objectsFile)
|
||||||
@ -76,7 +91,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
|
|||||||
|
|
||||||
if (!configs.empty()) {
|
if (!configs.empty()) {
|
||||||
BOOST_FOREACH(const String& configPath, configs) {
|
BOOST_FOREACH(const String& configPath, configs) {
|
||||||
Expression *expression = ConfigCompiler::CompileFile(configPath);
|
Expression *expression = ConfigCompiler::CompileFile(configPath, true, String(), "_etc");
|
||||||
success = ExecuteExpression(expression);
|
success = ExecuteExpression(expression);
|
||||||
delete expression;
|
delete expression;
|
||||||
if (!success)
|
if (!success)
|
||||||
@ -90,26 +105,21 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
|
|||||||
|
|
||||||
String zonesEtcDir = Application::GetZonesDir();
|
String zonesEtcDir = Application::GetZonesDir();
|
||||||
if (!zonesEtcDir.IsEmpty() && Utility::PathExists(zonesEtcDir))
|
if (!zonesEtcDir.IsEmpty() && Utility::PathExists(zonesEtcDir))
|
||||||
Utility::Glob(zonesEtcDir + "/*", boost::bind(&IncludeZoneDirRecursive, _1, boost::ref(success)), GlobDirectory);
|
Utility::Glob(zonesEtcDir + "/*", boost::bind(&IncludeZoneDirRecursive, _1, "_etc", boost::ref(success)), GlobDirectory);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
String zonesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones";
|
String zonesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones";
|
||||||
if (Utility::PathExists(zonesVarDir))
|
if (Utility::PathExists(zonesVarDir))
|
||||||
Utility::Glob(zonesVarDir + "/*", boost::bind(&IncludeNonLocalZone, _1, boost::ref(success)), GlobDirectory);
|
Utility::Glob(zonesVarDir + "/*", boost::bind(&IncludeNonLocalZone, _1, "_cluster", boost::ref(success)), GlobDirectory);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
String modulesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/modules";
|
String modulesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/modules";
|
||||||
if (Utility::PathExists(modulesVarDir)) {
|
if (Utility::PathExists(modulesVarDir))
|
||||||
std::vector<Expression *> expressions;
|
Utility::Glob(modulesVarDir + "/*", boost::bind(&IncludeModule, _1, boost::ref(success)), GlobDirectory);
|
||||||
Utility::Glob(modulesVarDir + "/*/include.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, ""), GlobFile);
|
|
||||||
DictExpression expr(expressions);
|
|
||||||
if (!ExecuteExpression(&expr))
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
|
@ -28,9 +28,9 @@ ApplyRule::RuleMap ApplyRule::m_Rules;
|
|||||||
ApplyRule::TypeMap ApplyRule::m_Types;
|
ApplyRule::TypeMap ApplyRule::m_Types;
|
||||||
|
|
||||||
ApplyRule::ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
ApplyRule::ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
||||||
const boost::shared_ptr<Expression>& filter, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
const boost::shared_ptr<Expression>& filter, const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
||||||
const DebugInfo& di, const Dictionary::Ptr& scope)
|
const DebugInfo& di, const Dictionary::Ptr& scope)
|
||||||
: m_TargetType(targetType), m_Name(name), m_Expression(expression), m_Filter(filter), m_FKVar(fkvar),
|
: m_TargetType(targetType), m_Name(name), m_Expression(expression), m_Filter(filter), m_Module(module), m_FKVar(fkvar),
|
||||||
m_FVVar(fvvar), m_FTerm(fterm), m_DebugInfo(di), m_Scope(scope), m_HasMatches(false)
|
m_FVVar(fvvar), m_FTerm(fterm), m_DebugInfo(di), m_Scope(scope), m_HasMatches(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -54,6 +54,11 @@ boost::shared_ptr<Expression> ApplyRule::GetFilter(void) const
|
|||||||
return m_Filter;
|
return m_Filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String ApplyRule::GetModule(void) const
|
||||||
|
{
|
||||||
|
return m_Module;
|
||||||
|
}
|
||||||
|
|
||||||
String ApplyRule::GetFKVar(void) const
|
String ApplyRule::GetFKVar(void) const
|
||||||
{
|
{
|
||||||
return m_FKVar;
|
return m_FKVar;
|
||||||
@ -80,10 +85,10 @@ Dictionary::Ptr ApplyRule::GetScope(void) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ApplyRule::AddRule(const String& sourceType, const String& targetType, const String& name,
|
void ApplyRule::AddRule(const String& sourceType, const String& targetType, const String& name,
|
||||||
const boost::shared_ptr<Expression>& expression, const boost::shared_ptr<Expression>& filter, const String& fkvar,
|
const boost::shared_ptr<Expression>& expression, const boost::shared_ptr<Expression>& filter, const String& module, const String& fkvar,
|
||||||
const String& fvvar, const boost::shared_ptr<Expression>& fterm, const DebugInfo& di, const Dictionary::Ptr& scope)
|
const String& fvvar, const boost::shared_ptr<Expression>& fterm, const DebugInfo& di, const Dictionary::Ptr& scope)
|
||||||
{
|
{
|
||||||
m_Rules[sourceType].push_back(ApplyRule(targetType, name, expression, filter, fkvar, fvvar, fterm, di, scope));
|
m_Rules[sourceType].push_back(ApplyRule(targetType, name, expression, filter, module, fkvar, fvvar, fterm, di, scope));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ApplyRule::EvaluateFilter(ScriptFrame& frame) const
|
bool ApplyRule::EvaluateFilter(ScriptFrame& frame) const
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
String GetName(void) const;
|
String GetName(void) const;
|
||||||
boost::shared_ptr<Expression> GetExpression(void) const;
|
boost::shared_ptr<Expression> GetExpression(void) const;
|
||||||
boost::shared_ptr<Expression> GetFilter(void) const;
|
boost::shared_ptr<Expression> GetFilter(void) const;
|
||||||
|
String GetModule(void) const;
|
||||||
String GetFKVar(void) const;
|
String GetFKVar(void) const;
|
||||||
String GetFVVar(void) const;
|
String GetFVVar(void) const;
|
||||||
boost::shared_ptr<Expression> GetFTerm(void) const;
|
boost::shared_ptr<Expression> GetFTerm(void) const;
|
||||||
@ -52,7 +53,7 @@ public:
|
|||||||
bool EvaluateFilter(ScriptFrame& frame) const;
|
bool EvaluateFilter(ScriptFrame& frame) const;
|
||||||
|
|
||||||
static void AddRule(const String& sourceType, const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
static void AddRule(const String& sourceType, const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
||||||
const boost::shared_ptr<Expression>& filter, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, const DebugInfo& di, const Dictionary::Ptr& scope);
|
const boost::shared_ptr<Expression>& filter, const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||||
static std::vector<ApplyRule>& GetRules(const String& type);
|
static std::vector<ApplyRule>& GetRules(const String& type);
|
||||||
|
|
||||||
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
|
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
|
||||||
@ -68,6 +69,7 @@ private:
|
|||||||
String m_Name;
|
String m_Name;
|
||||||
boost::shared_ptr<Expression> m_Expression;
|
boost::shared_ptr<Expression> m_Expression;
|
||||||
boost::shared_ptr<Expression> m_Filter;
|
boost::shared_ptr<Expression> m_Filter;
|
||||||
|
String m_Module;
|
||||||
String m_FKVar;
|
String m_FKVar;
|
||||||
String m_FVVar;
|
String m_FVVar;
|
||||||
boost::shared_ptr<Expression> m_FTerm;
|
boost::shared_ptr<Expression> m_FTerm;
|
||||||
@ -79,7 +81,7 @@ private:
|
|||||||
static RuleMap m_Rules;
|
static RuleMap m_Rules;
|
||||||
|
|
||||||
ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
||||||
const boost::shared_ptr<Expression>& filter, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
const boost::shared_ptr<Expression>& filter, const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
||||||
const DebugInfo& di, const Dictionary::Ptr& scope);
|
const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ object:
|
|||||||
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' is missing 'assign' for type '" + type + "'", DebugInfoRange(@2, @4)));
|
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' is missing 'assign' for type '" + type + "'", DebugInfoRange(@2, @4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), $5, $6, DebugInfoRange(@2, @5));
|
$$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), context->GetModule(), $5, $6, DebugInfoRange(@2, @5));
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -1017,7 +1017,7 @@ apply:
|
|||||||
Expression *fterm = context->m_FTerm.top();
|
Expression *fterm = context->m_FTerm.top();
|
||||||
context->m_FTerm.pop();
|
context->m_FTerm.pop();
|
||||||
|
|
||||||
$$ = new ApplyExpression(type, target, $4, filter, fkvar, fvvar, fterm, $7, $8, DebugInfoRange(@2, @7));
|
$$ = new ApplyExpression(type, target, $4, filter, context->GetModule(), fkvar, fvvar, fterm, $7, $8, DebugInfoRange(@2, @7));
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -40,8 +40,10 @@ std::map<String, std::vector<ZoneFragment> > ConfigCompiler::m_ZoneDirs;
|
|||||||
* @param input Input stream for the configuration file.
|
* @param input Input stream for the configuration file.
|
||||||
* @param zone The zone.
|
* @param zone The zone.
|
||||||
*/
|
*/
|
||||||
ConfigCompiler::ConfigCompiler(const String& path, std::istream *input, const String& zone)
|
ConfigCompiler::ConfigCompiler(const String& path, std::istream *input,
|
||||||
: m_Path(path), m_Input(input), m_Zone(zone), m_Eof(false), m_OpenBraces(0), m_IgnoreNewlines(0)
|
const String& zone, const String& module)
|
||||||
|
: m_Path(path), m_Input(input), m_Zone(zone), m_Module(module),
|
||||||
|
m_Eof(false), m_OpenBraces(0), m_IgnoreNewlines(0)
|
||||||
{
|
{
|
||||||
InitializeScanner();
|
InitializeScanner();
|
||||||
}
|
}
|
||||||
@ -98,9 +100,20 @@ String ConfigCompiler::GetZone(void) const
|
|||||||
return m_Zone;
|
return m_Zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigCompiler::CollectIncludes(std::vector<Expression *>& expressions, const String& file, const String& zone)
|
void ConfigCompiler::SetModule(const String& module)
|
||||||
{
|
{
|
||||||
expressions.push_back(CompileFile(file, true, zone));
|
m_Module = module;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ConfigCompiler::GetModule(void) const
|
||||||
|
{
|
||||||
|
return m_Module;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigCompiler::CollectIncludes(std::vector<Expression *>& expressions,
|
||||||
|
const String& file, const String& zone, const String& module)
|
||||||
|
{
|
||||||
|
expressions.push_back(CompileFile(file, true, zone, module));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,7 +147,7 @@ Expression *ConfigCompiler::HandleInclude(const String& include, bool search, co
|
|||||||
|
|
||||||
std::vector<Expression *> expressions;
|
std::vector<Expression *> expressions;
|
||||||
|
|
||||||
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
|
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Module), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "Include file '" + include + "' does not exist";
|
msgbuf << "Include file '" + include + "' does not exist";
|
||||||
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
|
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
|
||||||
@ -162,7 +175,7 @@ Expression *ConfigCompiler::HandleIncludeRecursive(const String& path, const Str
|
|||||||
ppath = Utility::DirName(GetPath()) + "/" + path;
|
ppath = Utility::DirName(GetPath()) + "/" + path;
|
||||||
|
|
||||||
std::vector<Expression *> expressions;
|
std::vector<Expression *> expressions;
|
||||||
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone), GlobFile);
|
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Module), GlobFile);
|
||||||
return new DictExpression(expressions);
|
return new DictExpression(expressions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +192,7 @@ void ConfigCompiler::HandleIncludeZone(const String& tag, const String& path, co
|
|||||||
|
|
||||||
RegisterZoneDir(tag, ppath, zoneName);
|
RegisterZoneDir(tag, ppath, zoneName);
|
||||||
|
|
||||||
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName), GlobFile);
|
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, m_Module), GlobFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,13 +245,14 @@ void ConfigCompiler::CompileHelper(void)
|
|||||||
* @param stream The input stream.
|
* @param stream The input stream.
|
||||||
* @returns Configuration items.
|
* @returns Configuration items.
|
||||||
*/
|
*/
|
||||||
Expression *ConfigCompiler::CompileStream(const String& path, std::istream *stream, bool async, const String& zone)
|
Expression *ConfigCompiler::CompileStream(const String& path,
|
||||||
|
std::istream *stream, bool async, const String& zone, const String& module)
|
||||||
{
|
{
|
||||||
CONTEXT("Compiling configuration stream with name '" + path + "'");
|
CONTEXT("Compiling configuration stream with name '" + path + "'");
|
||||||
|
|
||||||
stream->exceptions(std::istream::badbit);
|
stream->exceptions(std::istream::badbit);
|
||||||
|
|
||||||
ConfigCompiler* ctx = new ConfigCompiler(path, stream, zone);
|
ConfigCompiler* ctx = new ConfigCompiler(path, stream, zone, module);
|
||||||
|
|
||||||
if (async) {
|
if (async) {
|
||||||
boost::shared_future<boost::shared_ptr<Expression> > ftr = boost::shared_future<boost::shared_ptr<Expression> >(ctx->m_Promise.get_future());
|
boost::shared_future<boost::shared_ptr<Expression> > ftr = boost::shared_future<boost::shared_ptr<Expression> >(ctx->m_Promise.get_future());
|
||||||
@ -266,7 +280,8 @@ Expression *ConfigCompiler::CompileStream(const String& path, std::istream *stre
|
|||||||
* @param path The path.
|
* @param path The path.
|
||||||
* @returns Configuration items.
|
* @returns Configuration items.
|
||||||
*/
|
*/
|
||||||
Expression *ConfigCompiler::CompileFile(const String& path, bool async, const String& zone)
|
Expression *ConfigCompiler::CompileFile(const String& path, bool async,
|
||||||
|
const String& zone, const String& module)
|
||||||
{
|
{
|
||||||
CONTEXT("Compiling configuration file '" + path + "'");
|
CONTEXT("Compiling configuration file '" + path + "'");
|
||||||
|
|
||||||
@ -282,7 +297,7 @@ Expression *ConfigCompiler::CompileFile(const String& path, bool async, const St
|
|||||||
Log(LogInformation, "ConfigCompiler")
|
Log(LogInformation, "ConfigCompiler")
|
||||||
<< "Compiling config file: " << path;
|
<< "Compiling config file: " << path;
|
||||||
|
|
||||||
return CompileStream(path, stream, async, zone);
|
return CompileStream(path, stream, async, zone, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,10 +307,11 @@ Expression *ConfigCompiler::CompileFile(const String& path, bool async, const St
|
|||||||
* @param text The text.
|
* @param text The text.
|
||||||
* @returns Configuration items.
|
* @returns Configuration items.
|
||||||
*/
|
*/
|
||||||
Expression *ConfigCompiler::CompileText(const String& path, const String& text, bool async, const String& zone)
|
Expression *ConfigCompiler::CompileText(const String& path, const String& text,
|
||||||
|
bool async, const String& zone, const String& module)
|
||||||
{
|
{
|
||||||
std::stringstream *stream = new std::stringstream(text);
|
std::stringstream *stream = new std::stringstream(text);
|
||||||
return CompileStream(path, stream, async, zone);
|
return CompileStream(path, stream, async, zone, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,14 +79,18 @@ struct ZoneFragment
|
|||||||
class I2_CONFIG_API ConfigCompiler
|
class I2_CONFIG_API ConfigCompiler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ConfigCompiler(const String& path, std::istream *input, const String& zone = String());
|
explicit ConfigCompiler(const String& path, std::istream *input,
|
||||||
|
const String& zone = String(), const String& module = String());
|
||||||
virtual ~ConfigCompiler(void);
|
virtual ~ConfigCompiler(void);
|
||||||
|
|
||||||
Expression *Compile(void);
|
Expression *Compile(void);
|
||||||
|
|
||||||
static Expression *CompileStream(const String& path, std::istream *stream, bool async = true, const String& zone = String());
|
static Expression *CompileStream(const String& path, std::istream *stream,
|
||||||
static Expression *CompileFile(const String& path, bool async = true, const String& zone = String());
|
bool async = true, const String& zone = String(), const String& module = String());
|
||||||
static Expression *CompileText(const String& path, const String& text, bool async = true, const String& zone = String());
|
static Expression *CompileFile(const String& path, bool async = true,
|
||||||
|
const String& zone = String(), const String& module = String());
|
||||||
|
static Expression *CompileText(const String& path, const String& text,
|
||||||
|
bool async = true, const String& zone = String(), const String& module = String());
|
||||||
|
|
||||||
static void AddIncludeSearchDir(const String& dir);
|
static void AddIncludeSearchDir(const String& dir);
|
||||||
|
|
||||||
@ -94,8 +98,12 @@ public:
|
|||||||
|
|
||||||
void SetZone(const String& zone);
|
void SetZone(const String& zone);
|
||||||
String GetZone(void) const;
|
String GetZone(void) const;
|
||||||
|
|
||||||
|
void SetModule(const String& module);
|
||||||
|
String GetModule(void) const;
|
||||||
|
|
||||||
static void CollectIncludes(std::vector<Expression *>& expressions, const String& file, const String& zone);
|
static void CollectIncludes(std::vector<Expression *>& expressions,
|
||||||
|
const String& file, const String& zone, const String& module);
|
||||||
|
|
||||||
/* internally used methods */
|
/* internally used methods */
|
||||||
Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
|
Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
|
||||||
@ -117,6 +125,7 @@ private:
|
|||||||
String m_Path;
|
String m_Path;
|
||||||
std::istream *m_Input;
|
std::istream *m_Input;
|
||||||
String m_Zone;
|
String m_Zone;
|
||||||
|
String m_Module;
|
||||||
|
|
||||||
void *m_Scanner;
|
void *m_Scanner;
|
||||||
|
|
||||||
|
@ -62,10 +62,11 @@ ConfigItem::ConfigItem(const String& type, const String& name,
|
|||||||
bool abstract, const boost::shared_ptr<Expression>& exprl,
|
bool abstract, const boost::shared_ptr<Expression>& exprl,
|
||||||
const boost::shared_ptr<Expression>& filter,
|
const boost::shared_ptr<Expression>& filter,
|
||||||
const DebugInfo& debuginfo, const Dictionary::Ptr& scope,
|
const DebugInfo& debuginfo, const Dictionary::Ptr& scope,
|
||||||
const String& zone)
|
const String& zone, const String& module)
|
||||||
: m_Type(type), m_Name(name), m_Abstract(abstract),
|
: m_Type(type), m_Name(name), m_Abstract(abstract),
|
||||||
m_Expression(exprl), m_Filter(filter),
|
m_Expression(exprl), m_Filter(filter),
|
||||||
m_DebugInfo(debuginfo), m_Scope(scope), m_Zone(zone)
|
m_DebugInfo(debuginfo), m_Scope(scope), m_Zone(zone),
|
||||||
|
m_Module(module)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,6 +171,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||||||
dobj->SetDebugInfo(m_DebugInfo);
|
dobj->SetDebugInfo(m_DebugInfo);
|
||||||
dobj->SetTypeNameV(m_Type);
|
dobj->SetTypeNameV(m_Type);
|
||||||
dobj->SetZoneName(m_Zone);
|
dobj->SetZoneName(m_Zone);
|
||||||
|
dobj->SetModule(m_Module);
|
||||||
dobj->SetName(m_Name);
|
dobj->SetName(m_Name);
|
||||||
|
|
||||||
DebugHint debugHints;
|
DebugHint debugHints;
|
||||||
|
@ -42,7 +42,8 @@ public:
|
|||||||
const boost::shared_ptr<Expression>& exprl,
|
const boost::shared_ptr<Expression>& exprl,
|
||||||
const boost::shared_ptr<Expression>& filter,
|
const boost::shared_ptr<Expression>& filter,
|
||||||
const DebugInfo& debuginfo,
|
const DebugInfo& debuginfo,
|
||||||
const Dictionary::Ptr& scope, const String& zone);
|
const Dictionary::Ptr& scope, const String& zone,
|
||||||
|
const String& module);
|
||||||
|
|
||||||
String GetType(void) const;
|
String GetType(void) const;
|
||||||
String GetName(void) const;
|
String GetName(void) const;
|
||||||
@ -60,8 +61,6 @@ public:
|
|||||||
DebugInfo GetDebugInfo(void) const;
|
DebugInfo GetDebugInfo(void) const;
|
||||||
Dictionary::Ptr GetScope(void) const;
|
Dictionary::Ptr GetScope(void) const;
|
||||||
|
|
||||||
String GetZone(void) const;
|
|
||||||
|
|
||||||
static ConfigItem::Ptr GetObject(const String& type,
|
static ConfigItem::Ptr GetObject(const String& type,
|
||||||
const String& name);
|
const String& name);
|
||||||
|
|
||||||
@ -82,6 +81,7 @@ private:
|
|||||||
DebugInfo m_DebugInfo; /**< Debug information. */
|
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||||
Dictionary::Ptr m_Scope; /**< variable scope. */
|
Dictionary::Ptr m_Scope; /**< variable scope. */
|
||||||
String m_Zone; /**< The zone. */
|
String m_Zone; /**< The zone. */
|
||||||
|
String m_Module;
|
||||||
|
|
||||||
ConfigObject::Ptr m_Object;
|
ConfigObject::Ptr m_Object;
|
||||||
|
|
||||||
|
@ -65,6 +65,11 @@ void ConfigItemBuilder::SetZone(const String& zone)
|
|||||||
m_Zone = zone;
|
m_Zone = zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigItemBuilder::SetModule(const String& module)
|
||||||
|
{
|
||||||
|
m_Module = module;
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigItemBuilder::AddExpression(Expression *expr)
|
void ConfigItemBuilder::AddExpression(Expression *expr)
|
||||||
{
|
{
|
||||||
m_Expressions.push_back(expr);
|
m_Expressions.push_back(expr);
|
||||||
@ -111,6 +116,6 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void)
|
|||||||
exprl->MakeInline();
|
exprl->MakeInline();
|
||||||
|
|
||||||
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,
|
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,
|
||||||
m_DebugInfo, m_Scope, m_Zone);
|
m_DebugInfo, m_Scope, m_Zone, m_Module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ public:
|
|||||||
void SetAbstract(bool abstract);
|
void SetAbstract(bool abstract);
|
||||||
void SetScope(const Dictionary::Ptr& scope);
|
void SetScope(const Dictionary::Ptr& scope);
|
||||||
void SetZone(const String& zone);
|
void SetZone(const String& zone);
|
||||||
|
void SetModule(const String& module);
|
||||||
|
|
||||||
void AddExpression(Expression *expr);
|
void AddExpression(Expression *expr);
|
||||||
void SetFilter(const boost::shared_ptr<Expression>& filter);
|
void SetFilter(const boost::shared_ptr<Expression>& filter);
|
||||||
@ -62,6 +63,7 @@ private:
|
|||||||
DebugInfo m_DebugInfo; /**< Debug information. */
|
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||||
Dictionary::Ptr m_Scope; /**< variable scope. */
|
Dictionary::Ptr m_Scope; /**< variable scope. */
|
||||||
String m_Zone; /**< The zone. */
|
String m_Zone; /**< The zone. */
|
||||||
|
String m_Module; /**< The module name. */
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -740,7 +740,7 @@ ExpressionResult ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhin
|
|||||||
CHECK_RESULT(nameres);
|
CHECK_RESULT(nameres);
|
||||||
|
|
||||||
return VMOps::NewApply(frame, m_Type, m_Target, nameres.GetValue(), m_Filter,
|
return VMOps::NewApply(frame, m_Type, m_Target, nameres.GetValue(), m_Filter,
|
||||||
m_FKVar, m_FVVar, m_FTerm, m_ClosedVars, m_Expression, m_DebugInfo);
|
m_Module, m_FKVar, m_FVVar, m_FTerm, m_ClosedVars, m_Expression, m_DebugInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
@ -758,7 +758,7 @@ ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhi
|
|||||||
}
|
}
|
||||||
|
|
||||||
return VMOps::NewObject(frame, m_Abstract, m_Type, name, m_Filter, m_Zone,
|
return VMOps::NewObject(frame, m_Abstract, m_Type, name, m_Filter, m_Zone,
|
||||||
m_ClosedVars, m_Expression, m_DebugInfo);
|
m_Module, m_ClosedVars, m_Expression, m_DebugInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionResult ForExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
ExpressionResult ForExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
|
@ -807,11 +807,11 @@ class I2_CONFIG_API ApplyExpression : public DebuggableExpression
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ApplyExpression(const String& type, const String& target, Expression *name,
|
ApplyExpression(const String& type, const String& target, Expression *name,
|
||||||
Expression *filter, const String& fkvar, const String& fvvar,
|
Expression *filter, const String& module, const String& fkvar, const String& fvvar,
|
||||||
Expression *fterm, std::map<String, Expression *> *closedVars,
|
Expression *fterm, std::map<String, Expression *> *closedVars,
|
||||||
Expression *expression, const DebugInfo& debugInfo = DebugInfo())
|
Expression *expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
: DebuggableExpression(debugInfo), m_Type(type), m_Target(target),
|
: DebuggableExpression(debugInfo), m_Type(type), m_Target(target),
|
||||||
m_Name(name), m_Filter(filter), m_FKVar(fkvar), m_FVVar(fvvar),
|
m_Name(name), m_Filter(filter), m_Module(module), m_FKVar(fkvar), m_FVVar(fvvar),
|
||||||
m_FTerm(fterm), m_ClosedVars(closedVars), m_Expression(expression)
|
m_FTerm(fterm), m_ClosedVars(closedVars), m_Expression(expression)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -828,6 +828,7 @@ private:
|
|||||||
String m_Target;
|
String m_Target;
|
||||||
Expression *m_Name;
|
Expression *m_Name;
|
||||||
boost::shared_ptr<Expression> m_Filter;
|
boost::shared_ptr<Expression> m_Filter;
|
||||||
|
String m_Module;
|
||||||
String m_FKVar;
|
String m_FKVar;
|
||||||
String m_FVVar;
|
String m_FVVar;
|
||||||
boost::shared_ptr<Expression> m_FTerm;
|
boost::shared_ptr<Expression> m_FTerm;
|
||||||
@ -839,10 +840,10 @@ class I2_CONFIG_API ObjectExpression : public DebuggableExpression
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjectExpression(bool abstract, const String& type, Expression *name, Expression *filter,
|
ObjectExpression(bool abstract, const String& type, Expression *name, Expression *filter,
|
||||||
const String& zone, std::map<String, Expression *> *closedVars,
|
const String& zone, const String& module, std::map<String, Expression *> *closedVars,
|
||||||
Expression *expression, const DebugInfo& debugInfo = DebugInfo())
|
Expression *expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
: DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(type),
|
: DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(type),
|
||||||
m_Name(name), m_Filter(filter), m_Zone(zone), m_ClosedVars(closedVars), m_Expression(expression)
|
m_Name(name), m_Filter(filter), m_Zone(zone), m_Module(module), m_ClosedVars(closedVars), m_Expression(expression)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~ObjectExpression(void)
|
~ObjectExpression(void)
|
||||||
@ -859,6 +860,7 @@ private:
|
|||||||
Expression *m_Name;
|
Expression *m_Name;
|
||||||
boost::shared_ptr<Expression> m_Filter;
|
boost::shared_ptr<Expression> m_Filter;
|
||||||
String m_Zone;
|
String m_Zone;
|
||||||
|
String m_Module;
|
||||||
std::map<String, Expression *> *m_ClosedVars;
|
std::map<String, Expression *> *m_ClosedVars;
|
||||||
boost::shared_ptr<Expression> m_Expression;
|
boost::shared_ptr<Expression> m_Expression;
|
||||||
};
|
};
|
||||||
|
@ -105,17 +105,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr<Expression>& filter,
|
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr<Expression>& filter,
|
||||||
const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
|
const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
|
||||||
const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
{
|
{
|
||||||
ApplyRule::AddRule(type, target, name, expression, filter, fkvar,
|
ApplyRule::AddRule(type, target, name, expression, filter, module, fkvar,
|
||||||
fvvar, fterm, debugInfo, EvaluateClosedVars(frame, closedVars));
|
fvvar, fterm, debugInfo, EvaluateClosedVars(frame, closedVars));
|
||||||
|
|
||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Value NewObject(ScriptFrame& frame, bool abstract, const String& type, const String& name, const boost::shared_ptr<Expression>& filter,
|
static inline Value NewObject(ScriptFrame& frame, bool abstract, const String& type, const String& name, const boost::shared_ptr<Expression>& filter,
|
||||||
const String& zone, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
const String& zone, const String& module, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
{
|
{
|
||||||
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
|
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
|
||||||
|
|
||||||
@ -147,6 +147,7 @@ public:
|
|||||||
item->SetAbstract(abstract);
|
item->SetAbstract(abstract);
|
||||||
item->SetScope(EvaluateClosedVars(frame, closedVars));
|
item->SetScope(EvaluateClosedVars(frame, closedVars));
|
||||||
item->SetZone(zone);
|
item->SetZone(zone);
|
||||||
|
item->SetModule(module);
|
||||||
item->SetFilter(filter);
|
item->SetFilter(filter);
|
||||||
item->Compile()->Register();
|
item->Compile()->Register();
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
|
|||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "module"), OpSetLiteral, MakeLiteral(rule.GetModule()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr dependencyItem = builder->Compile();
|
ConfigItem::Ptr dependencyItem = builder->Compile();
|
||||||
|
@ -70,6 +70,8 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
|
|||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "module"), OpSetLiteral, MakeLiteral(rule.GetModule()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr notificationItem = builder->Compile();
|
ConfigItem::Ptr notificationItem = builder->Compile();
|
||||||
|
@ -69,6 +69,8 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
|
|||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "module"), OpSetLiteral, MakeLiteral(rule.GetModule()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr downtimeItem = builder->Compile();
|
ConfigItem::Ptr downtimeItem = builder->Compile();
|
||||||
|
@ -63,6 +63,8 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
|
|||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "module"), OpSetLiteral, MakeLiteral(rule.GetModule()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr serviceItem = builder->Compile();
|
ConfigItem::Ptr serviceItem = builder->Compile();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user