mirror of https://github.com/Icinga/icinga2.git
parent
6178ca3886
commit
f29a82bcfe
|
@ -59,6 +59,7 @@ void RedisWriter::UpdateAllConfigObjects(void)
|
|||
{
|
||||
AssertOnWorkQueue();
|
||||
|
||||
//TODO: "Publish" the config dump by adding another event, globally or by object
|
||||
redisReply *reply1 = reinterpret_cast<redisReply *>(redisCommand(m_Context, "MULTI"));
|
||||
|
||||
if (!reply1) {
|
||||
|
@ -86,7 +87,7 @@ void RedisWriter::UpdateAllConfigObjects(void)
|
|||
String typeName = type->GetName();
|
||||
|
||||
/* replace into aka delete insert is faster than a full diff */
|
||||
redisReply *reply2 = reinterpret_cast<redisReply *>(redisCommand(m_Context, "DEL icinga:config:%s icinga:status:%s", typeName.CStr(), typeName.CStr()));
|
||||
redisReply *reply2 = reinterpret_cast<redisReply *>(redisCommand(m_Context, "DEL icinga:config:%s icinga:config:%s:checksum, icinga:status:%s", typeName.CStr(), typeName.CStr(), typeName.CStr()));
|
||||
|
||||
if (!reply2) {
|
||||
redisFree(m_Context);
|
||||
|
@ -146,7 +147,6 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, const String
|
|||
|
||||
String jsonBody = JsonEncode(objectAttrs);
|
||||
|
||||
//TODO: checksum
|
||||
String objectName = object->GetName();
|
||||
|
||||
redisReply *reply1 = reinterpret_cast<redisReply *>(redisCommand(m_Context, "HSET icinga:config:%s %s %s", typeName.CStr(), objectName.CStr(), jsonBody.CStr()));
|
||||
|
@ -191,6 +191,9 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, const String
|
|||
checkSum->Set("groups_checksum", CalculateCheckSumGroups(host->GetGroups()));
|
||||
}
|
||||
|
||||
checkSum->Set("properties_checksum", CalculateCheckSumProperties(object));
|
||||
checkSum->Set("vars_checksum", CalculateCheckSumVars(object));
|
||||
|
||||
String checkSumBody = JsonEncode(checkSum);
|
||||
|
||||
redisReply *reply2 = reinterpret_cast<redisReply *>(redisCommand(m_Context, "HSET icinga:config:%s:checksum %s %s", typeName.CStr(), objectName.CStr(), checkSumBody.CStr()));
|
||||
|
|
|
@ -54,18 +54,39 @@ String RedisWriter::CalculateCheckSumGroups(const Array::Ptr& groups)
|
|||
return SHA1(output);
|
||||
}
|
||||
|
||||
String RedisWriter::CalculateCheckSumAttrs(const Dictionary::Ptr& attrs)
|
||||
String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object)
|
||||
{
|
||||
String output;
|
||||
//TODO: consider precision of 6 for double values; use specific config fields for hashing?
|
||||
return HashValue(object);
|
||||
}
|
||||
|
||||
//TODO: Implement
|
||||
for (const Dictionary::Pair& kv: attrs) {
|
||||
if (kv.second.IsNumber()) {
|
||||
//use a precision of 6 for floating point numbers
|
||||
}
|
||||
}
|
||||
String RedisWriter::CalculateCheckSumVars(const ConfigObject::Ptr& object)
|
||||
{
|
||||
CustomVarObject::Ptr customVarObject = dynamic_pointer_cast<CustomVarObject>(object);
|
||||
|
||||
return output;
|
||||
if (!customVarObject)
|
||||
return Empty;
|
||||
|
||||
Dictionary::Ptr vars = customVarObject->GetVars();
|
||||
|
||||
if (!vars)
|
||||
return Empty;
|
||||
|
||||
return HashValue(vars);
|
||||
}
|
||||
|
||||
String RedisWriter::HashValue(const Value& value)
|
||||
{
|
||||
Value temp;
|
||||
|
||||
Type::Ptr type = value.GetReflectionType();
|
||||
|
||||
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
|
||||
temp = Serialize(value, FAConfig);
|
||||
else
|
||||
temp = value;
|
||||
|
||||
return SHA1(JsonEncode(temp));
|
||||
}
|
||||
|
||||
Dictionary::Ptr RedisWriter::SerializeObjectAttrs(const Object::Ptr& object, int fieldType)
|
||||
|
|
|
@ -66,9 +66,13 @@ private:
|
|||
|
||||
/* utilities */
|
||||
static String FormatCheckSumBinary(const String& str);
|
||||
|
||||
static String CalculateCheckSumString(const String& str);
|
||||
static String CalculateCheckSumGroups(const Array::Ptr& groups);
|
||||
static String CalculateCheckSumAttrs(const Dictionary::Ptr& attrs);
|
||||
static String CalculateCheckSumProperties(const ConfigObject::Ptr& object);
|
||||
static String CalculateCheckSumVars(const ConfigObject::Ptr& object);
|
||||
|
||||
static String HashValue(const Value& value);
|
||||
static Dictionary::Ptr SerializeObjectAttrs(const Object::Ptr& object, int fieldType);
|
||||
|
||||
static void StateChangedHandler(const ConfigObject::Ptr& object);
|
||||
|
|
Loading…
Reference in New Issue