[icinga-checkins] icinga.org: icinga2/master: Build dependant services using extracted expression lists.

git at icinga.org git at icinga.org
Tue Mar 19 13:37:22 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Mar 19 13:37:09 2013 +0100

Build dependant services using extracted expression lists.

---

 lib/config/expression.cpp |   14 +++++++++++---
 lib/icinga/host.cpp       |   14 +++++++++++---
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp
index d411fad..3a240a7 100644
--- a/lib/config/expression.cpp
+++ b/lib/config/expression.cpp
@@ -220,10 +220,18 @@ void Expression::Extract(const std::vector<String>& path, const ExpressionList::
 	ASSERT(!path.empty());
 
 	if (path[0] == m_Key) {
-		if (path.size() > 1)
-			BOOST_THROW_EXCEPTION(std::invalid_argument("Specified path does not exist."));
-		else
+		if (path.size() == 1) {
 			result->AddExpression(*this);
+
+			return;
+		}
+
+		if (!m_Value.IsObjectType<ExpressionList>())
+			BOOST_THROW_EXCEPTION(std::invalid_argument("Specified path does not exist."));
+
+		ExpressionList::Ptr exprl = m_Value;
+		std::vector<String> sub_path(path.begin() + 1, path.end());
+		exprl->Extract(sub_path, result);
 	} else if (m_Operator == OperatorExecute) {
 		ExpressionList::Ptr exprl = m_Value;
 		exprl->Extract(path, result);
diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp
index 5ad3460..b925396 100644
--- a/lib/icinga/host.cpp
+++ b/lib/icinga/host.cpp
@@ -251,10 +251,18 @@ void Host::UpdateSlaveServices(void)
 			builder->AddExpression("display_name", OperatorSet, svcname);
 			builder->AddExpression("short_name", OperatorSet, svcname);
 
-			CopyServiceAttributes<false>(this, builder);
+			std::vector<String> path;
+			path.push_back("services");
+			path.push_back(svcname);
+
+			ExpressionList::Ptr exprl = boost::make_shared<ExpressionList>();
+			item->GetLinkedExpressionList()->Extract(path, exprl);
+			builder->AddExpressionList(exprl);
+
+			/*CopyServiceAttributes<false>(this, builder);
 
 			if (!svcdesc.IsObjectType<Dictionary>())
-				BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary."));
+				BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary."));*/
 
 			Dictionary::Ptr service = svcdesc;
 
@@ -268,7 +276,7 @@ void Host::UpdateSlaveServices(void)
 				}
 			}
 
-			CopyServiceAttributes<true>(service, builder);
+			//CopyServiceAttributes<true>(service, builder);
 
 			ConfigItem::Ptr serviceItem = builder->Compile();
 			DynamicObject::Ptr dobj = serviceItem->Commit();





More information about the icinga-checkins mailing list