From: Michael Friedrich Date: Wed, 29 Oct 2014 11:03:26 +0000 (+0100) Subject: Cli: Generate a health check host if agent != host for dependencies X-Git-Tag: v2.2.0~195 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7eb7e72750fb1d2d0217981fcb826a4e232668c9;p=icinga2 Cli: Generate a health check host if agent != host for dependencies refs #7249 --- diff --git a/lib/cli/agentupdateconfigcommand.cpp b/lib/cli/agentupdateconfigcommand.cpp index 6fd0b6de7..28032283f 100644 --- a/lib/cli/agentupdateconfigcommand.cpp +++ b/lib/cli/agentupdateconfigcommand.cpp @@ -95,6 +95,26 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v Dictionary::Ptr host_services = make_shared(); + /* 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(); + 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(); + 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;