mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-13 08:44:36 +02:00
Cli: Make sure to check for removed nodes only once in 'node update-config'
fixes #7917
This commit is contained in:
parent
0f496c0b55
commit
eb4de1884c
@ -88,7 +88,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||||||
|
|
||||||
std::vector<String> object_paths = RepositoryUtility::GetObjects();
|
std::vector<String> object_paths = RepositoryUtility::GetObjects();
|
||||||
|
|
||||||
bool creation_error = false;
|
/* first make sure that all nodes are valid and should not be removed */
|
||||||
BOOST_FOREACH(const Dictionary::Ptr& node, NodeUtility::GetNodes()) {
|
BOOST_FOREACH(const Dictionary::Ptr& node, NodeUtility::GetNodes()) {
|
||||||
Dictionary::Ptr repository = node->Get("repository");
|
Dictionary::Ptr repository = node->Get("repository");
|
||||||
String zone = node->Get("zone");
|
String zone = node->Get("zone");
|
||||||
@ -97,6 +97,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||||||
|
|
||||||
/* store existing structure in index */
|
/* store existing structure in index */
|
||||||
inventory->Set(endpoint, node);
|
inventory->Set(endpoint, node);
|
||||||
|
}
|
||||||
|
|
||||||
if (old_inventory) {
|
if (old_inventory) {
|
||||||
/* check if there are objects inside the old_inventory which do not exist anymore */
|
/* check if there are objects inside the old_inventory which do not exist anymore */
|
||||||
@ -199,6 +200,13 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* next iterate over all nodes and add hosts/services */
|
||||||
|
BOOST_FOREACH(const Dictionary::Ptr& node, NodeUtility::GetNodes()) {
|
||||||
|
Dictionary::Ptr repository = node->Get("repository");
|
||||||
|
String zone = node->Get("zone");
|
||||||
|
String endpoint = node->Get("endpoint");
|
||||||
|
String node_name = endpoint;
|
||||||
|
|
||||||
Dictionary::Ptr host_services = new Dictionary();
|
Dictionary::Ptr host_services = new Dictionary();
|
||||||
|
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
@ -215,7 +223,6 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||||||
if (!RepositoryUtility::AddObject(zone, "Host", host_attrs)) {
|
if (!RepositoryUtility::AddObject(zone, "Host", host_attrs)) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Cannot add node host '" << zone << "' to the config repository!\n";
|
<< "Cannot add node host '" << zone << "' to the config repository!\n";
|
||||||
creation_error = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repository) {
|
if (repository) {
|
||||||
@ -356,7 +363,6 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||||||
if (!RepositoryUtility::AddObject(endpoint, "Endpoint", endpoint_attrs)) {
|
if (!RepositoryUtility::AddObject(endpoint, "Endpoint", endpoint_attrs)) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Cannot add node endpoint '" << endpoint << "' to the config repository!\n";
|
<< "Cannot add node endpoint '" << endpoint << "' to the config repository!\n";
|
||||||
creation_error = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr zone_attrs = new Dictionary();
|
Dictionary::Ptr zone_attrs = new Dictionary();
|
||||||
@ -392,7 +398,6 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||||||
if (!RepositoryUtility::AddObject(zone, "Zone", zone_attrs)) {
|
if (!RepositoryUtility::AddObject(zone, "Zone", zone_attrs)) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Cannot add node zone '" << zone << "' to the config repository!\n";
|
<< "Cannot add node zone '" << zone << "' to the config repository!\n";
|
||||||
creation_error = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user