diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index a151c0cbd..6161b138a 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -1219,7 +1219,7 @@ void IcingaDB::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResu } void IcingaDB::SendSentNotification( - const Notification::Ptr& notification, const Checkable::Ptr& checkable, size_t users, + const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set& users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text ) { @@ -1233,9 +1233,12 @@ void IcingaDB::SendSentNotification( finalText = cr->GetOutput(); } + auto usersAmount (users.size()); + auto notificationHistoryId = Utility::NewUniqueID(); + std::vector xAdd ({ "XADD", "icinga:history:stream:notification", "*", - "id", Utility::NewUniqueID(), + "id", notificationHistoryId, "environment_id", SHA1(GetEnvironment()), "notification_id", GetObjectIdentifier(notification), "type", Convert::ToString(type), @@ -1243,7 +1246,7 @@ void IcingaDB::SendSentNotification( "previous_hard_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeHard)), "author", Utility::ValidateUTF8(author), "text", Utility::ValidateUTF8(finalText), - "users_notified", Convert::ToString(users), + "users_notified", Convert::ToString(usersAmount), "event_time", Convert::ToString(TimestampToMilliseconds(Utility::GetTime())), "event_id", Utility::NewUniqueID(), "event_type", "notification" @@ -1269,6 +1272,19 @@ void IcingaDB::SendSentNotification( } m_Rcon->FireAndForgetQuery(std::move(xAdd)); + + for (const User::Ptr& user : users) { + auto userId = GetObjectIdentifier(user); + std::vector xAddUser ({ + "XADD", "icinga:history:stream:usernotification", "*", + "id", Utility::NewUniqueID(), + "environment_id", SHA1(GetEnvironment()), + "notification_history_id", notificationHistoryId, + "user_id", GetObjectIdentifier(user), + }); + + m_Rcon->FireAndForgetQuery(std::move(xAddUser)); + } } void IcingaDB::SendStartedDowntime(const Downtime::Ptr& downtime) @@ -1751,12 +1767,11 @@ void IcingaDB::NotificationSentToAllUsersHandler( auto rws (ConfigType::GetObjectsByType()); if (!rws.empty()) { - auto usersAmount (users.size()); auto authorAndText (std::make_shared>(author, text)); for (auto& rw : rws) { - rw->m_WorkQueue.Enqueue([rw, notification, checkable, usersAmount, type, cr, authorAndText]() { - rw->SendSentNotification(notification, checkable, usersAmount, type, cr, authorAndText->first, authorAndText->second); + rw->m_WorkQueue.Enqueue([rw, notification, checkable, users, type, cr, authorAndText]() { + rw->SendSentNotification(notification, checkable, users, type, cr, authorAndText->first, authorAndText->second); }); } } diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index 4ebe26409..9140297c1 100644 --- a/lib/icingadb/icingadb.hpp +++ b/lib/icingadb/icingadb.hpp @@ -66,7 +66,7 @@ private: void SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type); void SendSentNotification( - const Notification::Ptr& notification, const Checkable::Ptr& checkable, size_t users, + const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set& users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text );