mirror of https://github.com/Icinga/icinga2.git
parent
d1d488a30d
commit
4e1c754786
|
@ -236,7 +236,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||
host_imports->Add("satellite-host"); //default host node template
|
||||
host_attrs->Set("import", host_imports);
|
||||
|
||||
if (!RepositoryUtility::AddObject(object_paths, zone, "Host", host_attrs, changes)) {
|
||||
if (!RepositoryUtility::AddObject(object_paths, zone, "Host", host_attrs, changes, false)) {
|
||||
Log(LogCritical, "cli")
|
||||
<< "Cannot add node host '" << zone << "' to the config repository!\n";
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||
host_imports->Add("satellite-host"); //default host node template
|
||||
host_attrs->Set("import", host_imports);
|
||||
|
||||
RepositoryUtility::AddObject(object_paths, host, "Host", host_attrs, changes);
|
||||
RepositoryUtility::AddObject(object_paths, host, "Host", host_attrs, changes, false);
|
||||
}
|
||||
|
||||
/* special condition: what if the host was blacklisted before, but the services should be generated? */
|
||||
|
@ -353,7 +353,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||
service_imports->Add("satellite-service"); //default service node template
|
||||
service_attrs->Set("import", service_imports);
|
||||
|
||||
if (!RepositoryUtility::AddObject(object_paths, service, "Service", service_attrs, changes))
|
||||
if (!RepositoryUtility::AddObject(object_paths, service, "Service", service_attrs, changes, false))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||
Log(LogInformation, "cli")
|
||||
<< "Adding endpoint '" << endpoint << "' to the repository.";
|
||||
|
||||
if (!RepositoryUtility::AddObject(object_paths, endpoint, "Endpoint", endpoint_attrs, changes)) {
|
||||
if (!RepositoryUtility::AddObject(object_paths, endpoint, "Endpoint", endpoint_attrs, changes, false)) {
|
||||
Log(LogCritical, "cli")
|
||||
<< "Cannot add node endpoint '" << endpoint << "' to the config repository!\n";
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||
Log(LogInformation, "cli")
|
||||
<< "Adding zone '" << zone << "' to the repository.";
|
||||
|
||||
if (!RepositoryUtility::AddObject(object_paths, zone, "Zone", zone_attrs, changes)) {
|
||||
if (!RepositoryUtility::AddObject(object_paths, zone, "Zone", zone_attrs, changes, false)) {
|
||||
Log(LogCritical, "cli")
|
||||
<< "Cannot add node zone '" << zone << "' to the config repository!\n";
|
||||
}
|
||||
|
|
|
@ -548,7 +548,7 @@ bool NodeUtility::CheckAgainstBlackAndWhiteList(const String& type, const String
|
|||
{
|
||||
Array::Ptr lists = GetBlackAndWhiteList(type);
|
||||
|
||||
Log(LogInformation, "cli")
|
||||
Log(LogNotice, "cli")
|
||||
<< "Checking object against " << type << ".";
|
||||
|
||||
ObjectLock olock(lists);
|
||||
|
|
|
@ -199,7 +199,8 @@ public:
|
|||
};
|
||||
|
||||
/* modify objects and write changelog */
|
||||
bool RepositoryUtility::AddObject(const std::vector<String>& object_paths, const String& name, const String& type, const Dictionary::Ptr& attrs, const Array::Ptr& changes)
|
||||
bool RepositoryUtility::AddObject(const std::vector<String>& object_paths, const String& name, const String& type,
|
||||
const Dictionary::Ptr& attrs, const Array::Ptr& changes, bool check_config)
|
||||
{
|
||||
String pattern;
|
||||
|
||||
|
@ -227,39 +228,41 @@ bool RepositoryUtility::AddObject(const std::vector<String>& object_paths, const
|
|||
change->Set("command", "add");
|
||||
change->Set("attrs", attrs);
|
||||
|
||||
String fname, fragment;
|
||||
BOOST_FOREACH(boost::tie(fname, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
|
||||
Expression *expression = ConfigCompiler::CompileText(fname, fragment);
|
||||
if (expression) {
|
||||
ScriptFrame frame;
|
||||
expression->Evaluate(frame);
|
||||
delete expression;
|
||||
if (check_config) {
|
||||
String fname, fragment;
|
||||
BOOST_FOREACH(boost::tie(fname, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
|
||||
Expression *expression = ConfigCompiler::CompileText(fname, fragment);
|
||||
if (expression) {
|
||||
ScriptFrame frame;
|
||||
expression->Evaluate(frame);
|
||||
delete expression;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigType::Ptr ctype = ConfigType::GetByName(type);
|
||||
ConfigType::Ptr ctype = ConfigType::GetByName(type);
|
||||
|
||||
if (!ctype)
|
||||
Log(LogCritical, "cli")
|
||||
<< "No validation type available for '" << type << "'.";
|
||||
else {
|
||||
Dictionary::Ptr vattrs = attrs->ShallowClone();
|
||||
vattrs->Set("__name", vattrs->Get("name"));
|
||||
vattrs->Remove("name");
|
||||
vattrs->Remove("import");
|
||||
vattrs->Set("type", type);
|
||||
if (!ctype)
|
||||
Log(LogCritical, "cli")
|
||||
<< "No validation type available for '" << type << "'.";
|
||||
else {
|
||||
Dictionary::Ptr vattrs = attrs->ShallowClone();
|
||||
vattrs->Set("__name", vattrs->Get("name"));
|
||||
vattrs->Remove("name");
|
||||
vattrs->Remove("import");
|
||||
vattrs->Set("type", type);
|
||||
|
||||
Type::Ptr dtype = Type::GetByName(type);
|
||||
Type::Ptr dtype = Type::GetByName(type);
|
||||
|
||||
Object::Ptr object = dtype->Instantiate();
|
||||
Deserialize(object, vattrs, false, FAConfig);
|
||||
Object::Ptr object = dtype->Instantiate();
|
||||
Deserialize(object, vattrs, false, FAConfig);
|
||||
|
||||
try {
|
||||
RepositoryTypeRuleUtilities utils;
|
||||
ctype->ValidateItem(name, object, DebugInfo(), &utils);
|
||||
} catch (const ScriptError& ex) {
|
||||
Log(LogCritical, "config", DiagnosticInformation(ex));
|
||||
return false;
|
||||
try {
|
||||
RepositoryTypeRuleUtilities utils;
|
||||
ctype->ValidateItem(name, object, DebugInfo(), &utils);
|
||||
} catch (const ScriptError& ex) {
|
||||
Log(LogCritical, "config", DiagnosticInformation(ex));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,8 @@ public:
|
|||
|
||||
static void PrintChangeLog(std::ostream& fp);
|
||||
|
||||
static bool AddObject(const std::vector<String>& object_paths, const String& name, const String& type, const Dictionary::Ptr& attrs, const Array::Ptr& changes);
|
||||
static bool AddObject(const std::vector<String>& object_paths, const String& name, const String& type, const Dictionary::Ptr& attrs,
|
||||
const Array::Ptr& changes, bool check_config = true);
|
||||
static bool RemoveObject(const String& name, const String& type, const Dictionary::Ptr& attrs, const Array::Ptr& changes);
|
||||
|
||||
static bool CheckChangeExists(const Dictionary::Ptr& change, const Array::Ptr& changes);
|
||||
|
|
Loading…
Reference in New Issue