]> granicus.if.org Git - icinga2/commitdiff
add GetChildHosts() to host object
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 19 Jul 2013 14:11:17 +0000 (16:11 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 19 Jul 2013 14:11:17 +0000 (16:11 +0200)
lib/icinga/host.cpp
lib/icinga/host.h

index 45ee6084776b0a205dc3398b7f0ab770f8d3eb0b..4ef46cfab6ef465787b5d68bba90abf60983f09a 100644 (file)
@@ -461,6 +461,29 @@ std::set<Host::Ptr> Host::GetParentHosts(void) const
        return parents;
 }
 
+std::set<Host::Ptr> Host::GetChildHosts(void) const
+{
+       std::set<Host::Ptr> childs;
+
+        BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
+               const Host::Ptr& host = static_pointer_cast<Host>(object);
+
+               Array::Ptr dependencies = host->GetHostDependencies();
+
+               if (dependencies) {
+                       ObjectLock olock(dependencies);
+
+                       BOOST_FOREACH(const Value& value, dependencies) {
+                               if (value == GetName())
+                                       childs.insert(host);
+                       }
+               }
+       }
+
+       return childs;
+
+}
+
 Service::Ptr Host::GetHostCheckService(void) const
 {
        String host_check = GetHostCheck();
index 176cfa6c91c435d72470887b2296e5c2a4b00372..f87d304d1bd807fdf15eeb8f6caa73e937bc56b3 100644 (file)
@@ -94,6 +94,7 @@ public:
 
        shared_ptr<Service> GetHostCheckService(void) const;
        std::set<Host::Ptr> GetParentHosts(void) const;
+       std::set<Host::Ptr> GetChildHosts(void) const;
        std::set<shared_ptr<Service> > GetParentServices(void) const;
 
        bool IsReachable() const;