mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-10-26 16:53:55 +01:00 
			
		
		
		
	Bugfixes for the type validation feature.
This commit is contained in:
		
							parent
							
								
									33aba14197
								
							
						
					
					
						commit
						628d8374c7
					
				| @ -18,23 +18,23 @@ | |||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| 
 | 
 | ||||||
| type DynamicObject { | type DynamicObject { | ||||||
|         number __abstract, | 	number __abstract, | ||||||
|         number __local, | 	number __local, | ||||||
|         number __name, | 	number __name, | ||||||
|         number __type, | 	number __type, | ||||||
| 
 | 
 | ||||||
|         dictionary methods { | 	dictionary methods { | ||||||
|                 string *, | 		string *, | ||||||
|         }, | 	}, | ||||||
| 
 | 
 | ||||||
|         any custom::* | 	any custom::* | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Component { | type Component { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Logger { | type Logger { | ||||||
| 	string type, | 	string "type", | ||||||
| 	string path, | 	string path, | ||||||
| 	string severity | 	string severity | ||||||
| } | } | ||||||
| @ -71,7 +71,7 @@ type IcingaApplication { | |||||||
| 	string service, | 	string service, | ||||||
| 	string pid_path, | 	string pid_path, | ||||||
| 	string state_path, | 	string state_path, | ||||||
| 	string macros | 	dictionary macros | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Service { | type Service { | ||||||
| @ -104,5 +104,8 @@ type ServiceGroup { | |||||||
| type Endpoint { | type Endpoint { | ||||||
| 	string node, | 	string node, | ||||||
| 	string service, | 	string service, | ||||||
| 	number local | 	number "local" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type TimePeriod { | ||||||
| } | } | ||||||
|  | |||||||
| @ -62,8 +62,8 @@ void ConfigType::ValidateObject(const DynamicObject::Ptr& object) const | |||||||
| 			continue; | 			continue; | ||||||
| 
 | 
 | ||||||
| 		if (!ValidateAttribute(it->first, it->second.Data)) | 		if (!ValidateAttribute(it->first, it->second.Data)) | ||||||
| 			Logger::Write(LogWarning, "base", "Configuration attribute '" + it->first + | 			Logger::Write(LogWarning, "config", "Configuration attribute '" + it->first + | ||||||
| 			    "' on object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "' is unknown."); | 			    "' on object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "' is unknown or contains an invalid type."); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,63 +1,66 @@ | |||||||
| /******************************************************************************
 | /******************************************************************************
 | ||||||
|  * Icinga 2                                                                   * |  * Icinga 2                                                                   * | ||||||
|  * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
 |  * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
 | ||||||
|  *                                                                            * |  *                                                                            * | ||||||
|  * This program is free software; you can redistribute it and/or              * |  * This program is free software; you can redistribute it and/or              * | ||||||
|  * modify it under the terms of the GNU General Public License                * |  * modify it under the terms of the GNU General Public License                * | ||||||
|  * as published by the Free Software Foundation; either version 2             * |  * as published by the Free Software Foundation; either version 2             * | ||||||
|  * of the License, or (at your option) any later version.                     * |  * of the License, or (at your option) any later version.                     * | ||||||
|  *                                                                            * |  *                                                                            * | ||||||
|  * This program is distributed in the hope that it will be useful,            * |  * This program is distributed in the hope that it will be useful,            * | ||||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of             * |  * but WITHOUT ANY WARRANTY; without even the implied warranty of             * | ||||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              * |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              * | ||||||
|  * GNU General Public License for more details.                               * |  * GNU General Public License for more details.                               * | ||||||
|  *                                                                            * |  *                                                                            * | ||||||
|  * You should have received a copy of the GNU General Public License          * |  * You should have received a copy of the GNU General Public License          * | ||||||
|  * along with this program; if not, write to the Free Software Foundation     * |  * along with this program; if not, write to the Free Software Foundation     * | ||||||
|  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             * |  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             * | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| 
 | 
 | ||||||
| #include "i2-config.h" | #include "i2-config.h" | ||||||
| 
 | 
 | ||||||
| using namespace icinga; | using namespace icinga; | ||||||
| 
 | 
 | ||||||
| TypeRule::TypeRule(TypeSpecifier type, const String& namePattern, | TypeRule::TypeRule(TypeSpecifier type, const String& namePattern, | ||||||
|     const TypeRuleList::Ptr& subRules, const DebugInfo& debuginfo) |     const TypeRuleList::Ptr& subRules, const DebugInfo& debuginfo) | ||||||
| 	: m_Type(type), m_NamePattern(namePattern), m_SubRules(subRules), m_DebugInfo(debuginfo) | 	: m_Type(type), m_NamePattern(namePattern), m_SubRules(subRules), m_DebugInfo(debuginfo) | ||||||
| { } | { } | ||||||
| 
 | 
 | ||||||
| TypeRuleList::Ptr TypeRule::GetSubRules(void) const | TypeRuleList::Ptr TypeRule::GetSubRules(void) const | ||||||
| { | { | ||||||
| 	return m_SubRules; | 	return m_SubRules; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool TypeRule::Matches(const String& name, const Value& value) const | bool TypeRule::Matches(const String& name, const Value& value) const | ||||||
| { | { | ||||||
| 	if (!Utility::Match(m_NamePattern, name)) | 	if (!Utility::Match(m_NamePattern, name)) | ||||||
| 		return false; | 		return false; | ||||||
| 
 | 
 | ||||||
| 	switch (m_Type) { | 	if (value.IsEmpty()) | ||||||
| 		case TypeAny: | 		return true; | ||||||
| 			return true; | 
 | ||||||
| 
 | 	switch (m_Type) { | ||||||
| 		case TypeString: | 		case TypeAny: | ||||||
| 			/* fall through; any scalar can be converted to a string */ | 			return true; | ||||||
| 		case TypeScalar: | 
 | ||||||
| 			return value.IsScalar(); | 		case TypeString: | ||||||
| 
 | 			/* fall through; any scalar can be converted to a string */ | ||||||
| 		case TypeNumber: | 		case TypeScalar: | ||||||
| 			try { | 			return value.IsScalar(); | ||||||
| 				Convert::ToDouble(value); | 
 | ||||||
| 			} catch (...) { | 		case TypeNumber: | ||||||
| 				return false; | 			try { | ||||||
| 			} | 				Convert::ToDouble(value); | ||||||
| 			 | 			} catch (...) { | ||||||
| 			return true; | 				return false; | ||||||
| 
 | 			} | ||||||
| 		case TypeDictionary: | 			 | ||||||
| 			return value.IsObjectType<Dictionary>(); | 			return true; | ||||||
| 
 | 
 | ||||||
| 		default: | 		case TypeDictionary: | ||||||
| 			assert(!"Type rule has invalid type specifier."); | 			return value.IsObjectType<Dictionary>(); | ||||||
| 	} | 
 | ||||||
| } | 		default: | ||||||
|  | 			assert(!"Type rule has invalid type specifier."); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user