]> granicus.if.org Git - icinga2/commitdiff
DB IDO: Refactor notification signal handling.
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 27 Jan 2014 16:22:48 +0000 (17:22 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 28 Jan 2014 14:53:12 +0000 (15:53 +0100)
Refs #5103
Fixes #5265

components/compat/compatlogger.cpp
components/compat/compatlogger.h
lib/db_ido/servicedbobject.cpp
lib/db_ido/servicedbobject.h
lib/icinga/notification.cpp
lib/icinga/service-notification.cpp
lib/icinga/service.h

index d0ec56fb1735665f2e849167ca6b2b3b70d3349c..ee587b5fb5b842e744ea40804f9f210ab0beaf4d 100644 (file)
@@ -50,7 +50,7 @@ void CompatLogger::Start(void)
        DynamicObject::Start();
 
        Service::OnNewCheckResult.connect(bind(&CompatLogger::CheckResultHandler, this, _1, _2));
-       Service::OnNotificationSentToUser.connect(bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7));
+       Service::OnNotificationSentToUser.connect(bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8));
        Service::OnFlappingChanged.connect(bind(&CompatLogger::FlappingHandler, this, _1, _2));
        Service::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1, _2));
        Service::OnDowntimeRemoved.connect(boost::bind(&CompatLogger::RemoveDowntimeHandler, this, _1, _2));
@@ -235,8 +235,8 @@ void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Down
 /**
  * @threadsafety Always.
  */
-void CompatLogger::NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user,
-    NotificationType const& notification_type, CheckResult::Ptr const& cr,
+void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification, const Service::Ptr& service,
+    const User::Ptr& user, NotificationType const& notification_type, CheckResult::Ptr const& cr,
     const String& author, const String& comment_text, const String& command_name)
 {
         Host::Ptr host = service->GetHost();
index 9efb982421a2c426b5347172e936bbf574454224..d48b5f28ad5d7a1cd86c8f1af0ca8b427452288b 100644 (file)
@@ -49,7 +49,9 @@ private:
        void Flush(void);
 
        void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr);
-       void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, CheckResult::Ptr const& cr, const String& author, const String& comment_text, const String& command_name);
+       void NotificationSentHandler(const Notification::Ptr& notification, const Service::Ptr& service,
+            const User::Ptr& user, NotificationType const& notification_type, CheckResult::Ptr const& cr,
+            const String& author, const String& comment_text, const String& command_name);
        void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
        void TriggerDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime);
        void RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime);
index 1ee4528e2fb5fb307cb9675ac2b4093372d8a160..f1ed3066285b635a6e59fe80a777121a6cd9a927 100644 (file)
@@ -52,13 +52,13 @@ void ServiceDbObject::StaticInitialize(void)
        Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddCommentHistory, _1, _2));
        Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntimeHistory, _1, _2));
        Service::OnAcknowledgementSet.connect(boost::bind(&ServiceDbObject::AddAcknowledgementHistory, _1, _2, _3, _4, _5));
-       Service::OnNotificationSentToUser.connect(bind(&ServiceDbObject::AddContactNotificationHistory, _1, _2));
-       Service::OnNotificationSentToAllUsers.connect(bind(&ServiceDbObject::AddNotificationHistory, _1, _2, _3, _4, _5, _6));
+       Service::OnNotificationSentToUser.connect(bind(&ServiceDbObject::AddContactNotificationHistory, _1, _2, _3));
+       Service::OnNotificationSendStart.connect(bind(&ServiceDbObject::AddNotificationHistory, _1, _2, _3, _4, _5, _6, _7));
 
        Service::OnStateChange.connect(boost::bind(&ServiceDbObject::AddStateChangeHistory, _1, _2, _3));
 
        Service::OnNewCheckResult.connect(bind(&ServiceDbObject::AddCheckResultLogHistory, _1, _2));
-       Service::OnNotificationSentToUser.connect(bind(&ServiceDbObject::AddNotificationSentLogHistory, _1, _2, _3, _4, _5, _6));
+       Service::OnNotificationSentToUser.connect(bind(&ServiceDbObject::AddNotificationSentLogHistory, _1, _2, _3, _4, _5, _6, _7));
        Service::OnFlappingChanged.connect(bind(&ServiceDbObject::AddFlappingLogHistory, _1, _2));
        Service::OnDowntimeTriggered.connect(boost::bind(&ServiceDbObject::AddTriggerDowntimeLogHistory, _1, _2));
        Service::OnDowntimeRemoved.connect(boost::bind(&ServiceDbObject::AddRemoveDowntimeLogHistory, _1, _2));
@@ -759,7 +759,7 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
 
 /* notifications */
 
-void ServiceDbObject::AddContactNotificationHistory(const Service::Ptr& service, const User::Ptr& user)
+void ServiceDbObject::AddContactNotificationHistory(const Notification::Ptr& notification, const Service::Ptr& service, const User::Ptr& user)
 {
        Host::Ptr host = service->GetHost();
 
@@ -788,7 +788,7 @@ void ServiceDbObject::AddContactNotificationHistory(const Service::Ptr& service,
        OnQuery(query1);
 }
 
-void ServiceDbObject::AddNotificationHistory(const Service::Ptr& service, const std::set<User::Ptr>& users, NotificationType type,
+void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notification, const Service::Ptr& service, const std::set<User::Ptr>& users, NotificationType type,
     const CheckResult::Ptr& cr, const String& author, const String& text)
 {
        Host::Ptr host = service->GetHost();
@@ -1047,7 +1047,7 @@ void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, c
        }
 }
 
-void ServiceDbObject::AddNotificationSentLogHistory(const Service::Ptr& service, const User::Ptr& user,
+void ServiceDbObject::AddNotificationSentLogHistory(const Notification::Ptr& notification, const Service::Ptr& service, const User::Ptr& user,
     NotificationType notification_type, const CheckResult::Ptr& cr,
     const String& author, const String& comment_text)
 {
index 7219ab5b33a1e1cb6aecb1dafc4ab9d73074ab65..ec6e8c6609c10a3e9c82176205e2ae84edfed120 100644 (file)
@@ -98,15 +98,20 @@ private:
         /* History */
         static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment);
        static void AddDowntimeHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
-        static void AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry);
-        static void AddContactNotificationHistory(const Service::Ptr& service, const User::Ptr& user);
-       static void AddNotificationHistory(const Service::Ptr& service, const std::set<User::Ptr>& users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text);
+        static void AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment,
+            AcknowledgementType type, double expiry);
+        static void AddContactNotificationHistory(const Notification::Ptr& notification, const Service::Ptr& service, const User::Ptr& user);
+       static void AddNotificationHistory(const Notification::Ptr& notification, const Service::Ptr& service,
+            const std::set<User::Ptr>& users, NotificationType type, const CheckResult::Ptr& cr, const String& author,
+            const String& text);
        static void AddStateChangeHistory(const Service::Ptr& service, const CheckResult::Ptr& cr, StateType type);
 
        static void AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr);
         static void AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
         static void AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
-       static void AddNotificationSentLogHistory(const Service::Ptr& service, const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const String& author, const String& comment_text);
+       static void AddNotificationSentLogHistory(const Notification::Ptr& notification, const Service::Ptr& service,
+            const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const String& author,
+            const String& comment_text);
         static void AddFlappingLogHistory(const Service::Ptr& service, FlappingState flapping_state);
 
         static void AddFlappingHistory(const Service::Ptr& service, FlappingState flapping_state);
index d21d7a94c30db7fa538c658ebe8221313b8274f2..def6c140979e5c0879b7c4e5f796dc144ce7a7e4 100644 (file)
@@ -256,14 +256,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
                std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
        }
 
-       unsigned long notified_users = 0;
+       Service::OnNotificationSendStart(GetSelf(), GetService(), allUsers, type, cr, author, text);
+
        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);
+       Service::OnNotificationSentToAllUsers(GetSelf(), GetService(), allUsers, type, cr, author, text);
 }
 
 void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author, const String& text)
@@ -312,7 +312,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
                        SetLastNotification(Utility::GetTime());
                }
 
-               Service::OnNotificationSentToUser(GetService(), user, type, cr, author, text, command->GetName());
+               Service::OnNotificationSentToUser(GetSelf(), GetService(), user, type, cr, author, text, command->GetName());
 
                Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'");
        } catch (const std::exception& ex) {
index 8fbb4fdbade4f51b54965a99fb0378fe837d98ab..9d460ecae28f81ea1af50e2162ef83d9f7e3aae2 100644 (file)
 
 using namespace icinga;
 
-boost::signals2::signal<void (const Service::Ptr&, const std::set<User::Ptr>&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSentToAllUsers;
-boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&)> Service::OnNotificationSentToUser;
+boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
+    const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSentToAllUsers;
+boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
+    const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSendStart;
+boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const User::Ptr&,
+    const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&)> Service::OnNotificationSentToUser;
 
 void Service::ResetNotificationNumbers(void)
 {
@@ -64,6 +68,8 @@ void Service::SendNotifications(NotificationType type, const CheckResult::Ptr& c
        if (notifications.empty())
                Log(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications.");
 
+       Log(LogDebug, "icinga", "Service '" + GetName() + "' has " + notifications.size() + " notification(s).");
+
        BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
                try {
                        notification->BeginExecuteNotification(type, cr, force, author, text);
index 0639f183b1d7fcc595396c8913bd0d6fa5a926fa..e65a98e21c084bdb01cad8980455cadd684e5e59 100644 (file)
@@ -169,16 +169,25 @@ public:
        static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableFlappingChanged;
        static boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, const String&)> OnNewCheckResult;
        static boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, StateType, const String&)> OnStateChange;
-       static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const CheckResult::Ptr&, const String&, const String&)> OnNotificationsRequested;
-       static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&)> OnNotificationSentToUser;
-       static boost::signals2::signal<void (const Service::Ptr&, const std::set<User::Ptr>&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> OnNotificationSentToAllUsers;
+       static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const CheckResult::Ptr&,
+           const String&, const String&)> OnNotificationsRequested;
+       static boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
+           const NotificationType&, const CheckResult::Ptr&, const String&,
+           const String&)> OnNotificationSendStart;
+       static boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const User::Ptr&,
+           const NotificationType&, const CheckResult::Ptr&, const String&,
+           const String&, const String&)> OnNotificationSentToUser;
+       static boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
+           const NotificationType&, const CheckResult::Ptr&, const String&,
+           const String&)> OnNotificationSentToAllUsers;
        static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentAdded;
        static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentRemoved;
        static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeAdded;
        static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeRemoved;
        static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
        static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered;
-       static boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType, double, const String&)> OnAcknowledgementSet;
+       static boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType,
+                                            double, const String&)> OnAcknowledgementSet;
        static boost::signals2::signal<void (const Service::Ptr&, const String&)> OnAcknowledgementCleared;
        static boost::signals2::signal<void (const Service::Ptr&)> OnEventCommandExecuted;