From: Michael Friedrich Date: Mon, 27 Jan 2014 16:22:48 +0000 (+0100) Subject: DB IDO: Refactor notification signal handling. X-Git-Tag: v0.0.7~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f30eca5a7321f6c2d9be74fee1e7909d8b279027;p=icinga2 DB IDO: Refactor notification signal handling. Refs #5103 Fixes #5265 --- diff --git a/components/compat/compatlogger.cpp b/components/compat/compatlogger.cpp index d0ec56fb1..ee587b5fb 100644 --- a/components/compat/compatlogger.cpp +++ b/components/compat/compatlogger.cpp @@ -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(); diff --git a/components/compat/compatlogger.h b/components/compat/compatlogger.h index 9efb98242..d48b5f28a 100644 --- a/components/compat/compatlogger.h +++ b/components/compat/compatlogger.h @@ -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); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 1ee4528e2..f1ed30662 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -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& users, NotificationType type, +void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notification, const Service::Ptr& service, const std::set& 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) { diff --git a/lib/db_ido/servicedbobject.h b/lib/db_ido/servicedbobject.h index 7219ab5b3..ec6e8c660 100644 --- a/lib/db_ido/servicedbobject.h +++ b/lib/db_ido/servicedbobject.h @@ -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& 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& 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); diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index d21d7a94c..def6c1409 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -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) { diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 8fbb4fdba..9d460ecae 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -31,8 +31,12 @@ using namespace icinga; -boost::signals2::signal&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSentToAllUsers; -boost::signals2::signal Service::OnNotificationSentToUser; +boost::signals2::signal&, + const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSentToAllUsers; +boost::signals2::signal&, + const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSendStart; +boost::signals2::signal 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); diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 0639f183b..e65a98e21 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -169,16 +169,25 @@ public: static boost::signals2::signal OnEnableFlappingChanged; static boost::signals2::signal OnNewCheckResult; static boost::signals2::signal OnStateChange; - static boost::signals2::signal OnNotificationsRequested; - static boost::signals2::signal OnNotificationSentToUser; - static boost::signals2::signal&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> OnNotificationSentToAllUsers; + static boost::signals2::signal OnNotificationsRequested; + static boost::signals2::signal&, + const NotificationType&, const CheckResult::Ptr&, const String&, + const String&)> OnNotificationSendStart; + static boost::signals2::signal OnNotificationSentToUser; + static boost::signals2::signal&, + const NotificationType&, const CheckResult::Ptr&, const String&, + const String&)> OnNotificationSentToAllUsers; static boost::signals2::signal OnCommentAdded; static boost::signals2::signal OnCommentRemoved; static boost::signals2::signal OnDowntimeAdded; static boost::signals2::signal OnDowntimeRemoved; static boost::signals2::signal OnFlappingChanged; static boost::signals2::signal OnDowntimeTriggered; - static boost::signals2::signal OnAcknowledgementSet; + static boost::signals2::signal OnAcknowledgementSet; static boost::signals2::signal OnAcknowledgementCleared; static boost::signals2::signal OnEventCommandExecuted;