DB IDO: Refactor notification signal handling.

Refs #5103
Fixes #5265
This commit is contained in:
Michael Friedrich 2014-01-27 17:22:48 +01:00
parent 95559cb329
commit f30eca5a73
7 changed files with 46 additions and 24 deletions

View File

@ -50,7 +50,7 @@ void CompatLogger::Start(void)
DynamicObject::Start(); DynamicObject::Start();
Service::OnNewCheckResult.connect(bind(&CompatLogger::CheckResultHandler, this, _1, _2)); 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::OnFlappingChanged.connect(bind(&CompatLogger::FlappingHandler, this, _1, _2));
Service::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1, _2)); Service::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1, _2));
Service::OnDowntimeRemoved.connect(boost::bind(&CompatLogger::RemoveDowntimeHandler, 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. * @threadsafety Always.
*/ */
void CompatLogger::NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification, const Service::Ptr& service,
NotificationType const& notification_type, CheckResult::Ptr const& cr, const User::Ptr& user, NotificationType const& notification_type, CheckResult::Ptr const& cr,
const String& author, const String& comment_text, const String& command_name) const String& author, const String& comment_text, const String& command_name)
{ {
Host::Ptr host = service->GetHost(); Host::Ptr host = service->GetHost();

View File

@ -49,7 +49,9 @@ private:
void Flush(void); void Flush(void);
void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr); 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 FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
void TriggerDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime); void TriggerDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime);
void RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime); void RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime);

View File

@ -52,13 +52,13 @@ void ServiceDbObject::StaticInitialize(void)
Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddCommentHistory, _1, _2)); Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddCommentHistory, _1, _2));
Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntimeHistory, _1, _2)); Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntimeHistory, _1, _2));
Service::OnAcknowledgementSet.connect(boost::bind(&ServiceDbObject::AddAcknowledgementHistory, _1, _2, _3, _4, _5)); Service::OnAcknowledgementSet.connect(boost::bind(&ServiceDbObject::AddAcknowledgementHistory, _1, _2, _3, _4, _5));
Service::OnNotificationSentToUser.connect(bind(&ServiceDbObject::AddContactNotificationHistory, _1, _2)); Service::OnNotificationSentToUser.connect(bind(&ServiceDbObject::AddContactNotificationHistory, _1, _2, _3));
Service::OnNotificationSentToAllUsers.connect(bind(&ServiceDbObject::AddNotificationHistory, _1, _2, _3, _4, _5, _6)); Service::OnNotificationSendStart.connect(bind(&ServiceDbObject::AddNotificationHistory, _1, _2, _3, _4, _5, _6, _7));
Service::OnStateChange.connect(boost::bind(&ServiceDbObject::AddStateChangeHistory, _1, _2, _3)); Service::OnStateChange.connect(boost::bind(&ServiceDbObject::AddStateChangeHistory, _1, _2, _3));
Service::OnNewCheckResult.connect(bind(&ServiceDbObject::AddCheckResultLogHistory, _1, _2)); 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::OnFlappingChanged.connect(bind(&ServiceDbObject::AddFlappingLogHistory, _1, _2));
Service::OnDowntimeTriggered.connect(boost::bind(&ServiceDbObject::AddTriggerDowntimeLogHistory, _1, _2)); Service::OnDowntimeTriggered.connect(boost::bind(&ServiceDbObject::AddTriggerDowntimeLogHistory, _1, _2));
Service::OnDowntimeRemoved.connect(boost::bind(&ServiceDbObject::AddRemoveDowntimeLogHistory, _1, _2)); Service::OnDowntimeRemoved.connect(boost::bind(&ServiceDbObject::AddRemoveDowntimeLogHistory, _1, _2));
@ -759,7 +759,7 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
/* notifications */ /* 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(); Host::Ptr host = service->GetHost();
@ -788,7 +788,7 @@ void ServiceDbObject::AddContactNotificationHistory(const Service::Ptr& service,
OnQuery(query1); 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) const CheckResult::Ptr& cr, const String& author, const String& text)
{ {
Host::Ptr host = service->GetHost(); 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, NotificationType notification_type, const CheckResult::Ptr& cr,
const String& author, const String& comment_text) const String& author, const String& comment_text)
{ {

View File

@ -98,15 +98,20 @@ private:
/* History */ /* History */
static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment); static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment);
static void AddDowntimeHistory(const Service::Ptr& service, const Downtime::Ptr& downtime); 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 AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment,
static void AddContactNotificationHistory(const Service::Ptr& service, const User::Ptr& user); AcknowledgementType type, double expiry);
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 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 AddStateChangeHistory(const Service::Ptr& service, const CheckResult::Ptr& cr, StateType type);
static void AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr); static void AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr);
static void AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime); static void AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
static void AddRemoveDowntimeLogHistory(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 AddFlappingLogHistory(const Service::Ptr& service, FlappingState flapping_state);
static void AddFlappingHistory(const Service::Ptr& service, FlappingState flapping_state); static void AddFlappingHistory(const Service::Ptr& service, FlappingState flapping_state);

View File

@ -256,14 +256,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin())); 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) { BOOST_FOREACH(const User::Ptr& user, allUsers) {
Log(LogDebug, "icinga", "Sending notification for user '" + user->GetName() + "'"); Log(LogDebug, "icinga", "Sending notification for user '" + user->GetName() + "'");
Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text)); 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) 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()); 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() + "'"); Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'");
} catch (const std::exception& ex) { } catch (const std::exception& ex) {

View File

@ -31,8 +31,12 @@
using namespace icinga; 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 Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&)> Service::OnNotificationSentToUser; 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) void Service::ResetNotificationNumbers(void)
{ {
@ -64,6 +68,8 @@ void Service::SendNotifications(NotificationType type, const CheckResult::Ptr& c
if (notifications.empty()) if (notifications.empty())
Log(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications."); 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) { BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
try { try {
notification->BeginExecuteNotification(type, cr, force, author, text); notification->BeginExecuteNotification(type, cr, force, author, text);

View 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&, 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&, 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&, 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&, NotificationType, const CheckResult::Ptr&,
static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&)> OnNotificationSentToUser; const String&, const String&)> OnNotificationsRequested;
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 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&)> OnCommentAdded;
static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentRemoved; 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&)> OnDowntimeAdded;
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeRemoved; 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&, FlappingState)> OnFlappingChanged;
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered; 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&, const String&)> OnAcknowledgementCleared;
static boost::signals2::signal<void (const Service::Ptr&)> OnEventCommandExecuted; static boost::signals2::signal<void (const Service::Ptr&)> OnEventCommandExecuted;