{
visibleDesc.add_options()
("name", po::value<std::string>(), "The name of the object")
- ("zone", po::value<std::string>(), "The name of the zone, e.g. the agent where this object is bound to")
- ("template", po::value<std::string>(), "Import the defined template into the object. This template must be defined and included separately in Icinga 2")
- ("name", po::value<std::string>(), "The name of the object");
+ ("template", po::value<std::vector<std::string> >(), "Import the defined template(s) into the object. Must be defined and included separately in Icinga 2");
if (m_Type == "Service") {
visibleDesc.add_options()
<< "Cannot parse passed attributes for object '" << name << "': " << boost::algorithm::join(tokens, "=");
}
- if (vm.count("zone"))
- attr->Set("zone", String(vm["zone"].as<std::string>()));
+ if (vm.count("template")) {
+ Array::Ptr templates = make_shared<Array>();
- if (vm.count("template"))
- attr->Set("templates", String(vm["template"].as<std::string>()));
+ BOOST_FOREACH(const String& tmpl, vm["template"].as<std::vector<std::string> >()) {
+ templates->Add(tmpl);
+ }
+
+ if (templates->GetLength() > 0)
+ attr->Set("templates", templates);
+ }
if (m_Command == RepositoryCommandList) {
RepositoryUtility::PrintObjects(std::cout, m_Type);
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")
{
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") {