From: Gunnar Beutner Date: Fri, 8 Feb 2013 20:30:14 +0000 (+0100) Subject: Implement dictionary-based host/service name pairs. X-Git-Tag: v0.0.2~494 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e443b77a566dd849855339489ef9e0aa2bb91d94;p=icinga2 Implement dictionary-based host/service name pairs. --- diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index c3d99cc3a..8be419460 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -411,20 +411,27 @@ void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vectorFinishResult(Empty); } -Service::Ptr Host::GetServiceByShortName(const String& name) const +Service::Ptr Host::GetServiceByShortName(const Value& name) const { - ValidateServicesCache(); + if (name.IsScalar()) { + ValidateServicesCache(); - map >& services = m_ServicesCache[GetName()]; - map >::iterator it = services.find(name); + map >& services = m_ServicesCache[GetName()]; + map >::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::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::GetParentHosts(void) const @@ -464,9 +471,9 @@ set 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 64ab67cb0..6e60d0bc6 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 GetServiceByShortName(const String& name) const; + shared_ptr GetServiceByShortName(const Value& name) const; set > GetServices(void) const; static void InvalidateServicesCache(void); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 765161387..663a06e01 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -777,9 +777,9 @@ set 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;