]> granicus.if.org Git - icinga2/commitdiff
compatlog: refactor custom/acknowledgement notifications with author/commenttext
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 1 Jul 2013 09:17:58 +0000 (11:17 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 1 Jul 2013 09:17:58 +0000 (11:17 +0200)
refs #4361

components/notification/notificationcomponent.cpp
lib/icinga/externalcommandprocessor.cpp
lib/icinga/notification.cpp
lib/icinga/notification.h
lib/icinga/notificationrequestmessage.cpp
lib/icinga/notificationrequestmessage.h
lib/icinga/service-comment.cpp
lib/icinga/service-notification.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index bc8b2703a2e2eb1bfa2adb04186b8cae8c37eb47..2bcac782640816a5493c0808ada1dac50527dfc4 100644 (file)
@@ -140,5 +140,10 @@ void NotificationComponent::SendNotificationsRequestHandler(const Endpoint::Ptr&
        if (!service)
                return;
 
-       service->SendNotifications(static_cast<NotificationType>(type), cr);
+       String author;
+       params.Get("author", &author);
+       String text;
+       params.Get("text", &text);
+
+       service->SendNotifications(static_cast<NotificationType>(type), cr, author, text);
 }
index c424d054bc9cd9253509f0f8abe0ea0665967ab0..ccc83279ab100638f831bf63afd955cb64a44175 100644 (file)
@@ -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<String>& arguments)
@@ -1500,4 +1500,4 @@ void ExternalCommandProcessor::DisableSvcFlapping(double, const std::vector<Stri
 
                service->SetEnableFlapping(false);
        }
-}
\ No newline at end of file
+}
index a9def59972647666aa4dd188fcf7db563667b6ce..b65537c04f6ea0ec9bffb528099e64d20f027b8c 100644 (file)
@@ -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);
 
index c13b200ce9e6a664ac9d052c8f1d866ef7ab53b3..fdf28094b70086e546c7a5266c153c793a862ab9 100644 (file)
@@ -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<String> m_HostName;
        Attribute<String> 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 = "");
 };
 
 }
index 931ef58f409a2c6809e5f1022edf20e2ff2ddd19..587a0c2f4a36a89873bfa98447095533123e075a 100644 (file)
@@ -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);
+}
index 88cd87f81bd643c3e18728e99fe3102d52ad9ce7..26cb29ad84427a749a63fee9e9b871b384671dd6 100644 (file)
@@ -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);
 };
 
 }
index 975514d00669c1ad3b44998cc2dda4a7c2890970..972b71c8da166545ad7f4622d7b8d526ab9301c9 100644 (file)
@@ -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;
 }
 
index 7939a9bd4bac8a1f64e01a1e353e53837e994515..0fc5bbc305fa99ad46446c3acf8357265943ac72 100644 (file)
@@ -36,7 +36,7 @@ static std::map<String, std::set<Notification::WeakPtr> > 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 '"
index 8f5251653efb32275ea5b5bf4affebdb1b429cf4..d11fa40c1b6779ad983b2b070d2eba0868d1ae73 100644 (file)
@@ -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)
index 0bea4742fef8d39a8206d59fb7143337a535472c..8c07698eb5632f55298d79165de9ce952d620a94 100644 (file)
@@ -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<Notification::Ptr> GetNotifications(void) const;
 
@@ -324,7 +322,6 @@ private:
 
        /* Comments */
        Attribute<Dictionary::Ptr> m_Comments;
-       Attribute<String> m_LastCommentID;
 
        static void CommentsExpireTimerHandler(void);