mirror of https://github.com/Icinga/icinga2.git
parent
8c36a71fe2
commit
57883ce8ae
|
@ -103,6 +103,16 @@ int AgentSetupCommand::Run(const boost::program_options::variables_map& vm, cons
|
|||
|
||||
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
|
||||
*/
|
||||
|
@ -111,7 +121,7 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
|
|||
<< "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.");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -148,18 +158,16 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
|
|||
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
|
||||
|
@ -167,7 +175,7 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
|
|||
|
||||
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)
|
||||
|
@ -183,6 +191,8 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
|
|||
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
|
||||
*/
|
||||
|
@ -345,6 +355,8 @@ int AgentSetupCommand::SetupAgent(const boost::program_options::variables_map& v
|
|||
}*/
|
||||
|
||||
|
||||
//TODO read --listen and set that as bind_host,port on ApiListener
|
||||
|
||||
/*
|
||||
* 7. generate local zones.conf with zone+endpoint
|
||||
*/
|
||||
|
|
|
@ -325,6 +325,37 @@ int AgentUtility::GenerateAgentIcingaConfig(const std::vector<std::string>& endp
|
|||
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.
|
||||
|
|
|
@ -58,8 +58,10 @@ public:
|
|||
|
||||
static bool WriteAgentConfigObjects(const String& filename, const Array::Ptr& objects);
|
||||
|
||||
|
||||
/* agent setup helpers */
|
||||
static int GenerateAgentIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename);
|
||||
static int GenerateAgentMasterIcingaConfig(const String& nodename);
|
||||
|
||||
private:
|
||||
AgentUtility(void);
|
||||
|
|
|
@ -257,22 +257,3 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool PkiUtility::CopyCertFile(const String& source, const String& target)
|
||||
{
|
||||
/*
|
||||
if (PathExists(target)) {
|
||||
Log(LogWarning, "Utility")
|
||||
<< "Target file '" << target << "' already exists.";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream ifs(source, std::ios::binary);
|
||||
std::ofstream ofs(target, std::ios::binary);
|
||||
|
||||
ofs << ifs.rdbuf();
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -45,8 +45,6 @@ public:
|
|||
static int RequestCertificate(const String& host, const String& port, const String& keyfile,
|
||||
const String& certfile, const String& cafile, const String& trustedfile, const String& ticket);
|
||||
|
||||
static bool CopyCertFile(const String& source, const String& target);
|
||||
|
||||
private:
|
||||
PkiUtility(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue