diff --git a/lib/cli/repositoryobjectcommand.cpp b/lib/cli/repositoryobjectcommand.cpp index d2524113a..9cb99d077 100644 --- a/lib/cli/repositoryobjectcommand.cpp +++ b/lib/cli/repositoryobjectcommand.cpp @@ -121,9 +121,7 @@ void RepositoryObjectCommand::InitParameters(boost::program_options::options_des { visibleDesc.add_options() ("name", po::value(), "The name of the object") - ("zone", po::value(), "The name of the zone, e.g. the agent where this object is bound to") - ("template", po::value(), "Import the defined template into the object. This template must be defined and included separately in Icinga 2") - ("name", po::value(), "The name of the object"); + ("template", po::value >(), "Import the defined template(s) into the object. Must be defined and included separately in Icinga 2"); if (m_Type == "Service") { visibleDesc.add_options() @@ -172,11 +170,16 @@ int RepositoryObjectCommand::Run(const boost::program_options::variables_map& vm << "Cannot parse passed attributes for object '" << name << "': " << boost::algorithm::join(tokens, "="); } - if (vm.count("zone")) - attr->Set("zone", String(vm["zone"].as())); + if (vm.count("template")) { + Array::Ptr templates = make_shared(); - if (vm.count("template")) - attr->Set("templates", String(vm["template"].as())); + BOOST_FOREACH(const String& tmpl, vm["template"].as >()) { + templates->Add(tmpl); + } + + if (templates->GetLength() > 0) + attr->Set("templates", templates); + } if (m_Command == RepositoryCommandList) { RepositoryUtility::PrintObjects(std::cout, m_Type); diff --git a/lib/cli/repositoryutility.cpp b/lib/cli/repositoryutility.cpp index 70177f1f7..51872dc36 100644 --- a/lib/cli/repositoryutility.cpp +++ b/lib/cli/repositoryutility.cpp @@ -43,6 +43,7 @@ String RepositoryUtility::GetRepositoryDPath(void) String RepositoryUtility::GetRepositoryDObjectsPath(const String& type, const String& hostname) { + //TODO find a better way to retrieve the objects path if (type == "Host") return GetRepositoryDPath() + "/hosts"; else if (type == "Service") @@ -371,8 +372,19 @@ void RepositoryUtility::SerializeObject(std::ostream& fp, const String& name, co { fp << "object " << type << " \"" << name << "\" {\n"; - if (object->Contains("templates")) - fp << "\t" << "import \"" << object->Get("templates") << "\"\n"; + if (!object) { + fp << "}\n"; + return; + } + + if (object->Contains("templates")) { + Array::Ptr templates = object->Get("templates"); + + ObjectLock olock(templates); + BOOST_FOREACH(const String& tmpl, templates) { + fp << "\t" << "import \"" << tmpl << "\"\n"; + } + } BOOST_FOREACH(const Dictionary::Pair& kv, object) { if (kv.first == "templates") {