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;
}
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);
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")
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");
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 */
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);
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);