From d09a435fe34412c728dbb45893af534522eb5e61 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Thu, 12 Jul 2018 15:05:10 +0200 Subject: [PATCH] Export usergroup(s)_checksum(s) Warning: ugly code --- lib/redis/rediswriter-objects.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index e5a3096b6..b5d68fa60 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -23,6 +23,7 @@ #include "icinga/service.hpp" #include "icinga/hostgroup.hpp" #include "icinga/servicegroup.hpp" +#include "icinga/usergroup.hpp" #include "icinga/checkcommand.hpp" #include "icinga/eventcommand.hpp" #include "icinga/notificationcommand.hpp" @@ -151,6 +152,11 @@ static ConfigObject::Ptr GetServiceGroup(const String& name) return ConfigObject::GetObject(name); } +static ConfigObject::Ptr GetUserGroup(const String& name) +{ + return ConfigObject::GetObject(name); +} + void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTransaction, bool runtimeUpdate) { AssertOnWorkQueue(); @@ -189,6 +195,31 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran if (zone) checkSums->Set("zone_checksum", GetIdentifier(zone)); + User::Ptr user = dynamic_pointer_cast(object); + + if (user) { + propertiesBlacklist.emplace("groups"); + + Array::Ptr groups; + ConfigObject::Ptr (*getGroup)(const String& name); + + groups = user->GetGroups(); + getGroup = &::GetUserGroup; + + checkSums->Set("groups_checksum", CalculateCheckSumGroups(groups)); + + Array::Ptr groupChecksums = new Array(); + + ObjectLock groupsLock (groups); + ObjectLock groupChecksumsLock (groupChecksums); + + for (auto group : groups) { + groupChecksums->Add(GetIdentifier((*getGroup)(group.Get()))); + } + + checkSums->Set("group_checksums", groupChecksums); + } + /* Calculate checkable checksums. */ Checkable::Ptr checkable = dynamic_pointer_cast(object);