From cd30cb48c834a522f720c0d683f53042efd0e8a1 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 24 Jan 2013 20:46:26 +0100 Subject: [PATCH] compatido: Update to use new *Group::GetMembers() functions Fixes #3564 --- components/compatido/compatidocomponent.cpp | 107 +++++++------------- 1 file changed, 38 insertions(+), 69 deletions(-) diff --git a/components/compatido/compatidocomponent.cpp b/components/compatido/compatidocomponent.cpp index a1113bd0b..bca11b554 100644 --- a/components/compatido/compatidocomponent.cpp +++ b/components/compatido/compatidocomponent.cpp @@ -737,103 +737,72 @@ void CompatIdoComponent::DumpConfigObjects(void) m_IdoConnection->SendMessage(msgStartConfigDump.str()); /* hosts and hostgroups */ - map > hostgroups; - DynamicObject::Ptr object; BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) { const Host::Ptr& host = static_pointer_cast(object); - Dictionary::Ptr dict; - dict = host->GetGroups(); - - if (dict) { - Value hostgroup; - BOOST_FOREACH(tie(tuples::ignore, hostgroup), dict) { - hostgroups[hostgroup].push_back(host->GetName()); - } - } - DumpHostObject(host); //FIXME remove me, debug only XXX //DisableHostObject(host); } - pair > hgt; - BOOST_FOREACH(hgt, hostgroups) { - const String& name = hgt.first; - const vector& hosts = hgt.second; + BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("HostGroup")->GetObjects()) { + const HostGroup::Ptr& hg = static_pointer_cast(object); - if (HostGroup::Exists(name)) { - HostGroup::Ptr hg = HostGroup::GetByName(name); + /* dump the hostgroup and its attributes/members to ido */ + stringstream message; + message << "\n" + << 401 << ":" << "\n" /* hostgroupdefinition */ + << 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */ + << 172 << "=" << hg->GetName() << "\n" /* hostgroupname */ + << 170 << "=" << hg->GetAlias() << "\n"; /* hostgroupalias */ - /* dump the hostgroup and its attributes/members to ido */ - stringstream message; - message << "\n" - << 401 << ":" << "\n" /* hostgroupdefinition */ - << 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */ - << 172 << "=" << name << "\n" /* hostgroupname */ - << 170 << "=" << hg->GetAlias() << "\n"; /* hostgroupalias */ + vector hglist; - SendMessageList(message, hosts, 171); /* hostgroupmember */ + BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) { + hglist.push_back(host->GetName()); + } + + SendMessageList(message, hglist, 171); /* hostgroupmember */ - message << 999 << "\n\n"; /* enddata */ + message << 999 << "\n\n"; /* enddata */ - m_IdoConnection->SendMessage(message.str()); - } + m_IdoConnection->SendMessage(message.str()); } /* services and servicegroups */ - map > servicegroups; - BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) { Service::Ptr service = static_pointer_cast(object); - Dictionary::Ptr dict; - - dict = service->GetGroups(); - - if (dict) { - Value servicegroup; - BOOST_FOREACH(tie(tuples::ignore, servicegroup), dict) { - servicegroups[servicegroup].push_back(service); - } - } - DumpServiceObject(service); //FIXME remove me, debug only XXX //DisableServiceObject(service); } - pair > sgt; - BOOST_FOREACH(sgt, servicegroups) { - const String& name = sgt.first; - const vector& services = sgt.second; - - if (ServiceGroup::Exists(name)) { - ServiceGroup::Ptr sg = ServiceGroup::GetByName(name); - - /* dump the servicegroup and its attributes/members to ido */ - stringstream message; - message << "\n" - << 403 << ":" << "\n" /* servicegroupdefinition */ - << 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */ - << 220 << "=" << name << "\n" /* servicegroupname */ - << 218 << "=" << sg->GetAlias() << "\n"; /* servicegroupalias */ - - vector sglist; - vector::iterator vt; - - BOOST_FOREACH(const Service::Ptr& service, services) { - sglist.push_back(service->GetHost()->GetName()); - sglist.push_back(service->GetAlias()); - } - - SendMessageList(message, services, 219); /* servicegroupmember */ + BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("ServiceGroup")->GetObjects()) { + const ServiceGroup::Ptr& sg = static_pointer_cast(object); - message << 999 << "\n\n"; /* enddata */ + /* dump the servicegroup and its attributes/members to ido */ + stringstream message; + message << "\n" + << 403 << ":" << "\n" /* servicegroupdefinition */ + << 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */ + << 220 << "=" << sg->GetName() << "\n" /* servicegroupname */ + << 218 << "=" << sg->GetAlias() << "\n"; /* servicegroupalias */ - m_IdoConnection->SendMessage(message.str()); + vector sglist; + vector::iterator vt; + + BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { + sglist.push_back(service->GetHost()->GetName()); + sglist.push_back(service->GetAlias()); } + + SendMessageList(message, sglist, 219); /* servicegroupmember */ + + message << 999 << "\n\n"; /* enddata */ + + m_IdoConnection->SendMessage(message.str()); } /* tell ido2db that we ended dumping the config */ -- 2.40.0