mirror of https://github.com/Icinga/icinga2.git
parent
6fff339212
commit
da83bae660
|
@ -79,7 +79,7 @@ abstract class ConfigObject : ConfigObjectBase
|
|||
};
|
||||
[config, internal, get_protected] String type (TypeNameV);
|
||||
[config] name(Zone) zone (ZoneName);
|
||||
[config] String module;
|
||||
[config] String package;
|
||||
[config, internal, get_protected] Array::Ptr templates;
|
||||
[get_protected] bool active;
|
||||
[get_protected] bool paused {
|
||||
|
|
|
@ -44,7 +44,7 @@ static bool ExecuteExpression(Expression *expression)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void IncludeZoneDirRecursive(const String& path, const String& module, bool& success)
|
||||
static void IncludeZoneDirRecursive(const String& path, const String& package, bool& success)
|
||||
{
|
||||
String zoneName = Utility::BaseName(path);
|
||||
|
||||
|
@ -52,29 +52,29 @@ static void IncludeZoneDirRecursive(const String& path, const String& module, bo
|
|||
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
|
||||
|
||||
std::vector<Expression *> expressions;
|
||||
Utility::GlobRecursive(path, "*.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, module), GlobFile);
|
||||
Utility::GlobRecursive(path, "*.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, package), GlobFile);
|
||||
DictExpression expr(expressions);
|
||||
if (!ExecuteExpression(&expr))
|
||||
success = false;
|
||||
}
|
||||
|
||||
static void IncludeNonLocalZone(const String& zonePath, const String& module, bool& success)
|
||||
static void IncludeNonLocalZone(const String& zonePath, const String& package, bool& success)
|
||||
{
|
||||
String etcPath = Application::GetZonesDir() + "/" + Utility::BaseName(zonePath);
|
||||
|
||||
if (Utility::PathExists(etcPath) || Utility::PathExists(zonePath + "/.authoritative"))
|
||||
return;
|
||||
|
||||
IncludeZoneDirRecursive(zonePath, module, success);
|
||||
IncludeZoneDirRecursive(zonePath, package, success);
|
||||
}
|
||||
|
||||
static void IncludeModule(const String& modulePath, bool& success)
|
||||
static void IncludePackage(const String& packagePath, bool& success)
|
||||
{
|
||||
String moduleName = Utility::BaseName(modulePath);
|
||||
String packageName = Utility::BaseName(packagePath);
|
||||
|
||||
if (Utility::PathExists(modulePath + "/include.conf")) {
|
||||
Expression *expr = ConfigCompiler::CompileFile(modulePath + "/include.conf",
|
||||
String(), moduleName);
|
||||
if (Utility::PathExists(packagePath + "/include.conf")) {
|
||||
Expression *expr = ConfigCompiler::CompileFile(packagePath + "/include.conf",
|
||||
String(), packageName);
|
||||
|
||||
if (!ExecuteExpression(expr))
|
||||
success = false;
|
||||
|
@ -117,9 +117,9 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
|
|||
if (!success)
|
||||
return false;
|
||||
|
||||
String modulesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/modules";
|
||||
if (Utility::PathExists(modulesVarDir))
|
||||
Utility::Glob(modulesVarDir + "/*", boost::bind(&IncludeModule, _1, boost::ref(success)), GlobDirectory);
|
||||
String packagesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/packages";
|
||||
if (Utility::PathExists(packagesVarDir))
|
||||
Utility::Glob(packagesVarDir + "/*", boost::bind(&IncludePackage, _1, boost::ref(success)), GlobDirectory);
|
||||
|
||||
if (!success)
|
||||
return false;
|
||||
|
|
|
@ -28,9 +28,9 @@ ApplyRule::RuleMap ApplyRule::m_Rules;
|
|||
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& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
||||
const boost::shared_ptr<Expression>& filter, const String& package, 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_Module(module), m_FKVar(fkvar),
|
||||
: m_TargetType(targetType), m_Name(name), m_Expression(expression), m_Filter(filter), m_Package(package), m_FKVar(fkvar),
|
||||
m_FVVar(fvvar), m_FTerm(fterm), m_DebugInfo(di), m_Scope(scope), m_HasMatches(false)
|
||||
{ }
|
||||
|
||||
|
@ -54,9 +54,9 @@ boost::shared_ptr<Expression> ApplyRule::GetFilter(void) const
|
|||
return m_Filter;
|
||||
}
|
||||
|
||||
String ApplyRule::GetModule(void) const
|
||||
String ApplyRule::GetPackage(void) const
|
||||
{
|
||||
return m_Module;
|
||||
return m_Package;
|
||||
}
|
||||
|
||||
String ApplyRule::GetFKVar(void) const
|
||||
|
@ -85,10 +85,10 @@ Dictionary::Ptr ApplyRule::GetScope(void) const
|
|||
}
|
||||
|
||||
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& module, const String& fkvar,
|
||||
const boost::shared_ptr<Expression>& expression, const boost::shared_ptr<Expression>& filter, const String& package, 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, module, fkvar, fvvar, fterm, di, scope));
|
||||
m_Rules[sourceType].push_back(ApplyRule(targetType, name, expression, filter, package, fkvar, fvvar, fterm, di, scope));
|
||||
}
|
||||
|
||||
bool ApplyRule::EvaluateFilter(ScriptFrame& frame) const
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
String GetName(void) const;
|
||||
boost::shared_ptr<Expression> GetExpression(void) const;
|
||||
boost::shared_ptr<Expression> GetFilter(void) const;
|
||||
String GetModule(void) const;
|
||||
String GetPackage(void) const;
|
||||
String GetFKVar(void) const;
|
||||
String GetFVVar(void) const;
|
||||
boost::shared_ptr<Expression> GetFTerm(void) const;
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
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& module, 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& package, 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);
|
||||
|
@ -69,7 +69,7 @@ private:
|
|||
String m_Name;
|
||||
boost::shared_ptr<Expression> m_Expression;
|
||||
boost::shared_ptr<Expression> m_Filter;
|
||||
String m_Module;
|
||||
String m_Package;
|
||||
String m_FKVar;
|
||||
String m_FVVar;
|
||||
boost::shared_ptr<Expression> m_FTerm;
|
||||
|
@ -81,7 +81,7 @@ private:
|
|||
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& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
||||
const boost::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
||||
const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||
};
|
||||
|
||||
|
|
|
@ -378,7 +378,7 @@ object:
|
|||
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' is missing 'assign' for type '" + type + "'", DebugInfoRange(@2, @4)));
|
||||
}
|
||||
|
||||
$$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), context->GetModule(), $5, $6, DebugInfoRange(@2, @5));
|
||||
$$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), context->GetPackage(), $5, $6, DebugInfoRange(@2, @5));
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -1015,7 +1015,7 @@ apply:
|
|||
Expression *fterm = context->m_FTerm.top();
|
||||
context->m_FTerm.pop();
|
||||
|
||||
$$ = new ApplyExpression(type, target, $4, filter, context->GetModule(), fkvar, fvvar, fterm, $7, $8, DebugInfoRange(@2, @7));
|
||||
$$ = new ApplyExpression(type, target, $4, filter, context->GetPackage(), fkvar, fvvar, fterm, $7, $8, DebugInfoRange(@2, @7));
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ std::map<String, std::vector<ZoneFragment> > ConfigCompiler::m_ZoneDirs;
|
|||
* @param zone The zone.
|
||||
*/
|
||||
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),
|
||||
const String& zone, const String& package)
|
||||
: m_Path(path), m_Input(input), m_Zone(zone), m_Package(package),
|
||||
m_Eof(false), m_OpenBraces(0), m_IgnoreNewlines(0)
|
||||
{
|
||||
InitializeScanner();
|
||||
|
@ -100,20 +100,20 @@ String ConfigCompiler::GetZone(void) const
|
|||
return m_Zone;
|
||||
}
|
||||
|
||||
void ConfigCompiler::SetModule(const String& module)
|
||||
void ConfigCompiler::SetPackage(const String& package)
|
||||
{
|
||||
m_Module = module;
|
||||
m_Package = package;
|
||||
}
|
||||
|
||||
String ConfigCompiler::GetModule(void) const
|
||||
String ConfigCompiler::GetPackage(void) const
|
||||
{
|
||||
return m_Module;
|
||||
return m_Package;
|
||||
}
|
||||
|
||||
void ConfigCompiler::CollectIncludes(std::vector<Expression *>& expressions,
|
||||
const String& file, const String& zone, const String& module)
|
||||
const String& file, const String& zone, const String& package)
|
||||
{
|
||||
expressions.push_back(CompileFile(file, zone, module));
|
||||
expressions.push_back(CompileFile(file, zone, package));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,7 +147,7 @@ Expression *ConfigCompiler::HandleInclude(const String& include, bool search, co
|
|||
|
||||
std::vector<Expression *> expressions;
|
||||
|
||||
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Module), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
|
||||
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Package), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << "Include file '" + include + "' does not exist";
|
||||
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
|
||||
|
@ -175,7 +175,7 @@ Expression *ConfigCompiler::HandleIncludeRecursive(const String& path, const Str
|
|||
ppath = Utility::DirName(GetPath()) + "/" + path;
|
||||
|
||||
std::vector<Expression *> expressions;
|
||||
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Module), GlobFile);
|
||||
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Package), GlobFile);
|
||||
return new DictExpression(expressions);
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ void ConfigCompiler::HandleIncludeZone(const String& tag, const String& path, co
|
|||
|
||||
RegisterZoneDir(tag, ppath, zoneName);
|
||||
|
||||
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, m_Module), GlobFile);
|
||||
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, m_Package), GlobFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,13 +225,13 @@ Expression *ConfigCompiler::HandleIncludeZones(const String& tag, const String&
|
|||
* @returns Configuration items.
|
||||
*/
|
||||
Expression *ConfigCompiler::CompileStream(const String& path,
|
||||
std::istream *stream, const String& zone, const String& module)
|
||||
std::istream *stream, const String& zone, const String& package)
|
||||
{
|
||||
CONTEXT("Compiling configuration stream with name '" + path + "'");
|
||||
|
||||
stream->exceptions(std::istream::badbit);
|
||||
|
||||
ConfigCompiler ctx(path, stream, zone, module);
|
||||
ConfigCompiler ctx(path, stream, zone, package);
|
||||
|
||||
try {
|
||||
return ctx.Compile();
|
||||
|
@ -249,7 +249,7 @@ Expression *ConfigCompiler::CompileStream(const String& path,
|
|||
* @returns Configuration items.
|
||||
*/
|
||||
Expression *ConfigCompiler::CompileFile(const String& path, const String& zone,
|
||||
const String& module)
|
||||
const String& package)
|
||||
{
|
||||
CONTEXT("Compiling configuration file '" + path + "'");
|
||||
|
||||
|
@ -264,7 +264,7 @@ Expression *ConfigCompiler::CompileFile(const String& path, const String& zone,
|
|||
Log(LogInformation, "ConfigCompiler")
|
||||
<< "Compiling config file: " << path;
|
||||
|
||||
return CompileStream(path, &stream, zone, module);
|
||||
return CompileStream(path, &stream, zone, package);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,10 +275,10 @@ Expression *ConfigCompiler::CompileFile(const String& path, const String& zone,
|
|||
* @returns Configuration items.
|
||||
*/
|
||||
Expression *ConfigCompiler::CompileText(const String& path, const String& text,
|
||||
const String& zone, const String& module)
|
||||
const String& zone, const String& package)
|
||||
{
|
||||
std::stringstream stream(text);
|
||||
return CompileStream(path, &stream, zone, module);
|
||||
return CompileStream(path, &stream, zone, package);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,17 +80,17 @@ class I2_CONFIG_API ConfigCompiler
|
|||
{
|
||||
public:
|
||||
explicit ConfigCompiler(const String& path, std::istream *input,
|
||||
const String& zone = String(), const String& module = String());
|
||||
const String& zone = String(), const String& package = String());
|
||||
virtual ~ConfigCompiler(void);
|
||||
|
||||
Expression *Compile(void);
|
||||
|
||||
static Expression *CompileStream(const String& path, std::istream *stream,
|
||||
const String& zone = String(), const String& module = String());
|
||||
const String& zone = String(), const String& package = String());
|
||||
static Expression *CompileFile(const String& path, const String& zone = String(),
|
||||
const String& module = String());
|
||||
const String& package = String());
|
||||
static Expression *CompileText(const String& path, const String& text,
|
||||
const String& zone = String(), const String& module = String());
|
||||
const String& zone = String(), const String& package = String());
|
||||
|
||||
static void AddIncludeSearchDir(const String& dir);
|
||||
|
||||
|
@ -99,11 +99,11 @@ public:
|
|||
void SetZone(const String& zone);
|
||||
String GetZone(void) const;
|
||||
|
||||
void SetModule(const String& module);
|
||||
String GetModule(void) const;
|
||||
void SetPackage(const String& package);
|
||||
String GetPackage(void) const;
|
||||
|
||||
static void CollectIncludes(std::vector<Expression *>& expressions,
|
||||
const String& file, const String& zone, const String& module);
|
||||
const String& file, const String& zone, const String& package);
|
||||
|
||||
/* internally used methods */
|
||||
Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
|
||||
|
@ -124,7 +124,7 @@ private:
|
|||
String m_Path;
|
||||
std::istream *m_Input;
|
||||
String m_Zone;
|
||||
String m_Module;
|
||||
String m_Package;
|
||||
|
||||
void *m_Scanner;
|
||||
|
||||
|
|
|
@ -62,11 +62,11 @@ ConfigItem::ConfigItem(const String& type, const String& name,
|
|||
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& module)
|
||||
const String& zone, const String& package)
|
||||
: 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_Module(module)
|
||||
m_Package(package)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||
dobj->SetDebugInfo(m_DebugInfo);
|
||||
dobj->SetTypeNameV(m_Type);
|
||||
dobj->SetZoneName(m_Zone);
|
||||
dobj->SetModule(m_Module);
|
||||
dobj->SetPackage(m_Package);
|
||||
dobj->SetName(m_Name);
|
||||
|
||||
DebugHint debugHints;
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
const boost::shared_ptr<Expression>& filter,
|
||||
const DebugInfo& debuginfo,
|
||||
const Dictionary::Ptr& scope, const String& zone,
|
||||
const String& module);
|
||||
const String& package);
|
||||
|
||||
String GetType(void) const;
|
||||
String GetName(void) const;
|
||||
|
@ -81,7 +81,7 @@ private:
|
|||
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||
Dictionary::Ptr m_Scope; /**< variable scope. */
|
||||
String m_Zone; /**< The zone. */
|
||||
String m_Module;
|
||||
String m_Package;
|
||||
|
||||
ConfigObject::Ptr m_Object;
|
||||
|
||||
|
|
|
@ -65,9 +65,9 @@ void ConfigItemBuilder::SetZone(const String& zone)
|
|||
m_Zone = zone;
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::SetModule(const String& module)
|
||||
void ConfigItemBuilder::SetPackage(const String& package)
|
||||
{
|
||||
m_Module = module;
|
||||
m_Package = package;
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::AddExpression(Expression *expr)
|
||||
|
@ -116,6 +116,6 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void)
|
|||
exprl->MakeInline();
|
||||
|
||||
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,
|
||||
m_DebugInfo, m_Scope, m_Zone, m_Module);
|
||||
m_DebugInfo, m_Scope, m_Zone, m_Package);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
void SetAbstract(bool abstract);
|
||||
void SetScope(const Dictionary::Ptr& scope);
|
||||
void SetZone(const String& zone);
|
||||
void SetModule(const String& module);
|
||||
void SetPackage(const String& package);
|
||||
|
||||
void AddExpression(Expression *expr);
|
||||
void SetFilter(const boost::shared_ptr<Expression>& filter);
|
||||
|
@ -63,7 +63,7 @@ private:
|
|||
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||
Dictionary::Ptr m_Scope; /**< variable scope. */
|
||||
String m_Zone; /**< The zone. */
|
||||
String m_Module; /**< The module name. */
|
||||
String m_Package; /**< The package name. */
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -749,7 +749,7 @@ ExpressionResult ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhin
|
|||
CHECK_RESULT(nameres);
|
||||
|
||||
return VMOps::NewApply(frame, m_Type, m_Target, nameres.GetValue(), m_Filter,
|
||||
m_Module, m_FKVar, m_FVVar, m_FTerm, m_ClosedVars, m_Expression, m_DebugInfo);
|
||||
m_Package, m_FKVar, m_FVVar, m_FTerm, m_ClosedVars, m_Expression, m_DebugInfo);
|
||||
}
|
||||
|
||||
ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||
|
@ -767,7 +767,7 @@ ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhi
|
|||
}
|
||||
|
||||
return VMOps::NewObject(frame, m_Abstract, m_Type, name, m_Filter, m_Zone,
|
||||
m_Module, m_ClosedVars, m_Expression, m_DebugInfo);
|
||||
m_Package, m_ClosedVars, m_Expression, m_DebugInfo);
|
||||
}
|
||||
|
||||
ExpressionResult ForExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||
|
|
|
@ -803,11 +803,11 @@ class I2_CONFIG_API ApplyExpression : public DebuggableExpression
|
|||
{
|
||||
public:
|
||||
ApplyExpression(const String& type, const String& target, Expression *name,
|
||||
Expression *filter, const String& module, const String& fkvar, const String& fvvar,
|
||||
Expression *filter, const String& package, 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_Module(module), m_FKVar(fkvar), m_FVVar(fvvar),
|
||||
m_Name(name), m_Filter(filter), m_Package(package), m_FKVar(fkvar), m_FVVar(fvvar),
|
||||
m_FTerm(fterm), m_ClosedVars(closedVars), m_Expression(expression)
|
||||
{ }
|
||||
|
||||
|
@ -824,7 +824,7 @@ private:
|
|||
String m_Target;
|
||||
Expression *m_Name;
|
||||
boost::shared_ptr<Expression> m_Filter;
|
||||
String m_Module;
|
||||
String m_Package;
|
||||
String m_FKVar;
|
||||
String m_FVVar;
|
||||
boost::shared_ptr<Expression> m_FTerm;
|
||||
|
@ -836,10 +836,10 @@ class I2_CONFIG_API ObjectExpression : public DebuggableExpression
|
|||
{
|
||||
public:
|
||||
ObjectExpression(bool abstract, const String& type, Expression *name, Expression *filter,
|
||||
const String& zone, const String& module, std::map<String, Expression *> *closedVars,
|
||||
const String& zone, const String& package, 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_Module(module), m_ClosedVars(closedVars), m_Expression(expression)
|
||||
m_Name(name), m_Filter(filter), m_Zone(zone), m_Package(package), m_ClosedVars(closedVars), m_Expression(expression)
|
||||
{ }
|
||||
|
||||
~ObjectExpression(void)
|
||||
|
@ -856,7 +856,7 @@ private:
|
|||
Expression *m_Name;
|
||||
boost::shared_ptr<Expression> m_Filter;
|
||||
String m_Zone;
|
||||
String m_Module;
|
||||
String m_Package;
|
||||
std::map<String, Expression *> *m_ClosedVars;
|
||||
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,
|
||||
const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
|
||||
const String& package, 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, module, fkvar,
|
||||
ApplyRule::AddRule(type, target, name, expression, filter, package, 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, const String& module, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
||||
const String& zone, const String& package, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
||||
{
|
||||
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
|
||||
|
||||
|
@ -147,7 +147,7 @@ public:
|
|||
item->SetAbstract(abstract);
|
||||
item->SetScope(EvaluateClosedVars(frame, closedVars));
|
||||
item->SetZone(zone);
|
||||
item->SetModule(module);
|
||||
item->SetPackage(package);
|
||||
item->SetFilter(filter);
|
||||
item->Compile()->Register();
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
|
|||
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 SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||
|
||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
|
|||
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 SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||
|
||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
|
|||
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 SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||
|
||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
|
|||
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 SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||
|
||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ set(remote_SOURCES
|
|||
actionshandler.cpp apiaction.cpp
|
||||
apifunction.cpp apilistener.cpp apilistener.thpp apilistener-sync.cpp
|
||||
apiuser.cpp apiuser.thpp authority.cpp base64.cpp
|
||||
configfileshandler.cpp configmoduleshandler.cpp configmoduleutility.cpp configobjectutility.cpp
|
||||
configfileshandler.cpp configpackageshandler.cpp configpackageutility.cpp configobjectutility.cpp
|
||||
configstageshandler.cpp createobjecthandler.cpp deleteobjecthandler.cpp
|
||||
endpoint.cpp endpoint.thpp filterutility.cpp
|
||||
httpchunkedencoding.cpp httpclientconnection.cpp httpserverconnection.cpp httphandler.cpp httprequest.cpp httpresponse.cpp
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
******************************************************************************/
|
||||
|
||||
#include "remote/configfileshandler.hpp"
|
||||
#include "remote/configmoduleutility.hpp"
|
||||
#include "remote/configpackageutility.hpp"
|
||||
#include "remote/httputility.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
@ -45,7 +45,7 @@ void ConfigFilesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& reques
|
|||
const std::vector<String>& urlPath = request.RequestUrl->GetPath();
|
||||
|
||||
if (urlPath.size() >= 4)
|
||||
params->Set("module", urlPath[3]);
|
||||
params->Set("package", urlPath[3]);
|
||||
|
||||
if (urlPath.size() >= 5)
|
||||
params->Set("stage", urlPath[4]);
|
||||
|
@ -55,22 +55,22 @@ void ConfigFilesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& reques
|
|||
params->Set("path", boost::algorithm::join(tmpPath, "/"));
|
||||
}
|
||||
|
||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
||||
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
||||
|
||||
if (!ConfigModuleUtility::ValidateName(moduleName) || !ConfigModuleUtility::ValidateName(stageName)) {
|
||||
if (!ConfigPackageUtility::ValidateName(packageName) || !ConfigPackageUtility::ValidateName(stageName)) {
|
||||
response.SetStatus(403, "Forbidden");
|
||||
return;
|
||||
}
|
||||
|
||||
String relativePath = HttpUtility::GetLastParameter(params, "path");
|
||||
|
||||
if (ConfigModuleUtility::ContainsDotDot(relativePath)) {
|
||||
if (ConfigPackageUtility::ContainsDotDot(relativePath)) {
|
||||
response.SetStatus(403, "Forbidden");
|
||||
return;
|
||||
}
|
||||
|
||||
String path = ConfigModuleUtility::GetModuleDir() + "/" + moduleName + "/" + stageName + "/" + relativePath;
|
||||
String path = ConfigPackageUtility::GetPackageDir() + "/" + packageName + "/" + stageName + "/" + relativePath;
|
||||
|
||||
if (!Utility::PathExists(path)) {
|
||||
response.SetStatus(404, "File not found");
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
******************************************************************************/
|
||||
|
||||
#include "remote/configobjectutility.hpp"
|
||||
#include "remote/configmoduleutility.hpp"
|
||||
#include "remote/configpackageutility.hpp"
|
||||
#include "config/configitembuilder.hpp"
|
||||
#include "config/configitem.hpp"
|
||||
#include "config/configwriter.hpp"
|
||||
|
@ -33,8 +33,8 @@ using namespace icinga;
|
|||
|
||||
String ConfigObjectUtility::GetConfigDir(void)
|
||||
{
|
||||
return ConfigModuleUtility::GetModuleDir() + "/_api/" +
|
||||
ConfigModuleUtility::GetActiveStage("_api");
|
||||
return ConfigPackageUtility::GetPackageDir() + "/_api/" +
|
||||
ConfigPackageUtility::GetActiveStage("_api");
|
||||
}
|
||||
|
||||
String ConfigObjectUtility::EscapeName(const String& name)
|
||||
|
@ -59,7 +59,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
|
|||
builder->SetType(type->GetName());
|
||||
builder->SetName(name);
|
||||
builder->SetScope(ScriptGlobal::GetGlobals());
|
||||
builder->SetModule("_api");
|
||||
builder->SetPackage("_api");
|
||||
|
||||
if (templates) {
|
||||
ObjectLock olock(templates);
|
||||
|
@ -116,11 +116,11 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!ConfigModuleUtility::ModuleExists("_api")) {
|
||||
ConfigModuleUtility::CreateModule("_api");
|
||||
if (!ConfigPackageUtility::PackageExists("_api")) {
|
||||
ConfigPackageUtility::CreatePackage("_api");
|
||||
|
||||
String stage = ConfigModuleUtility::CreateStage("_api");
|
||||
ConfigModuleUtility::ActivateStage("_api", stage);
|
||||
String stage = ConfigPackageUtility::CreateStage("_api");
|
||||
ConfigPackageUtility::ActivateStage("_api", stage);
|
||||
}
|
||||
|
||||
String typeDir = type->GetPluralName();
|
||||
|
@ -205,7 +205,7 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo
|
|||
|
||||
bool ConfigObjectUtility::DeleteObject(const ConfigObject::Ptr& object, bool cascade, const Array::Ptr& errors)
|
||||
{
|
||||
if (object->GetModule() != "_api") {
|
||||
if (object->GetPackage() != "_api") {
|
||||
if (errors)
|
||||
errors->Add("Object cannot be deleted because it was not created using the API.");
|
||||
|
||||
|
|
|
@ -17,16 +17,16 @@
|
|||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "remote/configmoduleshandler.hpp"
|
||||
#include "remote/configmoduleutility.hpp"
|
||||
#include "remote/configpackageshandler.hpp"
|
||||
#include "remote/configpackageutility.hpp"
|
||||
#include "remote/httputility.hpp"
|
||||
#include "base/exception.hpp"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_URLHANDLER("/v1/config/modules", ConfigModulesHandler);
|
||||
REGISTER_URLHANDLER("/v1/config/packages", ConfigPackagesHandler);
|
||||
|
||||
bool ConfigModulesHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||
bool ConfigPackagesHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
if (request.RequestUrl->GetPath().size() > 4)
|
||||
return false;
|
||||
|
@ -43,18 +43,18 @@ bool ConfigModulesHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest&
|
|||
return true;
|
||||
}
|
||||
|
||||
void ConfigModulesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||
void ConfigPackagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
std::vector<String> modules = ConfigModuleUtility::GetModules();
|
||||
std::vector<String> packages = ConfigPackageUtility::GetPackages();
|
||||
|
||||
Array::Ptr results = new Array();
|
||||
|
||||
BOOST_FOREACH(const String& module, modules) {
|
||||
Dictionary::Ptr moduleInfo = new Dictionary();
|
||||
moduleInfo->Set("name", module);
|
||||
moduleInfo->Set("stages", Array::FromVector(ConfigModuleUtility::GetStages(module)));
|
||||
moduleInfo->Set("active-stage", ConfigModuleUtility::GetActiveStage(module));
|
||||
results->Add(moduleInfo);
|
||||
BOOST_FOREACH(const String& package, packages) {
|
||||
Dictionary::Ptr packageInfo = new Dictionary();
|
||||
packageInfo->Set("name", package);
|
||||
packageInfo->Set("stages", Array::FromVector(ConfigPackageUtility::GetStages(package)));
|
||||
packageInfo->Set("active-stage", ConfigPackageUtility::GetActiveStage(package));
|
||||
results->Add(packageInfo);
|
||||
}
|
||||
|
||||
Dictionary::Ptr result = new Dictionary();
|
||||
|
@ -64,25 +64,25 @@ void ConfigModulesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& requ
|
|||
HttpUtility::SendJsonBody(response, result);
|
||||
}
|
||||
|
||||
void ConfigModulesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||
void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||
|
||||
if (request.RequestUrl->GetPath().size() >= 4)
|
||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
||||
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||
|
||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
||||
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||
|
||||
if (!ConfigModuleUtility::ValidateName(moduleName)) {
|
||||
if (!ConfigPackageUtility::ValidateName(packageName)) {
|
||||
response.SetStatus(403, "Forbidden");
|
||||
return;
|
||||
}
|
||||
|
||||
int code = 200;
|
||||
String status = "Created module.";
|
||||
String status = "Created package.";
|
||||
|
||||
try {
|
||||
ConfigModuleUtility::CreateModule(moduleName);
|
||||
ConfigPackageUtility::CreatePackage(packageName);
|
||||
} catch (const std::exception& ex) {
|
||||
code = 501;
|
||||
status = "Error: " + DiagnosticInformation(ex);
|
||||
|
@ -90,7 +90,7 @@ void ConfigModulesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& req
|
|||
|
||||
Dictionary::Ptr result1 = new Dictionary();
|
||||
|
||||
result1->Set("module", moduleName);
|
||||
result1->Set("package", packageName);
|
||||
result1->Set("code", code);
|
||||
result1->Set("status", status);
|
||||
|
||||
|
@ -104,25 +104,25 @@ void ConfigModulesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& req
|
|||
HttpUtility::SendJsonBody(response, result);
|
||||
}
|
||||
|
||||
void ConfigModulesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||
void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||
|
||||
if (request.RequestUrl->GetPath().size() >= 4)
|
||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
||||
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||
|
||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
||||
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||
|
||||
if (!ConfigModuleUtility::ValidateName(moduleName)) {
|
||||
if (!ConfigPackageUtility::ValidateName(packageName)) {
|
||||
response.SetStatus(403, "Forbidden");
|
||||
return;
|
||||
}
|
||||
|
||||
int code = 200;
|
||||
String status = "Deleted module.";
|
||||
String status = "Deleted package.";
|
||||
|
||||
try {
|
||||
ConfigModuleUtility::DeleteModule(moduleName);
|
||||
ConfigPackageUtility::DeletePackage(packageName);
|
||||
} catch (const std::exception& ex) {
|
||||
code = 501;
|
||||
status = "Error: " + DiagnosticInformation(ex);
|
||||
|
@ -130,7 +130,7 @@ void ConfigModulesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& r
|
|||
|
||||
Dictionary::Ptr result1 = new Dictionary();
|
||||
|
||||
result1->Set("module", moduleName);
|
||||
result1->Set("package", packageName);
|
||||
result1->Set("code", code);
|
||||
result1->Set("status", status);
|
||||
|
|
@ -25,10 +25,10 @@
|
|||
namespace icinga
|
||||
{
|
||||
|
||||
class I2_REMOTE_API ConfigModulesHandler : public HttpHandler
|
||||
class I2_REMOTE_API ConfigPackagesHandler : public HttpHandler
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(ConfigModulesHandler);
|
||||
DECLARE_PTR_TYPEDEFS(ConfigPackagesHandler);
|
||||
|
||||
virtual bool HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response) override;
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "remote/configmoduleutility.hpp"
|
||||
#include "remote/configpackageutility.hpp"
|
||||
#include "base/application.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include "base/scriptglobal.hpp"
|
||||
|
@ -30,66 +30,66 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
String ConfigModuleUtility::GetModuleDir(void)
|
||||
String ConfigPackageUtility::GetPackageDir(void)
|
||||
{
|
||||
return Application::GetLocalStateDir() + "/lib/icinga2/api/modules";
|
||||
return Application::GetLocalStateDir() + "/lib/icinga2/api/packages";
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::CreateModule(const String& name)
|
||||
void ConfigPackageUtility::CreatePackage(const String& name)
|
||||
{
|
||||
String path = GetModuleDir() + "/" + name;
|
||||
String path = GetPackageDir() + "/" + name;
|
||||
|
||||
if (Utility::PathExists(path))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Module already exists."));
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Package already exists."));
|
||||
|
||||
Utility::MkDirP(path, 0700);
|
||||
WriteModuleConfig(name);
|
||||
WritePackageConfig(name);
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::DeleteModule(const String& name)
|
||||
void ConfigPackageUtility::DeletePackage(const String& name)
|
||||
{
|
||||
String path = GetModuleDir() + "/" + name;
|
||||
String path = GetPackageDir() + "/" + name;
|
||||
|
||||
if (!Utility::PathExists(path))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Module does not exist."));
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Package does not exist."));
|
||||
|
||||
Utility::RemoveDirRecursive(path);
|
||||
Application::RequestRestart();
|
||||
}
|
||||
|
||||
std::vector<String> ConfigModuleUtility::GetModules(void)
|
||||
std::vector<String> ConfigPackageUtility::GetPackages(void)
|
||||
{
|
||||
std::vector<String> modules;
|
||||
Utility::Glob(GetModuleDir() + "/*", boost::bind(&ConfigModuleUtility::CollectDirNames, _1, boost::ref(modules)), GlobDirectory);
|
||||
return modules;
|
||||
std::vector<String> packages;
|
||||
Utility::Glob(GetPackageDir() + "/*", boost::bind(&ConfigPackageUtility::CollectDirNames, _1, boost::ref(packages)), GlobDirectory);
|
||||
return packages;
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::CollectDirNames(const String& path, std::vector<String>& dirs)
|
||||
void ConfigPackageUtility::CollectDirNames(const String& path, std::vector<String>& dirs)
|
||||
{
|
||||
String name = Utility::BaseName(path);
|
||||
dirs.push_back(name);
|
||||
}
|
||||
|
||||
bool ConfigModuleUtility::ModuleExists(const String& name)
|
||||
bool ConfigPackageUtility::PackageExists(const String& name)
|
||||
{
|
||||
return Utility::PathExists(GetModuleDir() + "/" + name);
|
||||
return Utility::PathExists(GetPackageDir() + "/" + name);
|
||||
}
|
||||
|
||||
String ConfigModuleUtility::CreateStage(const String& moduleName, const Dictionary::Ptr& files)
|
||||
String ConfigPackageUtility::CreateStage(const String& packageName, const Dictionary::Ptr& files)
|
||||
{
|
||||
String stageName = Utility::NewUniqueID();
|
||||
|
||||
String path = GetModuleDir() + "/" + moduleName;
|
||||
String path = GetPackageDir() + "/" + packageName;
|
||||
|
||||
if (!Utility::PathExists(path))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Module does not exist."));
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Package does not exist."));
|
||||
|
||||
path += "/" + stageName;
|
||||
|
||||
Utility::MkDirP(path, 0700);
|
||||
Utility::MkDirP(path + "/conf.d", 0700);
|
||||
Utility::MkDirP(path + "/zones.d", 0700);
|
||||
WriteStageConfig(moduleName, stageName);
|
||||
WriteStageConfig(packageName, stageName);
|
||||
|
||||
bool foundDotDot = false;
|
||||
|
||||
|
@ -103,7 +103,7 @@ String ConfigModuleUtility::CreateStage(const String& moduleName, const Dictiona
|
|||
|
||||
String filePath = path + "/" + kv.first;
|
||||
|
||||
Log(LogInformation, "ConfigModuleUtility")
|
||||
Log(LogInformation, "ConfigPackageUtility")
|
||||
<< "Updating configuration file: " << filePath;
|
||||
|
||||
//pass the directory and generate a dir tree, if not existing already
|
||||
|
@ -122,16 +122,16 @@ String ConfigModuleUtility::CreateStage(const String& moduleName, const Dictiona
|
|||
return stageName;
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::WriteModuleConfig(const String& moduleName)
|
||||
void ConfigPackageUtility::WritePackageConfig(const String& packageName)
|
||||
{
|
||||
String stageName = GetActiveStage(moduleName);
|
||||
String stageName = GetActiveStage(packageName);
|
||||
|
||||
String includePath = GetModuleDir() + "/" + moduleName + "/include.conf";
|
||||
String includePath = GetPackageDir() + "/" + packageName + "/include.conf";
|
||||
std::ofstream fpInclude(includePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||
fpInclude << "include \"*/include.conf\"\n";
|
||||
fpInclude.close();
|
||||
|
||||
String activePath = GetModuleDir() + "/" + moduleName + "/active.conf";
|
||||
String activePath = GetPackageDir() + "/" + packageName + "/active.conf";
|
||||
std::ofstream fpActive(activePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||
fpActive << "if (!globals.contains(\"ActiveStages\")) {\n"
|
||||
<< " globals.ActiveStages = {}\n"
|
||||
|
@ -139,67 +139,67 @@ void ConfigModuleUtility::WriteModuleConfig(const String& moduleName)
|
|||
<< "\n"
|
||||
<< "if (globals.contains(\"ActiveStageOverride\")) {\n"
|
||||
<< " var arr = ActiveStageOverride.split(\":\")\n"
|
||||
<< " if (arr[0] == \"" << moduleName << "\") {\n"
|
||||
<< " if (arr[0] == \"" << packageName << "\") {\n"
|
||||
<< " if (arr.len() < 2) {\n"
|
||||
<< " log(LogCritical, \"Config\", \"Invalid value for ActiveStageOverride\")\n"
|
||||
<< " } else {\n"
|
||||
<< " ActiveStages[\"" << moduleName << "\"] = arr[1]\n"
|
||||
<< " ActiveStages[\"" << packageName << "\"] = arr[1]\n"
|
||||
<< " }\n"
|
||||
<< " }\n"
|
||||
<< "}\n"
|
||||
<< "\n"
|
||||
<< "if (!ActiveStages.contains(\"" << moduleName << "\")) {\n"
|
||||
<< " ActiveStages[\"" << moduleName << "\"] = \"" << stageName << "\"\n"
|
||||
<< "if (!ActiveStages.contains(\"" << packageName << "\")) {\n"
|
||||
<< " ActiveStages[\"" << packageName << "\"] = \"" << stageName << "\"\n"
|
||||
<< "}\n";
|
||||
fpActive.close();
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::WriteStageConfig(const String& moduleName, const String& stageName)
|
||||
void ConfigPackageUtility::WriteStageConfig(const String& packageName, const String& stageName)
|
||||
{
|
||||
String path = GetModuleDir() + "/" + moduleName + "/" + stageName + "/include.conf";
|
||||
String path = GetPackageDir() + "/" + packageName + "/" + stageName + "/include.conf";
|
||||
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||
fp << "include \"../active.conf\"\n"
|
||||
<< "if (ActiveStages[\"" << moduleName << "\"] == \"" << stageName << "\") {\n"
|
||||
<< "if (ActiveStages[\"" << packageName << "\"] == \"" << stageName << "\") {\n"
|
||||
<< " include_recursive \"conf.d\"\n"
|
||||
<< " include_zones \"" << moduleName << "\", \"zones.d\"\n"
|
||||
<< " include_zones \"" << packageName << "\", \"zones.d\"\n"
|
||||
<< "}\n";
|
||||
fp.close();
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::ActivateStage(const String& moduleName, const String& stageName)
|
||||
void ConfigPackageUtility::ActivateStage(const String& packageName, const String& stageName)
|
||||
{
|
||||
String activeStagePath = GetModuleDir() + "/" + moduleName + "/active-stage";
|
||||
String activeStagePath = GetPackageDir() + "/" + packageName + "/active-stage";
|
||||
std::ofstream fpActiveStage(activeStagePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||
fpActiveStage << stageName;
|
||||
fpActiveStage.close();
|
||||
|
||||
WriteModuleConfig(moduleName);
|
||||
WritePackageConfig(packageName);
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::TryActivateStageCallback(const ProcessResult& pr, const String& moduleName, const String& stageName)
|
||||
void ConfigPackageUtility::TryActivateStageCallback(const ProcessResult& pr, const String& packageName, const String& stageName)
|
||||
{
|
||||
String logFile = GetModuleDir() + "/" + moduleName + "/" + stageName + "/startup.log";
|
||||
String logFile = GetPackageDir() + "/" + packageName + "/" + stageName + "/startup.log";
|
||||
std::ofstream fpLog(logFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||
fpLog << pr.Output;
|
||||
fpLog.close();
|
||||
|
||||
String statusFile = GetModuleDir() + "/" + moduleName + "/" + stageName + "/status";
|
||||
String statusFile = GetPackageDir() + "/" + packageName + "/" + stageName + "/status";
|
||||
std::ofstream fpStatus(statusFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||
fpStatus << pr.ExitStatus;
|
||||
fpStatus.close();
|
||||
|
||||
/* validation went fine, activate stage and reload */
|
||||
if (pr.ExitStatus == 0) {
|
||||
ActivateStage(moduleName, stageName);
|
||||
ActivateStage(packageName, stageName);
|
||||
Application::RequestRestart();
|
||||
} else {
|
||||
Log(LogCritical, "ConfigModuleUtility")
|
||||
<< "Config validation failed for module '"
|
||||
<< moduleName << "' and stage '" << stageName << "'.";
|
||||
Log(LogCritical, "ConfigPackageUtility")
|
||||
<< "Config validation failed for package '"
|
||||
<< packageName << "' and stage '" << stageName << "'.";
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::AsyncTryActivateStage(const String& moduleName, const String& stageName)
|
||||
void ConfigPackageUtility::AsyncTryActivateStage(const String& packageName, const String& stageName)
|
||||
{
|
||||
// prepare arguments
|
||||
Array::Ptr args = new Array();
|
||||
|
@ -207,36 +207,36 @@ void ConfigModuleUtility::AsyncTryActivateStage(const String& moduleName, const
|
|||
args->Add("daemon");
|
||||
args->Add("--validate");
|
||||
args->Add("--define");
|
||||
args->Add("ActiveStageOverride=" + moduleName + ":" + stageName);
|
||||
args->Add("ActiveStageOverride=" + packageName + ":" + stageName);
|
||||
|
||||
Process::Ptr process = new Process(Process::PrepareCommand(args));
|
||||
process->SetTimeout(300);
|
||||
process->Run(boost::bind(&TryActivateStageCallback, _1, moduleName, stageName));
|
||||
process->Run(boost::bind(&TryActivateStageCallback, _1, packageName, stageName));
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::DeleteStage(const String& moduleName, const String& stageName)
|
||||
void ConfigPackageUtility::DeleteStage(const String& packageName, const String& stageName)
|
||||
{
|
||||
String path = GetModuleDir() + "/" + moduleName + "/" + stageName;
|
||||
String path = GetPackageDir() + "/" + packageName + "/" + stageName;
|
||||
|
||||
if (!Utility::PathExists(path))
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Stage does not exist."));
|
||||
|
||||
if (GetActiveStage(moduleName) == stageName)
|
||||
if (GetActiveStage(packageName) == stageName)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Active stage cannot be deleted."));
|
||||
|
||||
Utility::RemoveDirRecursive(path);
|
||||
}
|
||||
|
||||
std::vector<String> ConfigModuleUtility::GetStages(const String& moduleName)
|
||||
std::vector<String> ConfigPackageUtility::GetStages(const String& packageName)
|
||||
{
|
||||
std::vector<String> stages;
|
||||
Utility::Glob(GetModuleDir() + "/" + moduleName + "/*", boost::bind(&ConfigModuleUtility::CollectDirNames, _1, boost::ref(stages)), GlobDirectory);
|
||||
Utility::Glob(GetPackageDir() + "/" + packageName + "/*", boost::bind(&ConfigPackageUtility::CollectDirNames, _1, boost::ref(stages)), GlobDirectory);
|
||||
return stages;
|
||||
}
|
||||
|
||||
String ConfigModuleUtility::GetActiveStage(const String& moduleName)
|
||||
String ConfigPackageUtility::GetActiveStage(const String& packageName)
|
||||
{
|
||||
String path = GetModuleDir() + "/" + moduleName + "/active-stage";
|
||||
String path = GetPackageDir() + "/" + packageName + "/active-stage";
|
||||
|
||||
std::ifstream fp;
|
||||
fp.open(path.CStr());
|
||||
|
@ -253,15 +253,15 @@ String ConfigModuleUtility::GetActiveStage(const String& moduleName)
|
|||
}
|
||||
|
||||
|
||||
std::vector<std::pair<String, bool> > ConfigModuleUtility::GetFiles(const String& moduleName, const String& stageName)
|
||||
std::vector<std::pair<String, bool> > ConfigPackageUtility::GetFiles(const String& packageName, const String& stageName)
|
||||
{
|
||||
std::vector<std::pair<String, bool> > paths;
|
||||
Utility::GlobRecursive(GetModuleDir() + "/" + moduleName + "/" + stageName, "*", boost::bind(&ConfigModuleUtility::CollectPaths, _1, boost::ref(paths)), GlobDirectory | GlobFile);
|
||||
Utility::GlobRecursive(GetPackageDir() + "/" + packageName + "/" + stageName, "*", boost::bind(&ConfigPackageUtility::CollectPaths, _1, boost::ref(paths)), GlobDirectory | GlobFile);
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
void ConfigModuleUtility::CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths)
|
||||
void ConfigPackageUtility::CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
struct stat statbuf;
|
||||
|
@ -286,7 +286,7 @@ void ConfigModuleUtility::CollectPaths(const String& path, std::vector<std::pair
|
|||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
bool ConfigModuleUtility::ContainsDotDot(const String& path)
|
||||
bool ConfigPackageUtility::ContainsDotDot(const String& path)
|
||||
{
|
||||
std::vector<String> tokens;
|
||||
boost::algorithm::split(tokens, path, boost::is_any_of("/\\"));
|
||||
|
@ -299,7 +299,7 @@ bool ConfigModuleUtility::ContainsDotDot(const String& path)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ConfigModuleUtility::ValidateName(const String& name)
|
||||
bool ConfigPackageUtility::ValidateName(const String& name)
|
||||
{
|
||||
if (name.IsEmpty())
|
||||
return false;
|
|
@ -35,25 +35,25 @@ namespace icinga
|
|||
*
|
||||
* @ingroup remote
|
||||
*/
|
||||
class I2_REMOTE_API ConfigModuleUtility
|
||||
class I2_REMOTE_API ConfigPackageUtility
|
||||
{
|
||||
|
||||
public:
|
||||
static String GetModuleDir(void);
|
||||
static String GetPackageDir(void);
|
||||
|
||||
static void CreateModule(const String& name);
|
||||
static void DeleteModule(const String& name);
|
||||
static std::vector<String> GetModules(void);
|
||||
static bool ModuleExists(const String& name);
|
||||
static void CreatePackage(const String& name);
|
||||
static void DeletePackage(const String& name);
|
||||
static std::vector<String> GetPackages(void);
|
||||
static bool PackageExists(const String& name);
|
||||
|
||||
static String CreateStage(const String& moduleName, const Dictionary::Ptr& files = Dictionary::Ptr());
|
||||
static void DeleteStage(const String& moduleName, const String& stageName);
|
||||
static std::vector<String> GetStages(const String& moduleName);
|
||||
static String GetActiveStage(const String& moduleName);
|
||||
static void ActivateStage(const String& moduleName, const String& stageName);
|
||||
static void AsyncTryActivateStage(const String& moduleName, const String& stageName);
|
||||
static String CreateStage(const String& packageName, const Dictionary::Ptr& files = Dictionary::Ptr());
|
||||
static void DeleteStage(const String& packageName, const String& stageName);
|
||||
static std::vector<String> GetStages(const String& packageName);
|
||||
static String GetActiveStage(const String& packageName);
|
||||
static void ActivateStage(const String& packageName, const String& stageName);
|
||||
static void AsyncTryActivateStage(const String& packageName, const String& stageName);
|
||||
|
||||
static std::vector<std::pair<String, bool> > GetFiles(const String& moduleName, const String& stageName);
|
||||
static std::vector<std::pair<String, bool> > GetFiles(const String& packageName, const String& stageName);
|
||||
|
||||
static bool ContainsDotDot(const String& path);
|
||||
static bool ValidateName(const String& name);
|
||||
|
@ -62,10 +62,10 @@ private:
|
|||
static void CollectDirNames(const String& path, std::vector<String>& dirs);
|
||||
static void CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths);
|
||||
|
||||
static void WriteModuleConfig(const String& moduleName);
|
||||
static void WriteStageConfig(const String& moduleName, const String& stageName);
|
||||
static void WritePackageConfig(const String& packageName);
|
||||
static void WriteStageConfig(const String& packageName, const String& stageName);
|
||||
|
||||
static void TryActivateStageCallback(const ProcessResult& pr, const String& moduleName, const String& stageName);
|
||||
static void TryActivateStageCallback(const ProcessResult& pr, const String& packageName, const String& stageName);
|
||||
};
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
******************************************************************************/
|
||||
|
||||
#include "remote/configstageshandler.hpp"
|
||||
#include "remote/configmoduleutility.hpp"
|
||||
#include "remote/configpackageutility.hpp"
|
||||
#include "remote/httputility.hpp"
|
||||
#include "base/application.hpp"
|
||||
#include "base/exception.hpp"
|
||||
|
@ -50,24 +50,24 @@ void ConfigStagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& reque
|
|||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||
|
||||
if (request.RequestUrl->GetPath().size() >= 4)
|
||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
||||
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||
|
||||
if (request.RequestUrl->GetPath().size() >= 5)
|
||||
params->Set("stage", request.RequestUrl->GetPath()[4]);
|
||||
|
||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
||||
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
||||
|
||||
if (!ConfigModuleUtility::ValidateName(moduleName) || !ConfigModuleUtility::ValidateName(stageName)) {
|
||||
if (!ConfigPackageUtility::ValidateName(packageName) || !ConfigPackageUtility::ValidateName(stageName)) {
|
||||
response.SetStatus(403, "Forbidden");
|
||||
return;
|
||||
}
|
||||
|
||||
Array::Ptr results = new Array();
|
||||
|
||||
std::vector<std::pair<String, bool> > paths = ConfigModuleUtility::GetFiles(moduleName, stageName);
|
||||
std::vector<std::pair<String, bool> > paths = ConfigPackageUtility::GetFiles(packageName, stageName);
|
||||
|
||||
String prefixPath = ConfigModuleUtility::GetModuleDir() + "/" + moduleName + "/" + stageName + "/";
|
||||
String prefixPath = ConfigPackageUtility::GetPackageDir() + "/" + packageName + "/" + stageName + "/";
|
||||
|
||||
typedef std::pair<String, bool> kv_pair;
|
||||
BOOST_FOREACH(const kv_pair& kv, paths) {
|
||||
|
@ -89,11 +89,11 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
|
|||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||
|
||||
if (request.RequestUrl->GetPath().size() >= 4)
|
||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
||||
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||
|
||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
||||
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||
|
||||
if (!ConfigModuleUtility::ValidateName(moduleName)) {
|
||||
if (!ConfigPackageUtility::ValidateName(packageName)) {
|
||||
response.SetStatus(403, "Forbidden");
|
||||
return;
|
||||
}
|
||||
|
@ -108,10 +108,10 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
|
|||
if (!files)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Parameter 'files' must be specified."));
|
||||
|
||||
stageName = ConfigModuleUtility::CreateStage(moduleName, files);
|
||||
stageName = ConfigPackageUtility::CreateStage(packageName, files);
|
||||
|
||||
/* validate the config. on success, activate stage and reload */
|
||||
ConfigModuleUtility::AsyncTryActivateStage(moduleName, stageName);
|
||||
ConfigPackageUtility::AsyncTryActivateStage(packageName, stageName);
|
||||
} catch (const std::exception& ex) {
|
||||
code = 501;
|
||||
status = "Error: " + DiagnosticInformation(ex);
|
||||
|
@ -119,7 +119,7 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
|
|||
|
||||
Dictionary::Ptr result1 = new Dictionary();
|
||||
|
||||
result1->Set("module", moduleName);
|
||||
result1->Set("package", packageName);
|
||||
result1->Set("stage", stageName);
|
||||
result1->Set("code", code);
|
||||
result1->Set("status", status);
|
||||
|
@ -139,15 +139,15 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re
|
|||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||
|
||||
if (request.RequestUrl->GetPath().size() >= 4)
|
||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
||||
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||
|
||||
if (request.RequestUrl->GetPath().size() >= 5)
|
||||
params->Set("stage", request.RequestUrl->GetPath()[4]);
|
||||
|
||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
||||
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
||||
|
||||
if (!ConfigModuleUtility::ValidateName(moduleName) || !ConfigModuleUtility::ValidateName(stageName)) {
|
||||
if (!ConfigPackageUtility::ValidateName(packageName) || !ConfigPackageUtility::ValidateName(stageName)) {
|
||||
response.SetStatus(403, "Forbidden");
|
||||
return;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re
|
|||
String status = "Deleted stage.";
|
||||
|
||||
try {
|
||||
ConfigModuleUtility::DeleteStage(moduleName, stageName);
|
||||
ConfigPackageUtility::DeleteStage(packageName, stageName);
|
||||
} catch (const std::exception& ex) {
|
||||
code = 501;
|
||||
status = "Error: " + DiagnosticInformation(ex);
|
||||
|
@ -164,7 +164,7 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re
|
|||
|
||||
Dictionary::Ptr result1 = new Dictionary();
|
||||
|
||||
result1->Set("module", moduleName);
|
||||
result1->Set("package", packageName);
|
||||
result1->Set("stage", stageName);
|
||||
result1->Set("code", code);
|
||||
result1->Set("status", status);
|
||||
|
|
Loading…
Reference in New Issue