From: Michael Friedrich Date: Tue, 24 Sep 2013 16:49:25 +0000 (+0200) Subject: notifications: Add OnNotificationSentToAllUsers signal. X-Git-Tag: v0.0.3~447 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4295cb3a4364a3422800972a1fed6fd22c008f2;p=icinga2 notifications: Add OnNotificationSentToAllUsers signal. --- diff --git a/components/compat/compatlog.cpp b/components/compat/compatlog.cpp index 27faf0b7c..d1008f0e2 100644 --- a/components/compat/compatlog.cpp +++ b/components/compat/compatlog.cpp @@ -52,7 +52,7 @@ void CompatLog::Start(void) DynamicObject::Start(); Service::OnNewCheckResult.connect(bind(&CompatLog::CheckResultHandler, this, _1, _2)); - Service::OnNotificationSentChanged.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6)); + Service::OnNotificationSentToUser.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6)); Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2)); Service::OnDowntimeTriggered.connect(boost::bind(&CompatLog::TriggerDowntimeHandler, this, _1, _2)); Service::OnDowntimeRemoved.connect(boost::bind(&CompatLog::RemoveDowntimeHandler, this, _1, _2)); diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 0f68171e9..7b4ec5d68 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -296,10 +296,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const Diction std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin())); } + unsigned long notified_users = 0; BOOST_FOREACH(const User::Ptr& user, allUsers) { Log(LogDebug, "icinga", "Sending notification for user '" + user->GetName() + "'"); Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text)); + notified_users++; } + + Service::OnNotificationSentToAllUsers(GetService(), allUsers, type, cr, author, text, notified_users); } void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author, const String& text) @@ -333,6 +337,11 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: } try { + NotificationCommand::Ptr notificationCommand = GetNotificationCommand(); + + if (!notificationCommand) + BOOST_THROW_EXCEPTION(std::invalid_argument("Notification command for notification object '" + GetName() + " and user '" + user->GetName() + "' does not exist.")); + GetNotificationCommand()->Execute(GetSelf(), user, cr, type); { @@ -341,7 +350,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: SetLastNotification(Utility::GetTime()); } - Service::OnNotificationSentChanged(GetService(), user, type, cr, author, text); + Service::OnNotificationSentToUser(GetService(), user, type, cr, author, text); Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'"); } catch (const std::exception& ex) { diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 05e656e99..f293b39f8 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -31,7 +31,8 @@ using namespace icinga; -boost::signals2::signal Service::OnNotificationSentChanged; +boost::signals2::signal&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&, unsigned long)> Service::OnNotificationSentToAllUsers; +boost::signals2::signal Service::OnNotificationSentToUser; Dictionary::Ptr Service::GetNotificationDescriptions(void) const { diff --git a/lib/icinga/service.h b/lib/icinga/service.h index fff97d308..931fe4798 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -239,7 +239,8 @@ public: static boost::signals2::signal OnEnableFlappingChanged; static boost::signals2::signal OnNewCheckResult; static boost::signals2::signal OnNotificationsRequested; - static boost::signals2::signal OnNotificationSentChanged; + static boost::signals2::signal OnNotificationSentToUser; + static boost::signals2::signal&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&, unsigned long)> OnNotificationSentToAllUsers; static boost::signals2::signal OnCommentAdded; static boost::signals2::signal OnCommentRemoved; static boost::signals2::signal OnDowntimeAdded;