]> granicus.if.org Git - icinga2/commitdiff
notifications: Add OnNotificationSentToAllUsers signal.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 24 Sep 2013 16:49:25 +0000 (18:49 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 24 Sep 2013 16:49:25 +0000 (18:49 +0200)
components/compat/compatlog.cpp
lib/icinga/notification.cpp
lib/icinga/service-notification.cpp
lib/icinga/service.h

index 27faf0b7c3dab3a2e75323d66c6157ea44a3e5b6..d1008f0e21a6e4c6a2ce5af79c7a6bc9483c744a 100644 (file)
@@ -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));
index 0f68171e96e69e9cbc95d6174526a59a640b251c..7b4ec5d687b7f5769299e149a53c04dd675a7b65 100644 (file)
@@ -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) {
index 05e656e99143367cb36c1609fdcd1a783143b906..f293b39f874cfb18e816edb628220b76194a043d 100644 (file)
@@ -31,7 +31,8 @@
 
 using namespace icinga;
 
-boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentChanged;
+boost::signals2::signal<void (const Service::Ptr&, const std::set<User::Ptr>&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&, unsigned long)> Service::OnNotificationSentToAllUsers;
+boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentToUser;
 
 Dictionary::Ptr Service::GetNotificationDescriptions(void) const
 {
index fff97d308379ec08d23b7b414c61a29d90155bf2..931fe4798cdd504dccbc3663c22b62aaccfcac80 100644 (file)
@@ -239,7 +239,8 @@ public:
        static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableFlappingChanged;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnNewCheckResult;
        static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const Dictionary::Ptr&, const String&, const String&)> OnNotificationsRequested;
-       static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentChanged;
+       static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentToUser;
+       static boost::signals2::signal<void (const Service::Ptr&, const std::set<User::Ptr>&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&, unsigned long)> OnNotificationSentToAllUsers;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnCommentAdded;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnCommentRemoved;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnDowntimeAdded;