From de99d68351b74431c23467182a81e06cb9eabeee Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 6 Aug 2018 10:55:24 +0200 Subject: [PATCH] Only use the type for commands in the object identifier checksum --- lib/redis/rediswriter-objects.cpp | 28 ++++++++++++++-------------- lib/redis/rediswriter-utility.cpp | 12 ++++++++++-- lib/redis/rediswriter.hpp | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index 4ca17e6ad..3d747b8f5 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -187,7 +187,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran Type::Ptr type = object->GetReflectionType(); String typeName = type->GetName().ToLower(); - String objectKey = GetIdentifier(object); + String objectKey = GetObjectIdentifier(object); std::set propertiesBlacklist ({"name", "__name", "package", "source_location", "templates"}); @@ -202,14 +202,14 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran auto endpointZone (endpoint->GetZone()); if (endpointZone) { - checkSums->Set("zone_checksum", GetIdentifier(endpointZone)); + checkSums->Set("zone_checksum", GetObjectIdentifier(endpointZone)); } } else { /* 'zone' is available for all config objects, therefore calculate the checksum. */ auto zone (static_pointer_cast(object->GetZone())); if (zone) - checkSums->Set("zone_checksum", GetIdentifier(zone)); + checkSums->Set("zone_checksum", GetObjectIdentifier(zone)); } User::Ptr user = dynamic_pointer_cast(object); @@ -231,7 +231,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran ObjectLock groupChecksumsLock (groupChecksums); for (auto group : groups) { - groupChecksums->Add(GetIdentifier((*getGroup)(group.Get()))); + groupChecksums->Add(GetObjectIdentifier((*getGroup)(group.Get()))); } checkSums->Set("group_checksums", groupChecksums); @@ -257,7 +257,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran getGroup = &::GetServiceGroup; /* Calculate the host_checksum */ - checkSums->Set("host_checksum", GetIdentifier(host)); + checkSums->Set("host_checksum", GetObjectIdentifier(host)); } else { groups = host->GetGroups(); getGroup = &::GetHostGroup; @@ -271,7 +271,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran ObjectLock groupChecksumsLock (groupChecksums); for (auto group : groups) { - groupChecksums->Add(GetIdentifier((*getGroup)(group.Get()))); + groupChecksums->Add(GetObjectIdentifier((*getGroup)(group.Get()))); } checkSums->Set("group_checksums", groupChecksums); @@ -280,15 +280,15 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran Endpoint::Ptr commandEndpoint = checkable->GetCommandEndpoint(); if (commandEndpoint) - checkSums->Set("command_endpoint_checksum", GetIdentifier(commandEndpoint)); + checkSums->Set("command_endpoint_checksum", GetObjectIdentifier(commandEndpoint)); /* *_command_checksum */ - checkSums->Set("check_command_checksum", GetIdentifier(checkable->GetCheckCommand())); + checkSums->Set("check_command_checksum", GetObjectIdentifier(checkable->GetCheckCommand())); EventCommand::Ptr eventCommand = checkable->GetEventCommand(); if (eventCommand) - checkSums->Set("event_command_checksum", GetIdentifier(eventCommand)); + checkSums->Set("event_command_checksum", GetObjectIdentifier(eventCommand)); /* *_url_checksum, icon_image_checksum */ String actionUrl = checkable->GetActionUrl(); @@ -321,7 +321,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran Zone::Ptr parentZone = zone->GetParent(); if (parentZone) - checkSums->Set("parent_checksum", GetIdentifier(parentZone)); + checkSums->Set("parent_checksum", GetObjectIdentifier(parentZone)); } else { /* zone_checksum for endpoints already is calculated above. */ @@ -381,7 +381,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran ObjectLock includeChecksumsLock (includeChecksums); for (auto include : includes) { - includeChecksums->Add(GetIdentifier((*getInclude)(include.Get()))); + includeChecksums->Add(GetObjectIdentifier((*getInclude)(include.Get()))); } checkSums->Set("include_checksums", includeChecksums); @@ -401,7 +401,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran ObjectLock excludeChecksumsLock (excludeChecksums); for (auto exclude : excludes) { - excludeChecksums->Add(GetIdentifier((*getExclude)(exclude.Get()))); + excludeChecksums->Add(GetObjectIdentifier((*getExclude)(exclude.Get()))); } checkSums->Set("exclude_checksums", excludeChecksums); @@ -459,7 +459,7 @@ void RedisWriter::SendConfigDelete(const ConfigObject::Ptr& object) return; String typeName = object->GetReflectionType()->GetName().ToLower(); - String objectKey = GetIdentifier(object); + String objectKey = GetObjectIdentifier(object); ExecuteQueries({ { "DEL", m_PrefixConfigObject + typeName + ":" + objectKey }, @@ -570,7 +570,7 @@ void RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject: String typeName = type->GetName().ToLower(); /* Use the name checksum as unique key. */ - String objectKey = GetIdentifier(object); + String objectKey = GetObjectIdentifier(object); std::vector > queries; diff --git a/lib/redis/rediswriter-utility.cpp b/lib/redis/rediswriter-utility.cpp index d6f2ab523..4251a30a5 100644 --- a/lib/redis/rediswriter-utility.cpp +++ b/lib/redis/rediswriter-utility.cpp @@ -19,6 +19,9 @@ #include "redis/rediswriter.hpp" #include "icinga/customvarobject.hpp" +#include "icinga/checkcommand.hpp" +#include "icinga/notificationcommand.hpp" +#include "icinga/eventcommand.hpp" #include "base/object-packer.hpp" #include "base/logger.hpp" #include "base/serializer.hpp" @@ -49,9 +52,14 @@ String RedisWriter::GetEnvironment() return ScriptGlobal::Get("Environment", &l_DefaultEnv); } -String RedisWriter::GetIdentifier(const ConfigObject::Ptr& object) +String RedisWriter::GetObjectIdentifier(const ConfigObject::Ptr& object) { - return HashValue((Array::Ptr)new Array({GetEnvironment(), object->GetReflectionType()->GetName(), object->GetName()})); + Type::Ptr type = object->GetReflectionType(); + + if (type == CheckCommand::TypeInstance || type == NotificationCommand::TypeInstance || type == EventCommand::TypeInstance) + return HashValue((Array::Ptr)new Array({GetEnvironment(), type->GetName(), object->GetName()})); + else + return HashValue((Array::Ptr)new Array({GetEnvironment(), object->GetName()})); } String RedisWriter::CalculateCheckSumString(const String& str) diff --git a/lib/redis/rediswriter.hpp b/lib/redis/rediswriter.hpp index 601281d78..5ed2891e4 100644 --- a/lib/redis/rediswriter.hpp +++ b/lib/redis/rediswriter.hpp @@ -77,7 +77,7 @@ private: /* utilities */ static String FormatCheckSumBinary(const String& str); - static String GetIdentifier(const ConfigObject::Ptr& object); + static String GetObjectIdentifier(const ConfigObject::Ptr& object); static String GetEnvironment(); static String CalculateCheckSumString(const String& str); static String CalculateCheckSumArray(const Array::Ptr& arr);