From 6178ca3886cca17e17df9c820e99c0866386addb Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Mar 2017 10:21:51 +0100 Subject: [PATCH] Use GetHostService() instead of casts refs #4991 --- lib/redis/rediswriter-config.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/redis/rediswriter-config.cpp b/lib/redis/rediswriter-config.cpp index 876b59587..ddaee058e 100644 --- a/lib/redis/rediswriter-config.cpp +++ b/lib/redis/rediswriter-config.cpp @@ -176,12 +176,19 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, const String checkSum->Set("name_checksum", CalculateCheckSumString(object->GetName())); - if (object->GetReflectionType() == Host::TypeInstance) { - Host::Ptr host = static_pointer_cast(object); - checkSum->Set("groups_checksum", CalculateCheckSumGroups(host->GetGroups())); - } else if (object->GetReflectionType() == Service::TypeInstance) { - Service::Ptr service = static_pointer_cast(object); - checkSum->Set("groups_checksum", CalculateCheckSumGroups(service->GetGroups())); + // TODO: move this elsewhere + Checkable::Ptr checkable = dynamic_pointer_cast(object); + + if (checkable) { + Host::Ptr host; + Service::Ptr service; + + tie(host, service) = GetHostService(checkable); + + if (service) + checkSum->Set("groups_checksum", CalculateCheckSumGroups(service->GetGroups())); + else + checkSum->Set("groups_checksum", CalculateCheckSumGroups(host->GetGroups())); } String checkSumBody = JsonEncode(checkSum);