diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index 1971f8030..c0e59e517 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -306,6 +306,7 @@ std::vector IcingaDB::GetTypeObjectKeys(const String& type) } else if (type == "notification") { keys.emplace_back(m_PrefixConfigObject + type + ":user"); keys.emplace_back(m_PrefixConfigObject + type + ":usergroup"); + keys.emplace_back(m_PrefixConfigObject + type + ":recipient"); } else if (type == "checkcommand" || type == "notificationcommand" || type == "eventcommand") { keys.emplace_back(m_PrefixConfigObject + type + ":envvar"); keys.emplace_back(m_PrefixConfigCheckSum + type + ":envvar"); @@ -581,6 +582,10 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S Notification::Ptr notification = static_pointer_cast(object); std::set users = notification->GetUsers(); + + std::set allUsers; + std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin())); + Array::Ptr userIds = new Array(); auto usergroups(notification->GetUserGroups()); @@ -606,13 +611,21 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S usergroupIds->Reserve(usergroups.size()); auto& groups (hMSets[m_PrefixConfigObject + typeName + ":usergroup"]); + auto& notificationRecipients (hMSets[m_PrefixConfigObject + typeName + ":recipient"]); for (auto& usergroup : usergroups) { String usergroupId = GetObjectIdentifier(usergroup); - String id = CalculateCheckSumArray(new Array({envId, usergroupId, objectKey})); + + auto groupMembers = usergroup->GetMembers(); + std::copy(groupMembers.begin(), groupMembers.end(), std::inserter(allUsers, allUsers.begin())); + + String id = CalculateCheckSumArray(new Array({envId, "usergroup", usergroupId, objectKey})); groups.emplace_back(id); groups.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"usergroup_id", usergroupId}}))); + notificationRecipients.emplace_back(id); + notificationRecipients.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"usergroup_id", usergroupId}}))); + if (configUpdates) { configUpdates->emplace_back(typeName + ":usergroup:" + id); } @@ -620,6 +633,17 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S usergroupIds->Add(usergroupId); } + for (auto& user : allUsers) { + String userId = GetObjectIdentifier(user); + String id = CalculateCheckSumArray(new Array({envId, "user", userId, objectKey})); + notificationRecipients.emplace_back(id); + notificationRecipients.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"user_id", userId}}))); + + if (configUpdates) { + configUpdates->emplace_back(typeName + ":recipient:" + id); + } + } + return; }