int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap)
{
+ /*
+ * 0. Ignore not required parameters
+ */
+ if (vm.count("ticket"))
+ Log(LogWarning, "cli", "Master for Agent setup: Ignoring --ticket");
+ if (vm.count("endpoint"))
+ Log(LogWarning, "cli", "Master for Agent setup: Ignoring --endpoint");
+ if (vm.count("trustedcert"))
+ Log(LogWarning, "cli", "Master for Agent setup: Ignoring --trustedcert");
+
/*
* 1. Generate a new CA, if not already existing
*/
<< "Generating new CA.";
if (PkiUtility::NewCa() > 0) {
- Log(LogWarning, "cli", "Found CA, skipping and using the existing one.\n");
+ Log(LogWarning, "cli", "Found CA, skipping and using the existing one.");
}
/*
String pki_path = PkiUtility::GetPkiPath();
Log(LogInformation, "cli")
- << "Moving certificates to " << pki_path << ".";
+ << "Copying generated certificates to " << pki_path << ".";
String target_key = pki_path + "/" + cn + ".key";
String target_cert = pki_path + "/" + cn + ".crt";
String target_ca = pki_path + "/ca.crt";
- //TODO
- PkiUtility::CopyCertFile(key, target_key);
- PkiUtility::CopyCertFile(cert, target_cert);
- PkiUtility::CopyCertFile(ca, target_ca);
-
- std::cout << ConsoleColorTag(Console_ForegroundRed | Console_Bold) << "PLACEHOLDER" << ConsoleColorTag(Console_Normal) << std::endl;
+ /* does not overwrite existing files! */
+ Utility::CopyFile(key, target_key);
+ Utility::CopyFile(cert, target_cert);
+ Utility::CopyFile(ca, target_ca);
/*
* 4. read zones.conf and update with zone + endpoint information
Log(LogInformation, "cli", "Generating zone and object configuration.");
- std::cout << ConsoleColorTag(Console_ForegroundRed | Console_Bold) << "PLACEHOLDER" << ConsoleColorTag(Console_Normal) << std::endl;
+ AgentUtility::GenerateAgentMasterIcingaConfig(cn);
/*
* 5. enable the ApiListener config (verifiy its data)
enable.push_back("api");
FeatureUtility::EnableFeatures(enable);
+ //TODO read --listen and set that as bind_host,port on ApiListener
+
/*
* 6. tell the user to set a safe salt in api.conf
*/
}*/
+ //TODO read --listen and set that as bind_host,port on ApiListener
+
/*
* 7. generate local zones.conf with zone+endpoint
*/
return 0;
}
+int AgentUtility::GenerateAgentMasterIcingaConfig(const String& nodename)
+{
+ Array::Ptr my_config = make_shared<Array>();
+
+ /* store the local generated agent master configuration */
+ Dictionary::Ptr my_master_endpoint = make_shared<Dictionary>();
+ Dictionary::Ptr my_master_zone = make_shared<Dictionary>();
+ Array::Ptr my_master_zone_members = make_shared<Array>();
+
+ my_master_endpoint->Set("__name", nodename);
+ my_master_endpoint->Set("__type", "Endpoint");
+
+ my_master_zone_members->Add(nodename);
+
+ my_master_zone->Set("__name", "master");
+ my_master_zone->Set("__type", "Zone");
+ my_master_zone->Set("//this is the local agent master named ", "master");
+ my_master_zone->Set("endpoints", my_master_zone_members);
+
+ /* store the local config */
+ my_config->Add(my_master_endpoint);
+ my_config->Add(my_master_zone);
+
+ /* write the newly generated configuration */
+ String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf";
+
+ AgentUtility::WriteAgentConfigObjects(zones_path, my_config);
+
+ return 0;
+}
+
/*
* This is ugly and requires refactoring into a generic config writer class.
* TODO.