]> granicus.if.org Git - icinga2/commitdiff
compat: Add {host,service}_groups attributes.
authorMichael Friedrich <Michael.Friedrich@netways.de>
Thu, 3 Oct 2013 15:59:17 +0000 (17:59 +0200)
committerMichael Friedrich <Michael.Friedrich@netways.de>
Thu, 3 Oct 2013 15:59:17 +0000 (17:59 +0200)
components/compat/statusdatawriter.cpp
components/compat/statusdatawriter.h

index c62d7035138771e2ae419d89b7826026e589d47d..6c53b946fd4a98d967023da970daeabcbc284f94 100644 (file)
@@ -341,14 +341,29 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
 
        }
 
-       /* TODO FIXME
-       Array::Ptr groups = host->GetGroups();
-       if (groups) {
-               fp << "\t" << "hostgroups" << "\t";
-               DumpNameArray(fp, host->GetGroups());
-               fp << "\n";
-       }
-       */
+       fp << "\t" << "host_groups" << "\t";
+       bool first = true;
+
+        Array::Ptr groups = host->GetGroups();
+
+        if (groups) {
+                ObjectLock olock(groups);
+
+                BOOST_FOREACH(const String& name, groups) {
+                        HostGroup::Ptr hg = HostGroup::GetByName(name);
+
+                        if (hg) {
+                               if (!first)
+                                       fp << ",";
+                               else
+                                       first = false;
+
+                               fp << hg->GetName();
+                        }
+                }
+        }
+
+       fp << "\n";
 
        DumpCustomAttributes(fp, host);
 
@@ -497,6 +512,30 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s
                    << "\t" << "check_freshness" << "\t" << 1 << "\n";
        }
 
+       fp << "\t" << "service_groups" << "\t";
+       bool first = true;
+
+        Array::Ptr groups = service->GetGroups();
+
+        if (groups) {
+                ObjectLock olock(groups);
+
+                BOOST_FOREACH(const String& name, groups) {
+                        ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
+
+                        if (sg) {
+                               if (!first)
+                                       fp << ",";
+                               else
+                                       first = false;
+
+                               fp << sg->GetName();
+                        }
+                }
+        }
+
+       fp << "\n";
+
        DumpCustomAttributes(fp, service);
 
        fp << "\t" << "}" << "\n"
@@ -747,22 +786,6 @@ void StatusDataWriter::StatusTimerHandler(void)
        }
 }
 
-/*
-void StatusDataWriter::DumpNameArray(std::ostream& fp, const Array::Ptr& array)
-{
-       bool first = true;
-       ObjectLock olock(array);
-       BOOST_FOREACH(const Array::Ptr& obj, array) {
-               if (!first)
-                       fp << ",";
-               else
-                       first = false;
-
-               fp << obj->GetName();
-       }
-}
-*/
-
 void StatusDataWriter::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
 {
        DynamicObject::InternalSerialize(bag, attributeTypes);
index 697c4f88c86ee61736ff53690a5fdd9787e29f81..2f63b12eb557c291bce0671f0c25c1c77fa1ccf1 100644 (file)
@@ -97,8 +97,6 @@ private:
                }
        }
 
-       void DumpNameArray(std::ostream& fp, const Array::Ptr& array);
-
        void DumpServiceStatus(std::ostream& fp, const Service::Ptr& service);
        void DumpServiceObject(std::ostream& fp, const Service::Ptr& service);