[icinga-checkins] icinga.org: icinga2/master: Bugfixes for the type validation feature.

git at icinga.org git at icinga.org
Sat Feb 2 20:03:27 CET 2013


Module: icinga2
Branch: master
Commit: 628d8374c70a9651836f1311e95bb7f887402e28
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=628d8374c70a9651836f1311e95bb7f887402e28

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Feb  2 19:56:23 2013 +0100

Bugfixes for the type validation feature.

---

 itl/types.conf            |   25 +++++----
 lib/config/configtype.cpp |    4 +-
 lib/config/typerule.cpp   |  129 +++++++++++++++++++++++----------------------
 3 files changed, 82 insertions(+), 76 deletions(-)

diff --git a/itl/types.conf b/itl/types.conf
index d1fbb7e..585e1f9 100644
--- a/itl/types.conf
+++ b/itl/types.conf
@@ -18,23 +18,23 @@
  ******************************************************************************/
 
 type DynamicObject {
-        number __abstract,
-        number __local,
-        number __name,
-        number __type,
+	number __abstract,
+	number __local,
+	number __name,
+	number __type,
 
-        dictionary methods {
-                string *,
-        },
+	dictionary methods {
+		string *,
+	},
 
-        any custom::*
+	any custom::*
 }
 
 type Component {
 }
 
 type Logger {
-	string type,
+	string "type",
 	string path,
 	string severity
 }
@@ -71,7 +71,7 @@ type IcingaApplication {
 	string service,
 	string pid_path,
 	string state_path,
-	string macros
+	dictionary macros
 }
 
 type Service {
@@ -104,5 +104,8 @@ type ServiceGroup {
 type Endpoint {
 	string node,
 	string service,
-	number local
+	number "local"
+}
+
+type TimePeriod {
 }
diff --git a/lib/config/configtype.cpp b/lib/config/configtype.cpp
index c575337..bc23a68 100644
--- a/lib/config/configtype.cpp
+++ b/lib/config/configtype.cpp
@@ -62,8 +62,8 @@ void ConfigType::ValidateObject(const DynamicObject::Ptr& object) const
 			continue;

 

 		if (!ValidateAttribute(it->first, it->second.Data))

-			Logger::Write(LogWarning, "base", "Configuration attribute '" + it->first +

-			    "' on object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "' is unknown.");

+			Logger::Write(LogWarning, "config", "Configuration attribute '" + it->first +

+			    "' on object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "' is unknown or contains an invalid type.");

 	}

 }

 

diff --git a/lib/config/typerule.cpp b/lib/config/typerule.cpp
index d729353..59a9ad8 100644
--- a/lib/config/typerule.cpp
+++ b/lib/config/typerule.cpp
@@ -1,63 +1,66 @@
-/******************************************************************************

- * Icinga 2                                                                   *

- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *

- *                                                                            *

- * This program is free software; you can redistribute it and/or              *

- * modify it under the terms of the GNU General Public License                *

- * as published by the Free Software Foundation; either version 2             *

- * of the License, or (at your option) any later version.                     *

- *                                                                            *

- * This program is distributed in the hope that it will be useful,            *

- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *

- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *

- * GNU General Public License for more details.                               *

- *                                                                            *

- * You should have received a copy of the GNU General Public License          *

- * along with this program; if not, write to the Free Software Foundation     *

- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *

- ******************************************************************************/

-

-#include "i2-config.h"

-

-using namespace icinga;

-

-TypeRule::TypeRule(TypeSpecifier type, const String& namePattern,

-    const TypeRuleList::Ptr& subRules, const DebugInfo& debuginfo)

-	: m_Type(type), m_NamePattern(namePattern), m_SubRules(subRules), m_DebugInfo(debuginfo)

-{ }

-

-TypeRuleList::Ptr TypeRule::GetSubRules(void) const

-{

-	return m_SubRules;

-}

-

-bool TypeRule::Matches(const String& name, const Value& value) const

-{

-	if (!Utility::Match(m_NamePattern, name))

-		return false;

-

-	switch (m_Type) {

-		case TypeAny:

-			return true;

-

-		case TypeString:

-			/* fall through; any scalar can be converted to a string */

-		case TypeScalar:

-			return value.IsScalar();

-

-		case TypeNumber:

-			try {

-				Convert::ToDouble(value);

-			} catch (...) {

-				return false;

-			}

-			

-			return true;

-

-		case TypeDictionary:

-			return value.IsObjectType<Dictionary>();

-

-		default:

-			assert(!"Type rule has invalid type specifier.");

-	}

-}

+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
+ *                                                                            *
+ * This program is free software; you can redistribute it and/or              *
+ * modify it under the terms of the GNU General Public License                *
+ * as published by the Free Software Foundation; either version 2             *
+ * of the License, or (at your option) any later version.                     *
+ *                                                                            *
+ * This program is distributed in the hope that it will be useful,            *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ * GNU General Public License for more details.                               *
+ *                                                                            *
+ * You should have received a copy of the GNU General Public License          *
+ * along with this program; if not, write to the Free Software Foundation     *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
+ ******************************************************************************/
+
+#include "i2-config.h"
+
+using namespace icinga;
+
+TypeRule::TypeRule(TypeSpecifier type, const String& namePattern,
+    const TypeRuleList::Ptr& subRules, const DebugInfo& debuginfo)
+	: m_Type(type), m_NamePattern(namePattern), m_SubRules(subRules), m_DebugInfo(debuginfo)
+{ }
+
+TypeRuleList::Ptr TypeRule::GetSubRules(void) const
+{
+	return m_SubRules;
+}
+
+bool TypeRule::Matches(const String& name, const Value& value) const
+{
+	if (!Utility::Match(m_NamePattern, name))
+		return false;
+
+	if (value.IsEmpty())
+		return true;
+
+	switch (m_Type) {
+		case TypeAny:
+			return true;
+
+		case TypeString:
+			/* fall through; any scalar can be converted to a string */
+		case TypeScalar:
+			return value.IsScalar();
+
+		case TypeNumber:
+			try {
+				Convert::ToDouble(value);
+			} catch (...) {
+				return false;
+			}
+			
+			return true;
+
+		case TypeDictionary:
+			return value.IsObjectType<Dictionary>();
+
+		default:
+			assert(!"Type rule has invalid type specifier.");
+	}
+}





More information about the icinga-checkins mailing list