notifications: Add OnNotificationSentToAllUsers signal.

This commit is contained in:
Michael Friedrich 2013-09-24 18:49:25 +02:00
parent 83a06b4378
commit d4295cb3a4
4 changed files with 15 additions and 4 deletions

View 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));

View 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) {

View 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
{

View 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;