]> granicus.if.org Git - icinga2/commitdiff
Cli: Generate a health check host if agent != host for dependencies
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 29 Oct 2014 11:03:26 +0000 (12:03 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 29 Oct 2014 11:03:26 +0000 (12:03 +0100)
refs #7249

lib/cli/agentupdateconfigcommand.cpp

index 6fd0b6de7e2d23fd6537ce6194784587b7d77651..28032283f6b3d878633db056fca2a5c3ab4fc90f 100644 (file)
@@ -95,6 +95,26 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
 
                Dictionary::Ptr host_services = make_shared<Dictionary>();
 
+               /* if there is no health check host for this agent zone, create one */
+               if (!repository->Contains(zone)) {
+                       Log(LogInformation, "cli")
+                           << "Repository for agent '" << endpoint << "' does not contain a health check host. Adding host '" << zone << "'.";
+
+                       Dictionary::Ptr host_attrs = make_shared<Dictionary>();
+                       host_attrs->Set("__name", zone);
+                       host_attrs->Set("name", zone);
+                       host_attrs->Set("check_command", "cluster-zone");
+                       host_attrs->Set("zone", zone);
+                       Array::Ptr host_imports = make_shared<Array>();
+                       host_imports->Add("agent-host"); //default host agent template
+                       host_attrs->Set("import", host_imports);
+
+                       if (!RepositoryUtility::AddObject(zone, "Host", host_attrs)) {
+                               Log(LogCritical, "cli")
+                                   << "Cannot add agent host '" << zone << "' to the config repository!\n";
+                       }
+               }
+
                ObjectLock olock(repository);
                BOOST_FOREACH(const Dictionary::Pair& kv, repository) {
                        String host = kv.first;