diff --git a/components/compat/compatlog.cpp b/components/compat/compatlog.cpp index a4298c397..2527db861 100644 --- a/components/compat/compatlog.cpp +++ b/components/compat/compatlog.cpp @@ -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(); @@ -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(¶ms)) - 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; diff --git a/components/compat/compatlog.h b/components/compat/compatlog.h index cef9a2037..5e739c136 100644 --- a/components/compat/compatlog.h +++ b/components/compat/compatlog.h @@ -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; diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 0fc5bbc30..be0581ed0 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -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 > l_NotificationsCache; static bool l_NotificationsCacheNeedsUpdate = false; static Timer::Ptr l_NotificationsCacheTimer; +boost::signals2::signal Service::OnNotificationSentChanged; + +void Service::NotificationSentRequestHandler(const RequestMessage& request) +{ + NotificationMessage params; + if (!request.GetParams(¶ms)) + 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; diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 5f04c44ef..3abc6655e 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -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", diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 8a4381186..7ee41897f 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -207,6 +207,7 @@ public: static boost::signals2::signal OnCheckerChanged; static boost::signals2::signal OnNextCheckChanged; + static boost::signals2::signal OnNotificationSentChanged; static boost::signals2::signal OnDowntimeChanged; static boost::signals2::signal OnFlappingChanged; @@ -363,6 +364,8 @@ private: static void RefreshNotificationsCache(void); + static void NotificationSentRequestHandler(const RequestMessage& request); + /* Event Handler */ Attribute m_EventCommand;