Support comments for icingadb

This splits comments into Host and Service comments
This commit is contained in:
Jean Flach 2018-09-27 16:54:52 +02:00 committed by Michael Friedrich
parent ed3db5b491
commit 8f411c7475
2 changed files with 30 additions and 7 deletions

View File

@ -127,9 +127,6 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
if (useTransaction)
ExecuteQuery({ "MULTI" });
/* Send all object attributes to Redis, no extra checksums involved here. */
UpdateObjectAttrs(m_PrefixConfigObject, object, FAConfig);
/* Calculate object specific checksums and store them in a different namespace. */
Type::Ptr type = object->GetReflectionType();
@ -408,11 +405,32 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
}
checkSums->Set("exclude_checksums", excludeChecksums);
} else {
icinga::Comment::Ptr comment = dynamic_pointer_cast<Comment>(object);
if (comment) {
propertiesBlacklist.emplace("name");
propertiesBlacklist.emplace("host_name");
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(comment->GetCheckable());
if (service) {
propertiesBlacklist.emplace("service_name");
checkSums->Set("service_checksum", GetObjectIdentifier(service));
typeName = "servicecomment";
} else {
checkSums->Set("host_checksum", GetObjectIdentifier(host));
typeName = "hostcomment";
}
}
}
}
}
}
/* Send all object attributes to Redis, no extra checksums involved here. */
UpdateObjectAttrs(m_PrefixConfigObject, object, FAConfig, typeName);
/* Custom var checksums. */
CustomVarObject::Ptr customVarObject = dynamic_pointer_cast<CustomVarObject>(object);
@ -483,7 +501,8 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, bool useTran
if (useTransaction)
ExecuteQuery({ "MULTI" });
UpdateObjectAttrs(m_PrefixStatusObject, object, FAState);
//TODO: Manage type names
UpdateObjectAttrs(m_PrefixStatusObject, object, FAState, "");
if (useTransaction)
ExecuteQuery({ "EXEC" });
@ -566,7 +585,7 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, bool useTran
// }
}
void RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr& object, int fieldType)
void RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride)
{
Type::Ptr type = object->GetReflectionType();
Dictionary::Ptr attrs (new Dictionary);
@ -591,7 +610,11 @@ void RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject:
}
/* Use the name checksum as unique key. */
ExecuteQuery({"HSET", keyPrefix + type->GetName().ToLower(), GetObjectIdentifier(object), JsonEncode(attrs)});
String typeName = type->GetName().ToLower();
if (!typeNameOverride.IsEmpty())
typeName = typeNameOverride.ToLower();
ExecuteQuery({"HSET", keyPrefix + typeName, GetObjectIdentifier(object), JsonEncode(attrs)});
}
void RedisWriter::StateChangedHandler(const ConfigObject::Ptr& object)

View File

@ -69,7 +69,7 @@ private:
void SendConfigUpdate(const ConfigObject::Ptr& object, bool useTransaction, bool runtimeUpdate = false);
void SendConfigDelete(const ConfigObject::Ptr& object);
void SendStatusUpdate(const ConfigObject::Ptr& object, bool useTransaction);
void UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr& object, int fieldType);
void UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride);
/* Stats */
Dictionary::Ptr GetStats();