mirror of https://github.com/Icinga/icinga2.git
notifications: refactor NotificationSent message
like flapping and downtimes behave now. refs #4361
This commit is contained in:
parent
b9c4e7f931
commit
9334c1e346
|
@ -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(¶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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(¶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;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue