mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
parent
df4a31556a
commit
5b0a413f32
@ -27,8 +27,7 @@ type DynamicObject {
|
|||||||
%require "__type",
|
%require "__type",
|
||||||
%attribute string "__type",
|
%attribute string "__type",
|
||||||
|
|
||||||
%attribute dictionary "methods" {
|
%attribute dictionary "methods",
|
||||||
},
|
|
||||||
|
|
||||||
%attribute any "custom::*"
|
%attribute any "custom::*"
|
||||||
}
|
}
|
||||||
|
@ -173,6 +173,92 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary,
|
|||||||
|
|
||||||
if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
|
if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
|
||||||
ValidateDictionary(value, subRuleLists, locations);
|
ValidateDictionary(value, subRuleLists, locations);
|
||||||
|
else if (!subRuleLists.empty() && value.IsObjectType<Array>())
|
||||||
|
ValidateArray(value, subRuleLists, locations);
|
||||||
|
|
||||||
|
locations.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @threadsafety Always.
|
||||||
|
*/
|
||||||
|
void ConfigType::ValidateArray(const Array::Ptr& array,
|
||||||
|
const vector<TypeRuleList::Ptr>& ruleLists, vector<String>& locations)
|
||||||
|
{
|
||||||
|
BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) {
|
||||||
|
BOOST_FOREACH(const String& require, ruleList->GetRequires()) {
|
||||||
|
long index = Convert::ToLong(require);
|
||||||
|
|
||||||
|
locations.push_back("Attribute '" + require + "'");
|
||||||
|
|
||||||
|
if (array->GetLength() < index) {
|
||||||
|
ConfigCompilerContext::GetContext()->AddError(false,
|
||||||
|
"Required array index is missing: " + LocationToString(locations));
|
||||||
|
}
|
||||||
|
|
||||||
|
locations.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
String validator = ruleList->GetValidator();
|
||||||
|
|
||||||
|
if (!validator.IsEmpty()) {
|
||||||
|
ScriptFunction::Ptr func = ScriptFunction::GetByName(validator);
|
||||||
|
|
||||||
|
if (!func)
|
||||||
|
BOOST_THROW_EXCEPTION(invalid_argument("Validator function '" + validator + "' does not exist."));
|
||||||
|
|
||||||
|
vector<Value> arguments;
|
||||||
|
arguments.push_back(LocationToString(locations));
|
||||||
|
arguments.push_back(array);
|
||||||
|
|
||||||
|
ScriptTask::Ptr task = boost::make_shared<ScriptTask>(func, arguments);
|
||||||
|
task->Start();
|
||||||
|
task->GetResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectLock olock(array);
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
String key;
|
||||||
|
BOOST_FOREACH(const Value& value, array) {
|
||||||
|
key = Convert::ToString(index);
|
||||||
|
index++;
|
||||||
|
|
||||||
|
TypeValidationResult overallResult = ValidationUnknownField;
|
||||||
|
vector<TypeRuleList::Ptr> subRuleLists;
|
||||||
|
|
||||||
|
locations.push_back("Attribute '" + key + "'");
|
||||||
|
|
||||||
|
BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) {
|
||||||
|
TypeRuleList::Ptr subRuleList;
|
||||||
|
TypeValidationResult result = ruleList->ValidateAttribute(key, value, &subRuleList);
|
||||||
|
|
||||||
|
if (subRuleList)
|
||||||
|
subRuleLists.push_back(subRuleList);
|
||||||
|
|
||||||
|
if (overallResult == ValidationOK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (result == ValidationOK) {
|
||||||
|
overallResult = result;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == ValidationInvalidType)
|
||||||
|
overallResult = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overallResult == ValidationUnknownField)
|
||||||
|
ConfigCompilerContext::GetContext()->AddError(true, "Unknown attribute: " + LocationToString(locations));
|
||||||
|
else if (overallResult == ValidationInvalidType)
|
||||||
|
ConfigCompilerContext::GetContext()->AddError(false, "Invalid type for array index: " + LocationToString(locations));
|
||||||
|
|
||||||
|
if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
|
||||||
|
ValidateDictionary(value, subRuleLists, locations);
|
||||||
|
else if (!subRuleLists.empty() && value.IsObjectType<Array>())
|
||||||
|
ValidateArray(value, subRuleLists, locations);
|
||||||
|
|
||||||
locations.pop_back();
|
locations.pop_back();
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,8 @@ private:
|
|||||||
|
|
||||||
static void ValidateDictionary(const Dictionary::Ptr& dictionary,
|
static void ValidateDictionary(const Dictionary::Ptr& dictionary,
|
||||||
const vector<TypeRuleList::Ptr>& ruleLists, vector<String>& locations);
|
const vector<TypeRuleList::Ptr>& ruleLists, vector<String>& locations);
|
||||||
|
static void ValidateArray(const Array::Ptr& array,
|
||||||
|
const vector<TypeRuleList::Ptr>& ruleLists, vector<String>& locations);
|
||||||
|
|
||||||
static String LocationToString(const vector<String>& locations);
|
static String LocationToString(const vector<String>& locations);
|
||||||
};
|
};
|
||||||
|
@ -20,14 +20,28 @@
|
|||||||
type Host {
|
type Host {
|
||||||
%attribute string "display_name",
|
%attribute string "display_name",
|
||||||
%attribute string "hostcheck",
|
%attribute string "hostcheck",
|
||||||
%attribute array "hostgroups",
|
%attribute array "hostgroups" {
|
||||||
%attribute array "hostdependencies",
|
%attribute string "*"
|
||||||
%attribute array "servicedependencies",
|
},
|
||||||
|
%attribute array "hostdependencies" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
%attribute array "servicedependencies" {
|
||||||
|
%attribute dictionary "*" {
|
||||||
|
%require "host",
|
||||||
|
%attribute string "host",
|
||||||
|
|
||||||
|
%require "service",
|
||||||
|
%attribute string "service"
|
||||||
|
}
|
||||||
|
},
|
||||||
%attribute dictionary "services" {
|
%attribute dictionary "services" {
|
||||||
%validator "ValidateServiceDictionary",
|
%validator "ValidateServiceDictionary",
|
||||||
|
|
||||||
%attribute dictionary "*" {
|
%attribute dictionary "*" {
|
||||||
%attribute array "templates",
|
%attribute array "templates" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
|
||||||
%attribute string "short_name",
|
%attribute string "short_name",
|
||||||
|
|
||||||
@ -39,23 +53,43 @@ type Host {
|
|||||||
%attribute number "check_interval",
|
%attribute number "check_interval",
|
||||||
%attribute number "retry_interval",
|
%attribute number "retry_interval",
|
||||||
|
|
||||||
%attribute array "servicegroups",
|
%attribute array "servicegroups" {
|
||||||
%attribute array "checkers",
|
%attribute string "*"
|
||||||
%attribute array "hostdependencies",
|
},
|
||||||
%attribute array "servicedependencies"
|
%attribute array "checkers" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
%attribute array "hostdependencies" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
%attribute array "servicedependencies" {
|
||||||
|
%attribute dictionary "*" {
|
||||||
|
%require "host",
|
||||||
|
%attribute string "host",
|
||||||
|
|
||||||
|
%require "service",
|
||||||
|
%attribute string "service"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
%attribute dictionary "notifications" {
|
%attribute dictionary "notifications" {
|
||||||
%attribute dictionary "*" {
|
%attribute dictionary "*" {
|
||||||
%attribute array "templates",
|
%attribute array "templates" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
|
||||||
%attribute dictionary "macros" {
|
%attribute dictionary "macros" {
|
||||||
%attribute string "*"
|
%attribute string "*"
|
||||||
},
|
},
|
||||||
|
|
||||||
%attribute array "users",
|
%attribute array "users" {
|
||||||
%attribute array "groups"
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
%attribute array "groups" {
|
||||||
|
%attribute string "*"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -68,8 +102,12 @@ type Host {
|
|||||||
%attribute dictionary "macros" {
|
%attribute dictionary "macros" {
|
||||||
%attribute string "*"
|
%attribute string "*"
|
||||||
},
|
},
|
||||||
%attribute array "servicegroups",
|
%attribute array "servicegroups" {
|
||||||
%attribute array "checkers"
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
%attribute array "checkers" {
|
||||||
|
%attribute string "*"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type HostGroup {
|
type HostGroup {
|
||||||
@ -98,16 +136,32 @@ type Service {
|
|||||||
%attribute dictionary "macros" {
|
%attribute dictionary "macros" {
|
||||||
%attribute string "*"
|
%attribute string "*"
|
||||||
},
|
},
|
||||||
%attribute array "check_command",
|
%attribute array "check_command" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
%attribute string "check_command",
|
%attribute string "check_command",
|
||||||
%attribute number "max_check_attempts",
|
%attribute number "max_check_attempts",
|
||||||
%attribute string "check_period",
|
%attribute string "check_period",
|
||||||
%attribute number "check_interval",
|
%attribute number "check_interval",
|
||||||
%attribute number "retry_interval",
|
%attribute number "retry_interval",
|
||||||
%attribute array "hostdependencies",
|
%attribute array "hostdependencies" {
|
||||||
%attribute array "servicedependencies",
|
%attribute string "*"
|
||||||
%attribute array "servicegroups",
|
},
|
||||||
%attribute array "checkers",
|
%attribute array "servicedependencies" {
|
||||||
|
%attribute dictionary "*" {
|
||||||
|
%require "host",
|
||||||
|
%attribute string "host",
|
||||||
|
|
||||||
|
%require "service",
|
||||||
|
%attribute string "service"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
%attribute array "servicegroups" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
%attribute array "checkers" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
|
||||||
%require "methods",
|
%require "methods",
|
||||||
%attribute dictionary "methods" {
|
%attribute dictionary "methods" {
|
||||||
@ -117,14 +171,20 @@ type Service {
|
|||||||
|
|
||||||
%attribute dictionary "notifications" {
|
%attribute dictionary "notifications" {
|
||||||
%attribute dictionary "*" {
|
%attribute dictionary "*" {
|
||||||
%attribute array "templates",
|
%attribute array "templates" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
|
||||||
%attribute dictionary "macros" {
|
%attribute dictionary "macros" {
|
||||||
%attribute string "*"
|
%attribute string "*"
|
||||||
},
|
},
|
||||||
|
|
||||||
%attribute array "users",
|
%attribute array "users" {
|
||||||
%attribute array "groups"
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
%attribute array "groups" {
|
||||||
|
%attribute string "*"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -152,10 +212,16 @@ type Notification {
|
|||||||
%attribute string "*"
|
%attribute string "*"
|
||||||
},
|
},
|
||||||
|
|
||||||
%attribute array "users",
|
%attribute array "users" {
|
||||||
%attribute array "groups",
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
%attribute array "groups" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
|
|
||||||
%attribute array "notification_command",
|
%attribute array "notification_command" {
|
||||||
|
%attribute string "*"
|
||||||
|
},
|
||||||
%attribute string "notification_command"
|
%attribute string "notification_command"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +232,9 @@ type User {
|
|||||||
%attribute string "*"
|
%attribute string "*"
|
||||||
},
|
},
|
||||||
|
|
||||||
%attribute array "groups"
|
%attribute array "groups" {
|
||||||
|
%attribute string "*"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserGroup {
|
type UserGroup {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user