mirror of https://github.com/Icinga/icinga2.git
Update validator for services dictionary.
This commit is contained in:
parent
fb82b73bc9
commit
4668e458ce
|
@ -387,36 +387,41 @@ void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vector<V
|
||||||
String key;
|
String key;
|
||||||
Value value;
|
Value value;
|
||||||
BOOST_FOREACH(tie(key, value), attrs) {
|
BOOST_FOREACH(tie(key, value), attrs) {
|
||||||
String name;
|
vector<String> templates;
|
||||||
|
|
||||||
if (value.IsScalar()) {
|
if (value.IsScalar()) {
|
||||||
name = value;
|
templates.push_back(value);
|
||||||
} else if (value.IsObjectType<Dictionary>()) {
|
} else if (value.IsObjectType<Dictionary>()) {
|
||||||
Dictionary::Ptr serviceDesc = value;
|
Dictionary::Ptr serviceDesc = value;
|
||||||
|
|
||||||
name = serviceDesc->Get("service");
|
Dictionary::Ptr templatesDict = serviceDesc->Get("templates");
|
||||||
|
ObjectLock tlock(templatesDict);
|
||||||
|
|
||||||
if (name.IsEmpty())
|
Value tmpl;
|
||||||
name = key;
|
BOOST_FOREACH(tie(tuples::ignore, tmpl), templatesDict) {
|
||||||
|
templates.push_back(tmpl);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigItem::Ptr item;
|
BOOST_FOREACH(const String& name, templates) {
|
||||||
|
ConfigItem::Ptr item;
|
||||||
|
|
||||||
ConfigCompilerContext *context = ConfigCompilerContext::GetContext();
|
ConfigCompilerContext *context = ConfigCompilerContext::GetContext();
|
||||||
|
|
||||||
if (context)
|
if (context)
|
||||||
item = context->GetItem("Service", name);
|
item = context->GetItem("Service", name);
|
||||||
|
|
||||||
/* ignore already active objects while we're in the compiler
|
/* ignore already active objects while we're in the compiler
|
||||||
* context and linking to existing items is disabled. */
|
* context and linking to existing items is disabled. */
|
||||||
if (!item && (!context || (context->GetFlags() & CompilerLinkExisting)))
|
if (!item && (!context || (context->GetFlags() & CompilerLinkExisting)))
|
||||||
item = ConfigItem::GetObject("Service", name);
|
item = ConfigItem::GetObject("Service", name);
|
||||||
|
|
||||||
if (!item) {
|
if (!item) {
|
||||||
ConfigCompilerContext::GetContext()->AddError(false, "Validation failed for " +
|
ConfigCompilerContext::GetContext()->AddError(false, "Validation failed for " +
|
||||||
location + ": Service '" + name + "' not found.");
|
location + ": Template '" + name + "' not found.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue