[icinga-checkins] icinga.org: icinga2/master: Config: Warn about unknown attributes.

git at icinga.org git at icinga.org
Fri Feb 1 14:12:44 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Feb  1 14:11:22 2013 +0100

Config: Warn about unknown attributes.

---

 lib/base/dynamicobject.cpp |    7 +++++++
 lib/base/dynamictype.cpp   |    7 ++++++-
 lib/base/dynamictype.h     |    1 +
 lib/icinga/host.cpp        |    2 ++
 4 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp
index dcec7be..d00d7f3 100644
--- a/lib/base/dynamicobject.cpp
+++ b/lib/base/dynamicobject.cpp
@@ -120,6 +120,13 @@ void DynamicObject::InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate,
 		Value data = attr->Get("data");
 		double tx = attr->Get("tx");
 
+		if (!HasAttribute(it->first)) {
+			DynamicType::Ptr dtype = GetType();
+			if (dtype && !dtype->HasAttribute(it->first))
+				Logger::Write(LogWarning, "base", "Adding unknown attribute '" +
+				    it->first + "' to object '" + GetName() + "' of type '" + dtype->GetName() + "'");
+		}
+
 		if (type & Attribute_Config)
 			RegisterAttribute(it->first, Attribute_Config);
 
diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp
index 9313a6d..0832885 100644
--- a/lib/base/dynamictype.cpp
+++ b/lib/base/dynamictype.cpp
@@ -111,8 +111,13 @@ void DynamicType::RemoveAttribute(const String& name)
 	m_Attributes.erase(name);
 }
 
+bool DynamicType::HasAttribute(const String& name)
+{
+	return (m_Attributes.find(name) != m_Attributes.end());
+}
+
 void DynamicType::AddAttributes(const AttributeDescription *attributes, int attributeCount)
 {
 	for (int i = 0; i < attributeCount; i++)
 		AddAttribute(attributes[i].Name, attributes[i].Type);
-}
\ No newline at end of file
+}
diff --git a/lib/base/dynamictype.h b/lib/base/dynamictype.h
index 818223b..b2bbd6e 100644
--- a/lib/base/dynamictype.h
+++ b/lib/base/dynamictype.h
@@ -59,6 +59,7 @@ public:
 
 	void AddAttribute(const String& name, DynamicAttributeType type);
 	void RemoveAttribute(const String& name);
+	bool HasAttribute(const String& name);
 
 	void AddAttributes(const AttributeDescription *attributes, int attributeCount);
 
diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp
index ec0a1da..8bf06eb 100644
--- a/lib/icinga/host.cpp
+++ b/lib/icinga/host.cpp
@@ -29,6 +29,8 @@ static AttributeDescription hostAttributes[] = {
 	{ "hostgroups", Attribute_Config },
 	{ "dependencies", Attribute_Config },
 	{ "hostchecks", Attribute_Config },
+	{ "macros", Attribute_Config },
+	{ "services", Attribute_Config },
 	{ "acknowledgement", Attribute_Replicated },
 	{ "acknowledgement_expiry", Attribute_Replicated },
 	{ "downtimes", Attribute_Replicated },





More information about the icinga-checkins mailing list