mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-29 00:24:23 +02:00
Reformat code
CLion is now pretty close at what we use with Icinga, other changes do make sense to me.
This commit is contained in:
parent
8f411c7475
commit
0456298c58
@ -68,12 +68,13 @@ void RedisWriter::UpdateAllConfigObjects(void)
|
|||||||
if (!ctype)
|
if (!ctype)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto lcType (type->GetName().ToLower());
|
auto lcType(type->GetName().ToLower());
|
||||||
|
|
||||||
ExecuteQuery({ "MULTI" });
|
ExecuteQuery({"MULTI"});
|
||||||
|
|
||||||
/* Delete obsolete object keys first. */
|
/* Delete obsolete object keys first. */
|
||||||
ExecuteQuery({"DEL", m_PrefixConfigCheckSum + lcType, m_PrefixConfigObject + lcType, m_PrefixStatusObject + lcType});
|
ExecuteQuery(
|
||||||
|
{"DEL", m_PrefixConfigCheckSum + lcType, m_PrefixConfigObject + lcType, m_PrefixStatusObject + lcType});
|
||||||
|
|
||||||
/* fetch all objects and dump them */
|
/* fetch all objects and dump them */
|
||||||
for (const ConfigObject::Ptr& object : ctype->GetObjects()) {
|
for (const ConfigObject::Ptr& object : ctype->GetObjects()) {
|
||||||
@ -82,13 +83,13 @@ void RedisWriter::UpdateAllConfigObjects(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* publish config type dump finished */
|
/* publish config type dump finished */
|
||||||
ExecuteQuery({ "PUBLISH", "icinga:config:dump", lcType });
|
ExecuteQuery({"PUBLISH", "icinga:config:dump", lcType});
|
||||||
|
|
||||||
ExecuteQuery({ "EXEC" });
|
ExecuteQuery({"EXEC"});
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogInformation, "RedisWriter")
|
Log(LogInformation, "RedisWriter")
|
||||||
<< "Initial config/status dump finished in " << Utility::GetTime() - startTime << " seconds.";
|
<< "Initial config/status dump finished in " << Utility::GetTime() - startTime << " seconds.";
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConfigObject::Ptr GetHostGroup(const String& name)
|
static ConfigObject::Ptr GetHostGroup(const String& name)
|
||||||
@ -125,7 +126,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (useTransaction)
|
if (useTransaction)
|
||||||
ExecuteQuery({ "MULTI" });
|
ExecuteQuery({"MULTI"});
|
||||||
|
|
||||||
/* Calculate object specific checksums and store them in a different namespace. */
|
/* Calculate object specific checksums and store them in a different namespace. */
|
||||||
Type::Ptr type = object->GetReflectionType();
|
Type::Ptr type = object->GetReflectionType();
|
||||||
@ -133,24 +134,24 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
String typeName = type->GetName().ToLower();
|
String typeName = type->GetName().ToLower();
|
||||||
String objectKey = GetObjectIdentifier(object);
|
String objectKey = GetObjectIdentifier(object);
|
||||||
|
|
||||||
std::set<String> propertiesBlacklist ({"name", "__name", "package", "source_location", "templates"});
|
std::set<String> propertiesBlacklist({"name", "__name", "package", "source_location", "templates"});
|
||||||
|
|
||||||
Dictionary::Ptr checkSums = new Dictionary();
|
Dictionary::Ptr checkSums = new Dictionary();
|
||||||
|
|
||||||
checkSums->Set("name_checksum", CalculateCheckSumString(object->GetShortName()));
|
checkSums->Set("name_checksum", CalculateCheckSumString(object->GetShortName()));
|
||||||
checkSums->Set("environment_checksum", CalculateCheckSumString(GetEnvironment()));
|
checkSums->Set("environment_checksum", CalculateCheckSumString(GetEnvironment()));
|
||||||
|
|
||||||
auto endpoint (dynamic_pointer_cast<Endpoint>(object));
|
auto endpoint(dynamic_pointer_cast<Endpoint>(object));
|
||||||
|
|
||||||
if (endpoint) {
|
if (endpoint) {
|
||||||
auto endpointZone (endpoint->GetZone());
|
auto endpointZone(endpoint->GetZone());
|
||||||
|
|
||||||
if (endpointZone) {
|
if (endpointZone) {
|
||||||
checkSums->Set("zone_checksum", GetObjectIdentifier(endpointZone));
|
checkSums->Set("zone_checksum", GetObjectIdentifier(endpointZone));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* 'zone' is available for all config objects, therefore calculate the checksum. */
|
/* 'zone' is available for all config objects, therefore calculate the checksum. */
|
||||||
auto zone (static_pointer_cast<Zone>(object->GetZone()));
|
auto zone(static_pointer_cast<Zone>(object->GetZone()));
|
||||||
|
|
||||||
if (zone)
|
if (zone)
|
||||||
checkSums->Set("zone_checksum", GetObjectIdentifier(zone));
|
checkSums->Set("zone_checksum", GetObjectIdentifier(zone));
|
||||||
@ -171,8 +172,8 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
|
|
||||||
Array::Ptr groupChecksums = new Array();
|
Array::Ptr groupChecksums = new Array();
|
||||||
|
|
||||||
ObjectLock groupsLock (groups);
|
ObjectLock groupsLock(groups);
|
||||||
ObjectLock groupChecksumsLock (groupChecksums);
|
ObjectLock groupChecksumsLock(groupChecksums);
|
||||||
|
|
||||||
for (auto group : groups) {
|
for (auto group : groups) {
|
||||||
groupChecksums->Add(GetObjectIdentifier((*getGroup)(group.Get<String>())));
|
groupChecksums->Add(GetObjectIdentifier((*getGroup)(group.Get<String>())));
|
||||||
@ -180,7 +181,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
|
|
||||||
checkSums->Set("group_checksums", groupChecksums);
|
checkSums->Set("group_checksums", groupChecksums);
|
||||||
|
|
||||||
auto period (user->GetPeriod());
|
auto period(user->GetPeriod());
|
||||||
|
|
||||||
if (period)
|
if (period)
|
||||||
checkSums->Set("period_checksum", GetObjectIdentifier(period));
|
checkSums->Set("period_checksum", GetObjectIdentifier(period));
|
||||||
@ -191,10 +192,10 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
if (notification) {
|
if (notification) {
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
auto users (notification->GetUsers());
|
auto users(notification->GetUsers());
|
||||||
Array::Ptr userChecksums = new Array();
|
Array::Ptr userChecksums = new Array();
|
||||||
Array::Ptr userNames = new Array();
|
Array::Ptr userNames = new Array();
|
||||||
auto usergroups (notification->GetUserGroups());
|
auto usergroups(notification->GetUserGroups());
|
||||||
Array::Ptr usergroupChecksums = new Array();
|
Array::Ptr usergroupChecksums = new Array();
|
||||||
Array::Ptr usergroupNames = new Array();
|
Array::Ptr usergroupNames = new Array();
|
||||||
|
|
||||||
@ -263,8 +264,8 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
|
|
||||||
Array::Ptr groupChecksums = new Array();
|
Array::Ptr groupChecksums = new Array();
|
||||||
|
|
||||||
ObjectLock groupsLock (groups);
|
ObjectLock groupsLock(groups);
|
||||||
ObjectLock groupChecksumsLock (groupChecksums);
|
ObjectLock groupChecksumsLock(groupChecksums);
|
||||||
|
|
||||||
for (auto group : groups) {
|
for (auto group : groups) {
|
||||||
groupChecksums->Add(GetObjectIdentifier((*getGroup)(group.Get<String>())));
|
groupChecksums->Add(GetObjectIdentifier((*getGroup)(group.Get<String>())));
|
||||||
@ -314,7 +315,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
|
|
||||||
checkSums->Set("endpoints_checksum", CalculateCheckSumArray(endpoints));
|
checkSums->Set("endpoints_checksum", CalculateCheckSumArray(endpoints));
|
||||||
|
|
||||||
Array::Ptr parents (new Array);
|
Array::Ptr parents(new Array);
|
||||||
|
|
||||||
for (auto& parent : zone->GetAllParentsRaw()) {
|
for (auto& parent : zone->GetAllParentsRaw()) {
|
||||||
parents->Add(GetObjectIdentifier(parent));
|
parents->Add(GetObjectIdentifier(parent));
|
||||||
@ -325,14 +326,14 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
} else {
|
} else {
|
||||||
/* zone_checksum for endpoints already is calculated above. */
|
/* zone_checksum for endpoints already is calculated above. */
|
||||||
|
|
||||||
auto command (dynamic_pointer_cast<Command>(object));
|
auto command(dynamic_pointer_cast<Command>(object));
|
||||||
|
|
||||||
if (command) {
|
if (command) {
|
||||||
Dictionary::Ptr arguments = command->GetArguments();
|
Dictionary::Ptr arguments = command->GetArguments();
|
||||||
Dictionary::Ptr argumentChecksums = new Dictionary;
|
Dictionary::Ptr argumentChecksums = new Dictionary;
|
||||||
|
|
||||||
if (arguments) {
|
if (arguments) {
|
||||||
ObjectLock argumentsLock (arguments);
|
ObjectLock argumentsLock(arguments);
|
||||||
|
|
||||||
for (auto& kv : arguments) {
|
for (auto& kv : arguments) {
|
||||||
argumentChecksums->Set(kv.first, HashValue(kv.second));
|
argumentChecksums->Set(kv.first, HashValue(kv.second));
|
||||||
@ -347,7 +348,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
Dictionary::Ptr envvarChecksums = new Dictionary;
|
Dictionary::Ptr envvarChecksums = new Dictionary;
|
||||||
|
|
||||||
if (envvars) {
|
if (envvars) {
|
||||||
ObjectLock argumentsLock (envvars);
|
ObjectLock argumentsLock(envvars);
|
||||||
|
|
||||||
for (auto& kv : envvars) {
|
for (auto& kv : envvars) {
|
||||||
envvarChecksums->Set(kv.first, HashValue(kv.second));
|
envvarChecksums->Set(kv.first, HashValue(kv.second));
|
||||||
@ -358,7 +359,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
checkSums->Set("envvar_checksums", envvarChecksums);
|
checkSums->Set("envvar_checksums", envvarChecksums);
|
||||||
propertiesBlacklist.emplace("env");
|
propertiesBlacklist.emplace("env");
|
||||||
} else {
|
} else {
|
||||||
auto timeperiod (dynamic_pointer_cast<TimePeriod>(object));
|
auto timeperiod(dynamic_pointer_cast<TimePeriod>(object));
|
||||||
|
|
||||||
if (timeperiod) {
|
if (timeperiod) {
|
||||||
Dictionary::Ptr ranges = timeperiod->GetRanges();
|
Dictionary::Ptr ranges = timeperiod->GetRanges();
|
||||||
@ -377,8 +378,8 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
|
|
||||||
Array::Ptr includeChecksums = new Array();
|
Array::Ptr includeChecksums = new Array();
|
||||||
|
|
||||||
ObjectLock includesLock (includes);
|
ObjectLock includesLock(includes);
|
||||||
ObjectLock includeChecksumsLock (includeChecksums);
|
ObjectLock includeChecksumsLock(includeChecksums);
|
||||||
|
|
||||||
for (auto include : includes) {
|
for (auto include : includes) {
|
||||||
includeChecksums->Add(GetObjectIdentifier((*getInclude)(include.Get<String>())));
|
includeChecksums->Add(GetObjectIdentifier((*getInclude)(include.Get<String>())));
|
||||||
@ -397,8 +398,8 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
|
|
||||||
Array::Ptr excludeChecksums = new Array();
|
Array::Ptr excludeChecksums = new Array();
|
||||||
|
|
||||||
ObjectLock excludesLock (excludes);
|
ObjectLock excludesLock(excludes);
|
||||||
ObjectLock excludeChecksumsLock (excludeChecksums);
|
ObjectLock excludeChecksumsLock(excludeChecksums);
|
||||||
|
|
||||||
for (auto exclude : excludes) {
|
for (auto exclude : excludes) {
|
||||||
excludeChecksums->Add(GetObjectIdentifier((*getExclude)(exclude.Get<String>())));
|
excludeChecksums->Add(GetObjectIdentifier((*getExclude)(exclude.Get<String>())));
|
||||||
@ -406,23 +407,23 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
|
|
||||||
checkSums->Set("exclude_checksums", excludeChecksums);
|
checkSums->Set("exclude_checksums", excludeChecksums);
|
||||||
} else {
|
} else {
|
||||||
icinga::Comment::Ptr comment = dynamic_pointer_cast<Comment>(object);
|
icinga::Comment::Ptr comment = dynamic_pointer_cast<Comment>(object);
|
||||||
if (comment) {
|
if (comment) {
|
||||||
propertiesBlacklist.emplace("name");
|
propertiesBlacklist.emplace("name");
|
||||||
propertiesBlacklist.emplace("host_name");
|
propertiesBlacklist.emplace("host_name");
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(comment->GetCheckable());
|
tie(host, service) = GetHostService(comment->GetCheckable());
|
||||||
if (service) {
|
if (service) {
|
||||||
propertiesBlacklist.emplace("service_name");
|
propertiesBlacklist.emplace("service_name");
|
||||||
checkSums->Set("service_checksum", GetObjectIdentifier(service));
|
checkSums->Set("service_checksum", GetObjectIdentifier(service));
|
||||||
typeName = "servicecomment";
|
typeName = "servicecomment";
|
||||||
} else {
|
} else {
|
||||||
checkSums->Set("host_checksum", GetObjectIdentifier(host));
|
checkSums->Set("host_checksum", GetObjectIdentifier(host));
|
||||||
typeName = "hostcomment";
|
typeName = "hostcomment";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,15 +440,15 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
|
|
||||||
checkSums->Set("vars_checksum", CalculateCheckSumVars(customVarObject));
|
checkSums->Set("vars_checksum", CalculateCheckSumVars(customVarObject));
|
||||||
|
|
||||||
auto vars (SerializeVars(customVarObject));
|
auto vars(SerializeVars(customVarObject));
|
||||||
|
|
||||||
if (vars) {
|
if (vars) {
|
||||||
auto varsJson (JsonEncode(vars));
|
auto varsJson(JsonEncode(vars));
|
||||||
|
|
||||||
Log(LogDebug, "RedisWriter")
|
Log(LogDebug, "RedisWriter")
|
||||||
<< "HSET " << m_PrefixConfigCustomVar + typeName << " " << objectKey << " " << varsJson;
|
<< "HSET " << m_PrefixConfigCustomVar + typeName << " " << objectKey << " " << varsJson;
|
||||||
|
|
||||||
ExecuteQuery({ "HSET", m_PrefixConfigCustomVar + typeName, objectKey, varsJson });
|
ExecuteQuery({"HSET", m_PrefixConfigCustomVar + typeName, objectKey, varsJson});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,18 +458,18 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
String checkSumsBody = JsonEncode(checkSums);
|
String checkSumsBody = JsonEncode(checkSums);
|
||||||
|
|
||||||
Log(LogDebug, "RedisWriter")
|
Log(LogDebug, "RedisWriter")
|
||||||
<< "HSET " << m_PrefixConfigCheckSum + typeName << " " << objectKey << " " << checkSumsBody;
|
<< "HSET " << m_PrefixConfigCheckSum + typeName << " " << objectKey << " " << checkSumsBody;
|
||||||
|
|
||||||
ExecuteQuery({ "HSET", m_PrefixConfigCheckSum + typeName, objectKey, checkSumsBody });
|
ExecuteQuery({"HSET", m_PrefixConfigCheckSum + typeName, objectKey, checkSumsBody});
|
||||||
|
|
||||||
|
|
||||||
/* Send an update event to subscribers. */
|
/* Send an update event to subscribers. */
|
||||||
if (runtimeUpdate) {
|
if (runtimeUpdate) {
|
||||||
ExecuteQuery({ "PUBLISH", "icinga:config:update", typeName + ":" + objectKey });
|
ExecuteQuery({"PUBLISH", "icinga:config:update", typeName + ":" + objectKey});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useTransaction)
|
if (useTransaction)
|
||||||
ExecuteQuery({ "EXEC" });
|
ExecuteQuery({"EXEC"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RedisWriter::SendConfigDelete(const ConfigObject::Ptr& object)
|
void RedisWriter::SendConfigDelete(const ConfigObject::Ptr& object)
|
||||||
@ -483,10 +484,10 @@ void RedisWriter::SendConfigDelete(const ConfigObject::Ptr& object)
|
|||||||
String objectKey = GetObjectIdentifier(object);
|
String objectKey = GetObjectIdentifier(object);
|
||||||
|
|
||||||
ExecuteQueries({
|
ExecuteQueries({
|
||||||
{ "HDEL", m_PrefixConfigObject + typeName, objectKey },
|
{"HDEL", m_PrefixConfigObject + typeName, objectKey},
|
||||||
{ "DEL", m_PrefixStatusObject + typeName + ":" + objectKey },
|
{"DEL", m_PrefixStatusObject + typeName + ":" + objectKey},
|
||||||
{ "PUBLISH", "icinga:config:delete", typeName + ":" + objectKey }
|
{"PUBLISH", "icinga:config:delete", typeName + ":" + objectKey}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,13 +500,13 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (useTransaction)
|
if (useTransaction)
|
||||||
ExecuteQuery({ "MULTI" });
|
ExecuteQuery({"MULTI"});
|
||||||
|
|
||||||
//TODO: Manage type names
|
//TODO: Manage type names
|
||||||
UpdateObjectAttrs(m_PrefixStatusObject, object, FAState, "");
|
UpdateObjectAttrs(m_PrefixStatusObject, object, FAState, "");
|
||||||
|
|
||||||
if (useTransaction)
|
if (useTransaction)
|
||||||
ExecuteQuery({ "EXEC" });
|
ExecuteQuery({"EXEC"});
|
||||||
|
|
||||||
// /* Serialize config object attributes */
|
// /* Serialize config object attributes */
|
||||||
// Dictionary::Ptr objectAttrs = SerializeObjectAttrs(object, FAState);
|
// Dictionary::Ptr objectAttrs = SerializeObjectAttrs(object, FAState);
|
||||||
@ -585,10 +586,11 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, bool useTran
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride)
|
void RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr& object, int fieldType,
|
||||||
|
const String& typeNameOverride)
|
||||||
{
|
{
|
||||||
Type::Ptr type = object->GetReflectionType();
|
Type::Ptr type = object->GetReflectionType();
|
||||||
Dictionary::Ptr attrs (new Dictionary);
|
Dictionary::Ptr attrs(new Dictionary);
|
||||||
|
|
||||||
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
|
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
|
||||||
Field field = type->GetFieldInfo(fid);
|
Field field = type->GetFieldInfo(fid);
|
||||||
@ -635,7 +637,8 @@ void RedisWriter::VersionChangedHandler(const ConfigObject::Ptr& object)
|
|||||||
for (const RedisWriter::Ptr& rw : ConfigType::GetObjectsByType<RedisWriter>()) {
|
for (const RedisWriter::Ptr& rw : ConfigType::GetObjectsByType<RedisWriter>()) {
|
||||||
rw->m_WorkQueue.Enqueue(std::bind(&RedisWriter::SendConfigUpdate, rw.get(), object, true, true));
|
rw->m_WorkQueue.Enqueue(std::bind(&RedisWriter::SendConfigUpdate, rw.get(), object, true, true));
|
||||||
}
|
}
|
||||||
} else if (!object->IsActive() && object->GetExtension("ConfigObjectDeleted")) { /* same as in apilistener-configsync.cpp */
|
} else if (!object->IsActive() &&
|
||||||
|
object->GetExtension("ConfigObjectDeleted")) { /* same as in apilistener-configsync.cpp */
|
||||||
/* Delete object config */
|
/* Delete object config */
|
||||||
for (const RedisWriter::Ptr& rw : ConfigType::GetObjectsByType<RedisWriter>()) {
|
for (const RedisWriter::Ptr& rw : ConfigType::GetObjectsByType<RedisWriter>()) {
|
||||||
rw->m_WorkQueue.Enqueue(std::bind(&RedisWriter::SendConfigDelete, rw.get(), object));
|
rw->m_WorkQueue.Enqueue(std::bind(&RedisWriter::SendConfigDelete, rw.get(), object));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user