Merge pull request #7669 from Icinga/feature/icingadb-notification-recipients

IcingaDB: Add notification recipients
This commit is contained in:
Alexander Aleksandrovič Klimov 2019-12-04 11:00:53 +01:00 committed by GitHub
commit 5d40a71f8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 1 deletions

View File

@ -335,6 +335,7 @@ std::vector<String> 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");
@ -610,6 +611,10 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
Notification::Ptr notification = static_pointer_cast<Notification>(object);
std::set<User::Ptr> users = notification->GetUsers();
std::set<User::Ptr> allUsers;
std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
Array::Ptr userIds = new Array();
auto usergroups(notification->GetUserGroups());
@ -635,13 +640,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);
}
@ -649,6 +662,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;
}