mirror of https://github.com/Icinga/icinga2.git
parent
27b15a5714
commit
1929e0c990
|
@ -121,9 +121,7 @@ void RepositoryObjectCommand::InitParameters(boost::program_options::options_des
|
||||||
{
|
{
|
||||||
visibleDesc.add_options()
|
visibleDesc.add_options()
|
||||||
("name", po::value<std::string>(), "The name of the object")
|
("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::vector<std::string> >(), "Import the defined template(s) into the object. Must be defined and included separately in Icinga 2");
|
||||||
("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");
|
|
||||||
|
|
||||||
if (m_Type == "Service") {
|
if (m_Type == "Service") {
|
||||||
visibleDesc.add_options()
|
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, "=");
|
<< "Cannot parse passed attributes for object '" << name << "': " << boost::algorithm::join(tokens, "=");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.count("zone"))
|
if (vm.count("template")) {
|
||||||
attr->Set("zone", String(vm["zone"].as<std::string>()));
|
Array::Ptr templates = make_shared<Array>();
|
||||||
|
|
||||||
if (vm.count("template"))
|
BOOST_FOREACH(const String& tmpl, vm["template"].as<std::vector<std::string> >()) {
|
||||||
attr->Set("templates", String(vm["template"].as<std::string>()));
|
templates->Add(tmpl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (templates->GetLength() > 0)
|
||||||
|
attr->Set("templates", templates);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_Command == RepositoryCommandList) {
|
if (m_Command == RepositoryCommandList) {
|
||||||
RepositoryUtility::PrintObjects(std::cout, m_Type);
|
RepositoryUtility::PrintObjects(std::cout, m_Type);
|
||||||
|
|
|
@ -43,6 +43,7 @@ String RepositoryUtility::GetRepositoryDPath(void)
|
||||||
|
|
||||||
String RepositoryUtility::GetRepositoryDObjectsPath(const String& type, const String& hostname)
|
String RepositoryUtility::GetRepositoryDObjectsPath(const String& type, const String& hostname)
|
||||||
{
|
{
|
||||||
|
//TODO find a better way to retrieve the objects path
|
||||||
if (type == "Host")
|
if (type == "Host")
|
||||||
return GetRepositoryDPath() + "/hosts";
|
return GetRepositoryDPath() + "/hosts";
|
||||||
else if (type == "Service")
|
else if (type == "Service")
|
||||||
|
@ -371,8 +372,19 @@ void RepositoryUtility::SerializeObject(std::ostream& fp, const String& name, co
|
||||||
{
|
{
|
||||||
fp << "object " << type << " \"" << name << "\" {\n";
|
fp << "object " << type << " \"" << name << "\" {\n";
|
||||||
|
|
||||||
if (object->Contains("templates"))
|
if (!object) {
|
||||||
fp << "\t" << "import \"" << object->Get("templates") << "\"\n";
|
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) {
|
BOOST_FOREACH(const Dictionary::Pair& kv, object) {
|
||||||
if (kv.first == "templates") {
|
if (kv.first == "templates") {
|
||||||
|
|
Loading…
Reference in New Issue