]> granicus.if.org Git - icinga2/commitdiff
notifications: refactor NotificationSent message
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 1 Jul 2013 15:56:21 +0000 (17:56 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 1 Jul 2013 15:56:21 +0000 (17:56 +0200)
like flapping and downtimes behave now.

refs #4361

components/compat/compatlog.cpp
components/compat/compatlog.h
lib/icinga/service-notification.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index a4298c397d99f2b4228f5a98ad759e67328eb77c..2527db8614c8884886328d499520e9c50ce83d2c 100644 (file)
@@ -68,10 +68,9 @@ void CompatLog::Start(void)
        m_Endpoint = Endpoint::MakeEndpoint("compatlog_" + GetName(), false);
        m_Endpoint->RegisterTopicHandler("checker::CheckResult",
            boost::bind(&CompatLog::CheckResultRequestHandler, this, _3));
-       m_Endpoint->RegisterTopicHandler("icinga::NotificationSent",
-           boost::bind(&CompatLog::NotificationSentRequestHandler, this, _3));
 
        Service::OnDowntimeChanged.connect(bind(&CompatLog::DowntimeHandler, this, _1, _2));
+       Service::OnNotificationSentChanged.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6));
        Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2));
 
        m_RotationTimer = boost::make_shared<Timer>();
@@ -273,31 +272,21 @@ void CompatLog::DowntimeHandler(const Service::Ptr& service, DowntimeState downt
 /**
  * @threadsafety Always.
  */
-void CompatLog::NotificationSentRequestHandler(const RequestMessage& request)
+void CompatLog::NotificationSentHandler(const Service::Ptr& service, const String& username,
+               NotificationType const& notification_type, Dictionary::Ptr const& cr,
+               const String& author, const String& comment_text)
 {
-        NotificationMessage params;
-        if (!request.GetParams(&params))
-                return;
-
-        String svcname = params.GetService();
-        Service::Ptr service = Service::GetByName(svcname);
-
         Host::Ptr host = service->GetHost();
 
         if (!host)
                 return;
 
-       String username = params.GetUser();
-       String author = params.GetAuthor();
-       String comment_text = params.GetCommentText();
-
        CheckCommand::Ptr commandObj = service->GetCheckCommand();
 
        String check_command = "";
        if (commandObj)
                check_command = commandObj->GetName();
 
-       NotificationType notification_type = params.GetType();
        String notification_type_str = Notification::NotificationTypeToString(notification_type);
 
        String author_comment = "";
@@ -305,7 +294,6 @@ void CompatLog::NotificationSentRequestHandler(const RequestMessage& request)
                author_comment = ";" + author + ";" + comment_text;
        }
 
-        Dictionary::Ptr cr = params.GetCheckResult();
         if (!cr)
                 return;
 
index cef9a2037fe0bd2b35c83469df9d357574221d4a..5e739c1364134079a31f92e9976fa26a463ad1cf 100644 (file)
@@ -64,8 +64,8 @@ private:
 
        Endpoint::Ptr m_Endpoint;
        void CheckResultRequestHandler(const RequestMessage& request);
-       void NotificationSentRequestHandler(const RequestMessage& request);
        void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state);
+       void NotificationSentHandler(const Service::Ptr& service, const String& username, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text);
        void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
 
        Timer::Ptr m_RotationTimer;
index 0fc5bbc305fa99ad46446c3acf8357265943ac72..be0581ed07ee5a8b7b935f5e1753f48c9d0a6a2b 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "icinga/service.h"
 #include "icinga/notificationrequestmessage.h"
+#include "icinga/notificationmessage.h"
 #include "remoting/endpointmanager.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
@@ -36,6 +37,27 @@ static std::map<String, std::set<Notification::WeakPtr> > l_NotificationsCache;
 static bool l_NotificationsCacheNeedsUpdate = false;
 static Timer::Ptr l_NotificationsCacheTimer;
 
+boost::signals2::signal<void (const Service::Ptr&, const String&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentChanged;
+
+void Service::NotificationSentRequestHandler(const RequestMessage& request)
+{
+       NotificationMessage params;
+       if (!request.GetParams(&params))
+               return;
+
+       String svcname = params.GetService();
+       Service::Ptr service = Service::GetByName(svcname);
+
+       String username = params.GetUser();
+       String author = params.GetAuthor();
+       String comment_text = params.GetCommentText();
+
+       NotificationType notification_type = params.GetType();
+       Dictionary::Ptr cr = params.GetCheckResult();
+
+       OnNotificationSentChanged(service, username, notification_type, cr, author, comment_text);
+}
+
 void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text)
 {
        RequestMessage msg;
index 5f04c44eff306c6fc2858c071f6c2ed467412c20..3abc6655ed9f570641c050ff561bb5068ef7f374 100644 (file)
@@ -109,6 +109,8 @@ Service::~Service(void)
 void Service::Initialize(void)
 {
        m_Endpoint = Endpoint::MakeEndpoint("service", false);
+       m_Endpoint->RegisterTopicHandler("icinga::NotificationSent",
+           boost::bind(&Service::NotificationSentRequestHandler, _3));
        m_Endpoint->RegisterTopicHandler("icinga::Downtime",
            boost::bind(&Service::DowntimeRequestHandler, _3));
        m_Endpoint->RegisterTopicHandler("icinga::Flapping",
index 8a43811865983d769a21b5f34c5c79ae461467ed..7ee41897f6c6301a8f27434a8d938cb91cda2d51 100644 (file)
@@ -207,6 +207,7 @@ public:
 
        static boost::signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
        static boost::signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
+       static boost::signals2::signal<void (const Service::Ptr&, const String&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentChanged;
        static boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> OnDowntimeChanged;
        static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
 
@@ -363,6 +364,8 @@ private:
 
        static void RefreshNotificationsCache(void);
 
+       static void NotificationSentRequestHandler(const RequestMessage& request);
+
        /* Event Handler */
        Attribute<String> m_EventCommand;