[icinga-checkins] icinga.org: icinga2/master: Implement dictionary-based host/ service name pairs.

git at icinga.org git at icinga.org
Fri Feb 8 21:38:59 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Feb  8 21:30:14 2013 +0100

Implement dictionary-based host/service name pairs.

---

 lib/icinga/host.cpp    |   33 ++++++++++++++++++++-------------
 lib/icinga/host.h      |    2 +-
 lib/icinga/service.cpp |    6 +++---
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp
index c3d99cc..8be4194 100644
--- a/lib/icinga/host.cpp
+++ b/lib/icinga/host.cpp
@@ -411,20 +411,27 @@ void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vector<V
 	task->FinishResult(Empty);
 }
 
-Service::Ptr Host::GetServiceByShortName(const String& name) const
+Service::Ptr Host::GetServiceByShortName(const Value& name) const
 {
-	ValidateServicesCache();
+	if (name.IsScalar()) {
+		ValidateServicesCache();
 
-	map<String, weak_ptr<Service> >& services = m_ServicesCache[GetName()];
-	map<String, weak_ptr<Service> >::iterator it = services.find(name);
+		map<String, weak_ptr<Service> >& services = m_ServicesCache[GetName()];
+		map<String, weak_ptr<Service> >::iterator it = services.find(name);
 
-	if (it != services.end()) {
-		Service::Ptr service = it->second.lock();
-		assert(service);
-		return service;
-	}
+		if (it != services.end()) {
+			Service::Ptr service = it->second.lock();
+			assert(service);
+			return service;
+		}
 
-	return Service::GetByName(name);
+		return Service::GetByName(name);
+	} else if (name.IsObjectType<Dictionary>()) {
+		Dictionary::Ptr dict = name;
+		return GetByName(dict->Get("host"))->GetServiceByShortName(dict->Get("service"));
+	} else {
+		BOOST_THROW_EXCEPTION(invalid_argument("Host/Service name pair is invalid."));
+	}
 }
 
 set<Host::Ptr> Host::GetParentHosts(void) const
@@ -464,9 +471,9 @@ set<Service::Ptr> Host::GetParentServices(void) const
 
 	if (dependencies) {
 		String key;
-		BOOST_FOREACH(tie(key, tuples::ignore), dependencies) {
-			// TODO(#3660): look up { host = "name", service = "name" } pairs
-			parents.insert(GetServiceByShortName(key));
+		Value value;
+		BOOST_FOREACH(tie(key, value), dependencies) {
+			parents.insert(GetServiceByShortName(value));
 		}
 	}
 
diff --git a/lib/icinga/host.h b/lib/icinga/host.h
index 64ab67c..6e60d0b 100644
--- a/lib/icinga/host.h
+++ b/lib/icinga/host.h
@@ -67,7 +67,7 @@ public:
 	bool IsInDowntime(void) const;
 	bool IsUp(void) const;
 
-	shared_ptr<Service> GetServiceByShortName(const String& name) const;
+	shared_ptr<Service> GetServiceByShortName(const Value& name) const;
 
 	set<shared_ptr<Service> > GetServices(void) const;
 	static void InvalidateServicesCache(void);
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index 7651613..663a06e 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -777,9 +777,9 @@ set<Service::Ptr> Service::GetParentServices(void) const
 
 	if (dependencies) {
 		String key;
-		BOOST_FOREACH(tie(key, tuples::ignore), dependencies) {
-			// TODO(#3660): look up { host = "name", service = "name" } pairs
-			Service::Ptr service = GetHost()->GetServiceByShortName(key);
+		Value value;
+		BOOST_FOREACH(tie(key, value), dependencies) {
+			Service::Ptr service = GetHost()->GetServiceByShortName(value);
 
 			if (service->GetName() == GetName())
 				continue;





More information about the icinga-checkins mailing list