diff --git a/components/notification/notificationcomponent.cpp b/components/notification/notificationcomponent.cpp index bc8b2703a..2bcac7826 100644 --- a/components/notification/notificationcomponent.cpp +++ b/components/notification/notificationcomponent.cpp @@ -140,5 +140,10 @@ void NotificationComponent::SendNotificationsRequestHandler(const Endpoint::Ptr& if (!service) return; - service->SendNotifications(static_cast(type), cr); + String author; + params.Get("author", &author); + String text; + params.Get("text", &text); + + service->SendNotifications(static_cast(type), cr, author, text); } diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index c424d054b..ccc83279a 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -1112,7 +1112,7 @@ void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vec service->Flush(); } - service->RequestNotifications(NotificationCustom, service->GetLastCheckResult()); + service->RequestNotifications(NotificationCustom, service->GetLastCheckResult(), arguments[2], arguments[3]); } } @@ -1132,7 +1132,7 @@ void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vect service->Flush(); } - service->RequestNotifications(NotificationCustom, service->GetLastCheckResult()); + service->RequestNotifications(NotificationCustom, service->GetLastCheckResult(), arguments[3], arguments[4]); } void ExternalCommandProcessor::DelayHostNotification(double, const std::vector& arguments) @@ -1500,4 +1500,4 @@ void ExternalCommandProcessor::DisableSvcFlapping(double, const std::vectorSetEnableFlapping(false); } -} \ No newline at end of file +} diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index a9def5997..b65537c04 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -234,7 +234,7 @@ String Notification::NotificationTypeToString(NotificationType type) } } -void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force) +void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force, const String& author, const String& text) { ASSERT(!OwnsLock()); @@ -295,11 +295,11 @@ void Notification::BeginExecuteNotification(NotificationType type, const Diction 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)); + Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text)); } } -void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force) +void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author, const String& text) { ASSERT(!OwnsLock()); @@ -336,20 +336,11 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: rm.SetMethod("icinga::NotificationSent"); NotificationMessage params; - String comment_id = GetService()->GetLastCommentID(); - Dictionary::Ptr comment = Service::GetCommentByID(comment_id); - String author = ""; - String text = ""; - if (comment) { - author = comment->Get("author"); - text = comment->Get("text"); - Log(LogDebug, "icinga", "notification for service '" + GetService()->GetName() + "' with author " + author + "and text " + text); - } params.SetService(GetService()->GetName()); params.SetUser(user->GetName()); params.SetType(type); - params.SetAuthor(author); // figure out how to receive these attributes properly from service->comments TODO + params.SetAuthor(author); params.SetCommentText(text); params.SetCheckResult(cr); diff --git a/lib/icinga/notification.h b/lib/icinga/notification.h index c13b200ce..fdf28094b 100644 --- a/lib/icinga/notification.h +++ b/lib/icinga/notification.h @@ -84,7 +84,7 @@ public: double GetNextNotification(void) const; void SetNextNotification(double time); - void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force); + void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = ""); static String NotificationTypeToString(NotificationType type); @@ -109,7 +109,7 @@ private: Attribute m_HostName; Attribute m_Service; - void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force); + void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = ""); }; } diff --git a/lib/icinga/notificationrequestmessage.cpp b/lib/icinga/notificationrequestmessage.cpp index 931ef58f4..587a0c2f4 100644 --- a/lib/icinga/notificationrequestmessage.cpp +++ b/lib/icinga/notificationrequestmessage.cpp @@ -56,3 +56,27 @@ void NotificationRequestMessage::SetCheckResult(const Dictionary::Ptr& cr) { Set("check_result", cr); } + +String NotificationRequestMessage::GetAuthor(void) const +{ + String author; + Get("author", &author); + return author; +} + +void NotificationRequestMessage::SetAuthor(const String& author) +{ + Set("author", author); +} + +String NotificationRequestMessage::GetText(void) const +{ + String text; + Get("text", &text); + return text; +} + +void NotificationRequestMessage::SetText(const String& text) +{ + Set("text", text); +} diff --git a/lib/icinga/notificationrequestmessage.h b/lib/icinga/notificationrequestmessage.h index 88cd87f81..26cb29ad8 100644 --- a/lib/icinga/notificationrequestmessage.h +++ b/lib/icinga/notificationrequestmessage.h @@ -46,6 +46,12 @@ public: Dictionary::Ptr GetCheckResult(void) const; void SetCheckResult(const Dictionary::Ptr& cr); + + String GetAuthor(void) const; + void SetAuthor(const String& author); + + String GetText(void) const; + void SetText(const String& text); }; } diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index 975514d00..972b71c8d 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -44,16 +44,6 @@ int Service::GetNextCommentID(void) return l_NextCommentID; } -String Service::GetLastCommentID(void) const -{ - return m_LastCommentID; -} - -void Service::SetLastCommentID(String id) -{ - m_LastCommentID = id; -} - Dictionary::Ptr Service::GetComments(void) const { return m_Comments; @@ -100,8 +90,6 @@ String Service::AddComment(CommentType entryType, const String& author, Touch("comments"); } - SetLastCommentID(id); - return id; } diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 7939a9bd4..0fc5bbc30 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -36,7 +36,7 @@ static std::map > l_NotificationsCache; static bool l_NotificationsCacheNeedsUpdate = false; static Timer::Ptr l_NotificationsCacheTimer; -void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr& cr) +void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text) { RequestMessage msg; msg.SetMethod("icinga::SendNotifications"); @@ -47,12 +47,14 @@ void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr& params.SetService(GetName()); params.SetType(type); params.SetCheckResult(cr); + params.SetAuthor(author); + params.SetText(text); Log(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'"); EndpointManager::GetInstance()->SendAnycastMessage(Endpoint::Ptr(), msg); } -void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr) +void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text) { bool force = false; @@ -75,7 +77,7 @@ void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr BOOST_FOREACH(const Notification::Ptr& notification, notifications) { try { - notification->BeginExecuteNotification(type, cr, force); + notification->BeginExecuteNotification(type, cr, force, author, text); } catch (const std::exception& ex) { std::ostringstream msgbuf; msgbuf << "Exception occured during notification for service '" diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 8f5251653..d11fa40c1 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -297,7 +297,7 @@ void Service::AcknowledgeProblem(const String& author, const String& comment, Ac (void) AddComment(CommentAcknowledgement, author, comment, 0); - RequestNotifications(NotificationAcknowledgement, GetLastCheckResult()); + RequestNotifications(NotificationAcknowledgement, GetLastCheckResult(), author, comment); } void Service::ClearAcknowledgement(void) diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 0bea4742f..8c07698eb 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -222,8 +222,6 @@ public: /* Comments */ static int GetNextCommentID(void); - String GetLastCommentID(void) const; - void SetLastCommentID(String id); Dictionary::Ptr GetComments(void) const; @@ -246,8 +244,8 @@ public: bool GetEnableNotifications(void) const; void SetEnableNotifications(bool enabled); - void RequestNotifications(NotificationType type, const Dictionary::Ptr& cr); - void SendNotifications(NotificationType type, const Dictionary::Ptr& cr); + void RequestNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = ""); + void SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = ""); std::set GetNotifications(void) const; @@ -324,7 +322,6 @@ private: /* Comments */ Attribute m_Comments; - Attribute m_LastCommentID; static void CommentsExpireTimerHandler(void);