mirror of https://github.com/Icinga/icinga2.git
Cli: Always generate an agent master zone parent (setup & update-config)
refs #7423 refs #7249
This commit is contained in:
parent
57747ccdb1
commit
f72f7d87c7
|
@ -62,7 +62,7 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||
if (RepositoryUtility::ChangeLogHasPendingChanges()) {
|
||||
Log(LogWarning, "cli")
|
||||
<< "There are pending changes for commit.\n"
|
||||
<< "Please review and commit them using 'icinga2 repository commit [--simulate]\n"
|
||||
<< "Please review and commit them using 'icinga2 repository commit [--simulate]'\n"
|
||||
<< "or drop them using 'icinga2 repository commit --clear' before proceeding.";
|
||||
return 1;
|
||||
}
|
||||
|
@ -86,14 +86,13 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||
std::vector<String> object_paths = RepositoryUtility::GetObjects();
|
||||
|
||||
BOOST_FOREACH(const Dictionary::Ptr& agent, AgentUtility::GetAgents()) {
|
||||
|
||||
/* store existing structure in index */
|
||||
inventory->Set(agent->Get("endpoint"), agent);
|
||||
|
||||
Dictionary::Ptr repository = agent->Get("repository");
|
||||
String zone = agent->Get("zone");
|
||||
String endpoint = agent->Get("endpoint");
|
||||
|
||||
/* store existing structure in index */
|
||||
inventory->Set(endpoint, agent);
|
||||
|
||||
Dictionary::Ptr host_services = make_shared<Dictionary>();
|
||||
|
||||
ObjectLock olock(repository);
|
||||
|
@ -209,7 +208,17 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||
zone_attrs->Set("__name", zone);
|
||||
zone_attrs->Set("name", zone);
|
||||
zone_attrs->Set("endpoints", zone_members);
|
||||
zone_attrs->Set("parent", agent->Get("parent_zone"));
|
||||
|
||||
String parent_zone = "master"; //hardcode the name
|
||||
|
||||
if (!agent->Contains("parent_zone") || !agent->Get("parent_zone")) {
|
||||
Log(LogWarning, "cli")
|
||||
<< "Agent '" << endpoint << "' does not have any parent zone defined. Using 'master' as default. Please verify the generated configuration.";
|
||||
} else {
|
||||
parent_zone = agent->Get("parent_zone");
|
||||
}
|
||||
|
||||
zone_attrs->Set("parent", parent_zone);
|
||||
|
||||
if (!RepositoryUtility::AddObject(zone, "Zone", zone_attrs)) {
|
||||
Log(LogCritical, "cli")
|
||||
|
@ -240,7 +249,6 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||
RepositoryUtility::RemoveObject(host, "Host", host_attrs); //this removes all services for this host as well
|
||||
}
|
||||
|
||||
//TODO: Remove zone/endpoint information as well
|
||||
String zone = old_agent->Get("zone");
|
||||
String endpoint = old_agent->Get("endpoint");
|
||||
|
||||
|
|
|
@ -242,6 +242,8 @@ int AgentUtility::GenerateAgentIcingaConfig(const std::vector<std::string>& endp
|
|||
Dictionary::Ptr my_master_zone = make_shared<Dictionary>();
|
||||
Array::Ptr my_master_zone_members = make_shared<Array>();
|
||||
|
||||
String master_zone_name = "master"; //TODO: Find a better name.
|
||||
|
||||
BOOST_FOREACH(const std::string& endpoint, endpoints) {
|
||||
|
||||
/* extract all --endpoint arguments and store host,port info */
|
||||
|
@ -265,9 +267,8 @@ int AgentUtility::GenerateAgentIcingaConfig(const std::vector<std::string>& endp
|
|||
my_config->Add(my_master_endpoint);
|
||||
}
|
||||
|
||||
|
||||
/* add the master zone to the config */
|
||||
my_master_zone->Set("__name", "master"); //hardcoded name
|
||||
my_master_zone->Set("__name", master_zone_name);
|
||||
my_master_zone->Set("__type", "Zone");
|
||||
my_master_zone->Set("endpoints", my_master_zone_members);
|
||||
|
||||
|
@ -285,6 +286,7 @@ int AgentUtility::GenerateAgentIcingaConfig(const std::vector<std::string>& endp
|
|||
|
||||
my_zone->Set("__name", nodename);
|
||||
my_zone->Set("__type", "Zone");
|
||||
my_zone->Set("parent", master_zone_name); //set the master zone as parent
|
||||
my_zone->Set("//this is the local agent", nodename);
|
||||
my_zone->Set("endpoints", my_zone_members);
|
||||
|
||||
|
|
Loading…
Reference in New Issue