mirror of https://github.com/Icinga/icinga2.git
parent
0eead93c69
commit
83f4ebc0df
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "icinga/checkable.hpp"
|
||||
#include "icinga/checkable.tcpp"
|
||||
#include "icinga/host.hpp"
|
||||
#include "icinga/service.hpp"
|
||||
#include "base/objectlock.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include "base/exception.hpp"
|
||||
|
@ -81,7 +83,13 @@ void Checkable::AddGroup(const String& name)
|
|||
{
|
||||
boost::mutex::scoped_lock lock(m_CheckableMutex);
|
||||
|
||||
Array::Ptr groups = GetGroups();
|
||||
Array::Ptr groups;
|
||||
Host *host = dynamic_cast<Host *>(this);
|
||||
|
||||
if (host)
|
||||
groups = host->GetGroups();
|
||||
else
|
||||
groups = static_cast<Service *>(this)->GetGroups();
|
||||
|
||||
if (groups && groups->Contains(name))
|
||||
return;
|
||||
|
|
|
@ -40,9 +40,6 @@ enum AcknowledgementType
|
|||
|
||||
abstract class Checkable : CustomVarObject
|
||||
{
|
||||
[config] Array::Ptr groups {
|
||||
default {{{ return new Array(); }}}
|
||||
};
|
||||
[config, protected, required] name(CheckCommand) check_command (CheckCommandRaw);
|
||||
[config] int max_check_attempts (MaxCheckAttemptsRaw) {
|
||||
default {{{ return 3; }}}
|
||||
|
|
|
@ -25,6 +25,10 @@ namespace icinga
|
|||
|
||||
class Host : Checkable
|
||||
{
|
||||
[config] Array::Ptr groups {
|
||||
default {{{ return new Array(); }}}
|
||||
};
|
||||
|
||||
[config] String display_name {
|
||||
get {{{
|
||||
if (m_DisplayName.IsEmpty())
|
||||
|
|
|
@ -37,6 +37,10 @@ class Service : Checkable < ServiceNameComposer
|
|||
{
|
||||
load_after Host;
|
||||
|
||||
[config] Array::Ptr groups {
|
||||
default {{{ return new Array(); }}}
|
||||
};
|
||||
|
||||
[config] String display_name {
|
||||
get {{{
|
||||
if (m_DisplayName.IsEmpty())
|
||||
|
|
|
@ -645,14 +645,10 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string&
|
|||
if (validatorType != ValidatorField)
|
||||
m_Impl << "const String& key, ";
|
||||
|
||||
bool static_known_attribute = false;
|
||||
|
||||
m_Impl << fieldType.GetArgumentType() << " value, std::vector<String>& location, const ValidationUtils& utils)" << std::endl
|
||||
<< "{" << std::endl;
|
||||
|
||||
if (validatorType == ValidatorField) {
|
||||
static_known_attribute = true;
|
||||
|
||||
bool required = false;
|
||||
|
||||
for (std::vector<Rule>::size_type i = 0; i < rules.size(); i++) {
|
||||
|
@ -679,7 +675,7 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string&
|
|||
}
|
||||
}
|
||||
|
||||
if (!static_known_attribute)
|
||||
if (validatorType != ValidatorField)
|
||||
m_Impl << "\t" << "bool known_attribute = false;" << std::endl;
|
||||
|
||||
bool type_check = false;
|
||||
|
@ -703,11 +699,9 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string&
|
|||
m_Impl << "\t\t" << "if (key != \"" << rule.Pattern << "\")" << std::endl;
|
||||
|
||||
m_Impl << "\t\t\t" << "break;" << std::endl;
|
||||
} else
|
||||
static_known_attribute = true;
|
||||
}
|
||||
|
||||
if (!static_known_attribute)
|
||||
m_Impl << "\t\t" << "known_attribute = true;" << std::endl;
|
||||
m_Impl << "\t\t" << "known_attribute = true;" << std::endl;
|
||||
}
|
||||
|
||||
if (rule.IsName) {
|
||||
|
@ -824,12 +818,13 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string&
|
|||
}
|
||||
|
||||
if (type_check || validatorType != ValidatorField) {
|
||||
if (!static_known_attribute)
|
||||
if (validatorType != ValidatorField) {
|
||||
m_Impl << "\t" << "if (!known_attribute)" << std::endl
|
||||
<< "\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast<DynamicObject>(object), location, \"Invalid attribute: \" + key));" << std::endl
|
||||
<< "\t" << "else" << std::endl;
|
||||
}
|
||||
|
||||
m_Impl << (!static_known_attribute ? "\t" : "") << "\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast<DynamicObject>(object), location, \"Invalid type.\"));" << std::endl;
|
||||
m_Impl << (validatorType != ValidatorField ? "\t" : "") << "\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast<DynamicObject>(object), location, \"Invalid type.\"));" << std::endl;
|
||||
}
|
||||
|
||||
m_Impl << "}" << std::endl << std::endl;
|
||||
|
|
Loading…
Reference in New Issue