};
[config, internal, get_protected] String type (TypeNameV);
[config] name(Zone) zone (ZoneName);
+ [config] String module;
[config, internal, get_protected] Array::Ptr templates;
[get_protected] bool active;
[get_protected] bool paused {
using namespace icinga;
-bool ExecuteExpression(Expression *expression)
+static bool ExecuteExpression(Expression *expression)
{
if (!expression)
return false;
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);
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
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);
if (!ExecuteExpression(&expr))
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);
if (Utility::PathExists(etcPath) || Utility::PathExists(zonePath + "/.authoritative"))
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)
if (!configs.empty()) {
BOOST_FOREACH(const String& configPath, configs) {
- Expression *expression = ConfigCompiler::CompileFile(configPath);
+ Expression *expression = ConfigCompiler::CompileFile(configPath, true, String(), "_etc");
success = ExecuteExpression(expression);
delete expression;
if (!success)
String zonesEtcDir = Application::GetZonesDir();
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)
return false;
String zonesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones";
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)
return false;
String modulesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/modules";
- if (Utility::PathExists(modulesVarDir)) {
- std::vector<Expression *> expressions;
- Utility::Glob(modulesVarDir + "/*/include.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, ""), GlobFile);
- DictExpression expr(expressions);
- if (!ExecuteExpression(&expr))
- success = false;
- }
+ if (Utility::PathExists(modulesVarDir))
+ Utility::Glob(modulesVarDir + "/*", boost::bind(&IncludeModule, _1, boost::ref(success)), GlobDirectory);
if (!success)
return false;
ApplyRule::TypeMap ApplyRule::m_Types;
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)
- : 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)
{ }
return m_Filter;
}
+String ApplyRule::GetModule(void) const
+{
+ return m_Module;
+}
+
String ApplyRule::GetFKVar(void) const
{
return m_FKVar;
}
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)
{
- 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
String GetName(void) const;
boost::shared_ptr<Expression> GetExpression(void) const;
boost::shared_ptr<Expression> GetFilter(void) const;
+ String GetModule(void) const;
String GetFKVar(void) const;
String GetFVVar(void) const;
boost::shared_ptr<Expression> GetFTerm(void) const;
bool EvaluateFilter(ScriptFrame& frame) const;
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 void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
String m_Name;
boost::shared_ptr<Expression> m_Expression;
boost::shared_ptr<Expression> m_Filter;
+ String m_Module;
String m_FKVar;
String m_FVVar;
boost::shared_ptr<Expression> m_FTerm;
static RuleMap m_Rules;
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);
};
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));
}
;
Expression *fterm = context->m_FTerm.top();
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));
}
;
* @param input Input stream for the configuration file.
* @param zone The zone.
*/
-ConfigCompiler::ConfigCompiler(const String& path, std::istream *input, const String& zone)
- : m_Path(path), m_Input(input), m_Zone(zone), m_Eof(false), m_OpenBraces(0), m_IgnoreNewlines(0)
+ConfigCompiler::ConfigCompiler(const String& path, std::istream *input,
+ 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();
}
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));
}
/**
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;
msgbuf << "Include file '" + include + "' does not exist";
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
ppath = Utility::DirName(GetPath()) + "/" + path;
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);
}
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);
}
/**
* @param stream The input stream.
* @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 + "'");
stream->exceptions(std::istream::badbit);
- ConfigCompiler* ctx = new ConfigCompiler(path, stream, zone);
+ ConfigCompiler* ctx = new ConfigCompiler(path, stream, zone, module);
if (async) {
boost::shared_future<boost::shared_ptr<Expression> > ftr = boost::shared_future<boost::shared_ptr<Expression> >(ctx->m_Promise.get_future());
* @param path The path.
* @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 + "'");
Log(LogInformation, "ConfigCompiler")
<< "Compiling config file: " << path;
- return CompileStream(path, stream, async, zone);
+ return CompileStream(path, stream, async, zone, module);
}
/**
* @param text The text.
* @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);
- return CompileStream(path, stream, async, zone);
+ return CompileStream(path, stream, async, zone, module);
}
/**
class I2_CONFIG_API ConfigCompiler
{
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);
Expression *Compile(void);
- static Expression *CompileStream(const String& path, std::istream *stream, bool async = true, const String& zone = String());
- static Expression *CompileFile(const String& path, bool async = true, const String& zone = String());
- static Expression *CompileText(const String& path, const String& text, bool async = true, const String& zone = String());
+ static Expression *CompileStream(const String& path, std::istream *stream,
+ bool async = true, const String& zone = String(), const String& module = 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);
void SetZone(const String& zone);
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 */
Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
String m_Path;
std::istream *m_Input;
String m_Zone;
+ String m_Module;
void *m_Scanner;
bool abstract, const boost::shared_ptr<Expression>& exprl,
const boost::shared_ptr<Expression>& filter,
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_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)
{
}
dobj->SetDebugInfo(m_DebugInfo);
dobj->SetTypeNameV(m_Type);
dobj->SetZoneName(m_Zone);
+ dobj->SetModule(m_Module);
dobj->SetName(m_Name);
DebugHint debugHints;
const boost::shared_ptr<Expression>& exprl,
const boost::shared_ptr<Expression>& filter,
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 GetName(void) const;
DebugInfo GetDebugInfo(void) const;
Dictionary::Ptr GetScope(void) const;
- String GetZone(void) const;
-
static ConfigItem::Ptr GetObject(const String& type,
const String& name);
DebugInfo m_DebugInfo; /**< Debug information. */
Dictionary::Ptr m_Scope; /**< variable scope. */
String m_Zone; /**< The zone. */
+ String m_Module;
ConfigObject::Ptr m_Object;
m_Zone = zone;
}
+void ConfigItemBuilder::SetModule(const String& module)
+{
+ m_Module = module;
+}
+
void ConfigItemBuilder::AddExpression(Expression *expr)
{
m_Expressions.push_back(expr);
exprl->MakeInline();
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);
}
void SetAbstract(bool abstract);
void SetScope(const Dictionary::Ptr& scope);
void SetZone(const String& zone);
+ void SetModule(const String& module);
void AddExpression(Expression *expr);
void SetFilter(const boost::shared_ptr<Expression>& filter);
DebugInfo m_DebugInfo; /**< Debug information. */
Dictionary::Ptr m_Scope; /**< variable scope. */
String m_Zone; /**< The zone. */
+ String m_Module; /**< The module name. */
};
}
CHECK_RESULT(nameres);
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
}
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
{
public:
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 *expression, const DebugInfo& debugInfo = DebugInfo())
: 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)
{ }
String m_Target;
Expression *m_Name;
boost::shared_ptr<Expression> m_Filter;
+ String m_Module;
String m_FKVar;
String m_FVVar;
boost::shared_ptr<Expression> m_FTerm;
{
public:
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())
: 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)
Expression *m_Name;
boost::shared_ptr<Expression> m_Filter;
String m_Zone;
+ String m_Module;
std::map<String, Expression *> *m_ClosedVars;
boost::shared_ptr<Expression> m_Expression;
};
}
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())
{
- ApplyRule::AddRule(type, target, name, expression, filter, fkvar,
+ ApplyRule::AddRule(type, target, name, expression, filter, module, fkvar,
fvvar, fterm, debugInfo, EvaluateClosedVars(frame, closedVars));
return Empty;
}
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);
item->SetAbstract(abstract);
item->SetScope(EvaluateClosedVars(frame, closedVars));
item->SetZone(zone);
+ item->SetModule(module);
item->SetFilter(filter);
item->Compile()->Register();
if (!zone.IsEmpty())
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()));
ConfigItem::Ptr dependencyItem = builder->Compile();
if (!zone.IsEmpty())
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()));
ConfigItem::Ptr notificationItem = builder->Compile();
if (!zone.IsEmpty())
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()));
ConfigItem::Ptr downtimeItem = builder->Compile();
if (!zone.IsEmpty())
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()));
ConfigItem::Ptr serviceItem = builder->Compile();