From: Michael Friedrich Date: Thu, 3 Oct 2013 15:59:17 +0000 (+0200) Subject: compat: Add {host,service}_groups attributes. X-Git-Tag: v0.0.3~269 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70314211622b52f46ceefae368c822ecd5bff758;p=icinga2 compat: Add {host,service}_groups attributes. --- diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index c62d70351..6c53b946f 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -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); diff --git a/components/compat/statusdatawriter.h b/components/compat/statusdatawriter.h index 697c4f88c..2f63b12eb 100644 --- a/components/compat/statusdatawriter.h +++ b/components/compat/statusdatawriter.h @@ -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);