mirror of https://github.com/Icinga/icinga2.git
Cli: Add endpoint & zone repository object for 'agent update-config'
refs #7248
This commit is contained in:
parent
3c5645c730
commit
00652f603c
|
@ -74,6 +74,7 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||
BOOST_FOREACH(const Dictionary::Ptr& agent, AgentUtility::GetAgents()) {
|
||||
Dictionary::Ptr repository = agent->Get("repository");
|
||||
String zone = agent->Get("zone");
|
||||
String endpoint = agent->Get("endpoint");
|
||||
|
||||
ObjectLock olock(repository);
|
||||
BOOST_FOREACH(const Dictionary::Pair& kv, repository) {
|
||||
|
@ -107,6 +108,35 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* write a new zone and endpoint for the agent */
|
||||
Dictionary::Ptr endpoint_attrs = make_shared<Dictionary>();
|
||||
|
||||
Dictionary::Ptr settings = agent->Get("settings");
|
||||
|
||||
if (settings) {
|
||||
if (settings->Contains("host"))
|
||||
endpoint_attrs->Set("host", settings->Get("host"));
|
||||
if (settings->Contains("port"))
|
||||
endpoint_attrs->Set("port", settings->Get("port"));
|
||||
}
|
||||
|
||||
if (!RepositoryUtility::AddObject(endpoint, "Endpoint", endpoint_attrs)) {
|
||||
Log(LogCritical, "cli")
|
||||
<< "Cannot add agent endpoint '" << endpoint << "' to the config repository!\n";
|
||||
}
|
||||
|
||||
Dictionary::Ptr zone_attrs = make_shared<Dictionary>();
|
||||
Array::Ptr zone_members = make_shared<Array>();
|
||||
|
||||
zone_members->Add(endpoint);
|
||||
zone_attrs->Set("endpoints", zone_members);
|
||||
zone_attrs->Set("parent", agent->Get("parent_zone"));
|
||||
|
||||
if (!RepositoryUtility::AddObject(zone, "Zone", zone_attrs)) {
|
||||
Log(LogCritical, "cli")
|
||||
<< "Cannot add agent zone '" << zone << "' to the config repository!\n";
|
||||
}
|
||||
}
|
||||
|
||||
Log(LogInformation, "cli", "Committing agent configuration.");
|
||||
|
|
|
@ -84,7 +84,7 @@ String RepositoryUtility::GetRepositoryObjectConfigPath(const String& type, cons
|
|||
path += "hosts/" + object->Get("host_name");
|
||||
else if (type == "Zone")
|
||||
path += "zones";
|
||||
else if (type == "Endpoints")
|
||||
else if (type == "Endpoint")
|
||||
path += "endpoints";
|
||||
|
||||
return path;
|
||||
|
@ -181,7 +181,7 @@ void RepositoryUtility::PrintChangeLog(std::ostream& fp)
|
|||
bool RepositoryUtility::AddObject(const String& name, const String& type, const Dictionary::Ptr& attrs)
|
||||
{
|
||||
/* add a new changelog entry by timestamp */
|
||||
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(static_cast<long>(Utility::GetTime())) + "-" + SHA256(name) + ".change";
|
||||
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(Utility::GetTime()) + "-" + type + "-" + SHA256(name) + ".change";
|
||||
|
||||
Dictionary::Ptr change = make_shared<Dictionary>();
|
||||
|
||||
|
@ -197,7 +197,7 @@ bool RepositoryUtility::AddObject(const String& name, const String& type, const
|
|||
bool RepositoryUtility::RemoveObject(const String& name, const String& type, const Dictionary::Ptr& attrs)
|
||||
{
|
||||
/* add a new changelog entry by timestamp */
|
||||
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(static_cast<long>(Utility::GetTime())) + "-" + SHA256(name) + ".change";
|
||||
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(Utility::GetTime()) + "-" + type + "-" + SHA256(name) + ".change";
|
||||
|
||||
Dictionary::Ptr change = make_shared<Dictionary>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue