]> granicus.if.org Git - icinga2/commitdiff
Implement dictionary-based host/service name pairs.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 8 Feb 2013 20:30:14 +0000 (21:30 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 8 Feb 2013 20:30:14 +0000 (21:30 +0100)
lib/icinga/host.cpp
lib/icinga/host.h
lib/icinga/service.cpp

index c3d99cc3a5c4675a52162c0e9df631f1b798bba3..8be419460399c5aa7183c2138a80b8fda6165140 100644 (file)
@@ -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));
                }
        }
 
index 64ab67cb0230ddbe243f7a38a6dc9baa9c04fb93..6e60d0bc6321008f52303994f985e218758448f7 100644 (file)
@@ -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);
index 765161387446ef5f983c63a74dcfe8e1025f8d0a..663a06e0140ca9f5c137919bada4f9b1d638fe37 100644 (file)
@@ -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;