From 3a8cf8d74d0315471357157d6197b4c6dd4c0eff Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 9 Aug 2018 10:49:36 +0200 Subject: [PATCH] RedisWriter: dump missing checksums for notifications refs #18 --- lib/redis/rediswriter-objects.cpp | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index 69f808bbd..3471cae17 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -242,6 +242,49 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran checkSums->Set("period_checksum", GetObjectIdentifier(period)); } + Notification::Ptr notification = dynamic_pointer_cast(object); + + if (notification) { + Host::Ptr host; + Service::Ptr service; + auto users (notification->GetUsers()); + Array::Ptr userChecksums = new Array(); + Array::Ptr userNames = new Array(); + auto usergroups (notification->GetUserGroups()); + Array::Ptr usergroupChecksums = new Array(); + Array::Ptr usergroupNames = new Array(); + + tie(host, service) = GetHostService(notification->GetCheckable()); + + checkSums->Set("host_checksum", GetObjectIdentifier(host)); + checkSums->Set("command_checksum", GetObjectIdentifier(notification->GetCommand())); + + if (service) + checkSums->Set("service_checksum", GetObjectIdentifier(service)); + + userChecksums->Reserve(users.size()); + userNames->Reserve(users.size()); + + for (auto& user : users) { + userChecksums->Add(GetObjectIdentifier(user)); + userNames->Add(user->GetName()); + } + + checkSums->Set("user_checksums", userChecksums); + checkSums->Set("users_checksum", CalculateCheckSumArray(userNames)); + + usergroupChecksums->Reserve(usergroups.size()); + usergroupNames->Reserve(usergroups.size()); + + for (auto& usergroup : usergroups) { + usergroupChecksums->Add(GetObjectIdentifier(usergroup)); + usergroupNames->Add(usergroup->GetName()); + } + + checkSums->Set("usergroup_checksums", usergroupChecksums); + checkSums->Set("usergroups_checksum", CalculateCheckSumArray(usergroupNames)); + } + /* Calculate checkable checksums. */ Checkable::Ptr checkable = dynamic_pointer_cast(object);