mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
Clean up the code a bit
This commit is contained in:
parent
fff1049ba0
commit
b6c86f98ec
@ -135,7 +135,11 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, const String
|
||||
}
|
||||
|
||||
checkSum->Set("properties_checksum", CalculateCheckSumProperties(object));
|
||||
checkSum->Set("vars_checksum", CalculateCheckSumVars(object));
|
||||
|
||||
CustomVarObject::Ptr customVarObject = dynamic_pointer_cast<CustomVarObject>(object);
|
||||
|
||||
if (customVarObject)
|
||||
checkSum->Set("vars_checksum", CalculateCheckSumVars(customVarObject));
|
||||
|
||||
String checkSumBody = JsonEncode(checkSum);
|
||||
|
||||
@ -188,7 +192,7 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, const String
|
||||
if (checkable) {
|
||||
Dictionary::Ptr attrs = new Dictionary();
|
||||
String tableName;
|
||||
String objectCheckSum = CalculateCheckSumString(objectName, true); //store binary checksum here
|
||||
String objectCheckSum = CalculateCheckSumString(objectName);
|
||||
|
||||
Host::Ptr host;
|
||||
Service::Ptr service;
|
||||
@ -198,7 +202,7 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, const String
|
||||
if (service) {
|
||||
tableName = "servicestate";
|
||||
attrs->Set("service_checksum", objectCheckSum);
|
||||
attrs->Set("host_checksum", CalculateCheckSumString(host->GetName(), true));
|
||||
attrs->Set("host_checksum", CalculateCheckSumString(host->GetName()));
|
||||
} else {
|
||||
tableName = "hoststate";
|
||||
attrs->Set("host_checksum", objectCheckSum);
|
||||
|
@ -36,46 +36,43 @@ String RedisWriter::FormatCheckSumBinary(const String& str)
|
||||
return output;
|
||||
}
|
||||
|
||||
String RedisWriter::CalculateCheckSumString(const String& str, bool binary)
|
||||
String RedisWriter::CalculateCheckSumString(const String& str)
|
||||
{
|
||||
return SHA1(str, binary);
|
||||
return SHA1(str);
|
||||
}
|
||||
|
||||
String RedisWriter::CalculateCheckSumGroups(const Array::Ptr& groups, bool binary)
|
||||
String RedisWriter::CalculateCheckSumGroups(const Array::Ptr& groups)
|
||||
{
|
||||
String output;
|
||||
|
||||
ObjectLock olock(groups);
|
||||
{
|
||||
ObjectLock olock(groups);
|
||||
|
||||
for (const String& group : groups) {
|
||||
output += SHA1(group, true); //binary checksum required here
|
||||
for (const String& group : groups) {
|
||||
output += SHA1(group);
|
||||
}
|
||||
}
|
||||
|
||||
return SHA1(output, binary);
|
||||
return SHA1(output);
|
||||
}
|
||||
|
||||
String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object, bool binary)
|
||||
String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object)
|
||||
{
|
||||
//TODO: consider precision of 6 for double values; use specific config fields for hashing?
|
||||
return HashValue(object, binary);
|
||||
return HashValue(object);
|
||||
}
|
||||
|
||||
String RedisWriter::CalculateCheckSumVars(const ConfigObject::Ptr& object, bool binary)
|
||||
String RedisWriter::CalculateCheckSumVars(const CustomVarObject::Ptr& object)
|
||||
{
|
||||
CustomVarObject::Ptr customVarObject = dynamic_pointer_cast<CustomVarObject>(object);
|
||||
|
||||
if (!customVarObject)
|
||||
return HashValue(Empty, binary);
|
||||
|
||||
Dictionary::Ptr vars = customVarObject->GetVars();
|
||||
Dictionary::Ptr vars = object->GetVars();
|
||||
|
||||
if (!vars)
|
||||
return HashValue(Empty, binary);
|
||||
return HashValue(Empty);
|
||||
|
||||
return HashValue(vars, binary);
|
||||
return HashValue(vars);
|
||||
}
|
||||
|
||||
String RedisWriter::HashValue(const Value& value, bool binary)
|
||||
String RedisWriter::HashValue(const Value& value)
|
||||
{
|
||||
Value temp;
|
||||
|
||||
@ -86,7 +83,7 @@ String RedisWriter::HashValue(const Value& value, bool binary)
|
||||
else
|
||||
temp = value;
|
||||
|
||||
return SHA1(JsonEncode(temp), binary);
|
||||
return SHA1(JsonEncode(temp));
|
||||
}
|
||||
|
||||
Dictionary::Ptr RedisWriter::SerializeObjectAttrs(const Object::Ptr& object, int fieldType)
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define REDISWRITER_H
|
||||
|
||||
#include "redis/rediswriter.thpp"
|
||||
#include "icinga/customvarobject.hpp"
|
||||
#include "remote/messageorigin.hpp"
|
||||
#include "base/timer.hpp"
|
||||
#include "base/workqueue.hpp"
|
||||
@ -70,12 +71,12 @@ private:
|
||||
/* utilities */
|
||||
static String FormatCheckSumBinary(const String& str);
|
||||
|
||||
static String CalculateCheckSumString(const String& str, bool binary = false);
|
||||
static String CalculateCheckSumGroups(const Array::Ptr& groups, bool binary = false);
|
||||
static String CalculateCheckSumProperties(const ConfigObject::Ptr& object, bool binary = false);
|
||||
static String CalculateCheckSumVars(const ConfigObject::Ptr& object, bool binary = false);
|
||||
static String CalculateCheckSumString(const String& str);
|
||||
static String CalculateCheckSumGroups(const Array::Ptr& groups);
|
||||
static String CalculateCheckSumProperties(const ConfigObject::Ptr& object);
|
||||
static String CalculateCheckSumVars(const CustomVarObject::Ptr& object);
|
||||
|
||||
static String HashValue(const Value& value, bool binary = false);
|
||||
static String HashValue(const Value& value);
|
||||
static Dictionary::Ptr SerializeObjectAttrs(const Object::Ptr& object, int fieldType);
|
||||
|
||||
static void StateChangedHandler(const ConfigObject::Ptr& object);
|
||||
|
Loading…
x
Reference in New Issue
Block a user