mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
compatlog: refactor custom/acknowledgement notifications with author/commenttext
refs #4361
This commit is contained in:
parent
cd48a4946a
commit
6f7b231302
@ -140,5 +140,10 @@ void NotificationComponent::SendNotificationsRequestHandler(const Endpoint::Ptr&
|
|||||||
if (!service)
|
if (!service)
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -1112,7 +1112,7 @@ void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vec
|
|||||||
service->Flush();
|
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->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
service->RequestNotifications(NotificationCustom, service->GetLastCheckResult());
|
service->RequestNotifications(NotificationCustom, service->GetLastCheckResult(), arguments[3], arguments[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalCommandProcessor::DelayHostNotification(double, const std::vector<String>& arguments)
|
void ExternalCommandProcessor::DelayHostNotification(double, const std::vector<String>& arguments)
|
||||||
|
@ -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());
|
ASSERT(!OwnsLock());
|
||||||
|
|
||||||
@ -295,11 +295,11 @@ void Notification::BeginExecuteNotification(NotificationType type, const Diction
|
|||||||
|
|
||||||
BOOST_FOREACH(const User::Ptr& user, allUsers) {
|
BOOST_FOREACH(const User::Ptr& user, allUsers) {
|
||||||
Log(LogDebug, "icinga", "Sending notification for user '" + user->GetName() + "'");
|
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());
|
ASSERT(!OwnsLock());
|
||||||
|
|
||||||
@ -336,20 +336,11 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
|
|||||||
rm.SetMethod("icinga::NotificationSent");
|
rm.SetMethod("icinga::NotificationSent");
|
||||||
|
|
||||||
NotificationMessage params;
|
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.SetService(GetService()->GetName());
|
||||||
params.SetUser(user->GetName());
|
params.SetUser(user->GetName());
|
||||||
params.SetType(type);
|
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.SetCommentText(text);
|
||||||
params.SetCheckResult(cr);
|
params.SetCheckResult(cr);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public:
|
|||||||
double GetNextNotification(void) const;
|
double GetNextNotification(void) const;
|
||||||
void SetNextNotification(double time);
|
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);
|
static String NotificationTypeToString(NotificationType type);
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ private:
|
|||||||
Attribute<String> m_HostName;
|
Attribute<String> m_HostName;
|
||||||
Attribute<String> m_Service;
|
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 = "");
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,3 +56,27 @@ void NotificationRequestMessage::SetCheckResult(const Dictionary::Ptr& cr)
|
|||||||
{
|
{
|
||||||
Set("check_result", 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);
|
||||||
|
}
|
||||||
|
@ -46,6 +46,12 @@ public:
|
|||||||
|
|
||||||
Dictionary::Ptr GetCheckResult(void) const;
|
Dictionary::Ptr GetCheckResult(void) const;
|
||||||
void SetCheckResult(const Dictionary::Ptr& cr);
|
void SetCheckResult(const Dictionary::Ptr& cr);
|
||||||
|
|
||||||
|
String GetAuthor(void) const;
|
||||||
|
void SetAuthor(const String& author);
|
||||||
|
|
||||||
|
String GetText(void) const;
|
||||||
|
void SetText(const String& text);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,16 +44,6 @@ int Service::GetNextCommentID(void)
|
|||||||
return l_NextCommentID;
|
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
|
Dictionary::Ptr Service::GetComments(void) const
|
||||||
{
|
{
|
||||||
return m_Comments;
|
return m_Comments;
|
||||||
@ -100,8 +90,6 @@ String Service::AddComment(CommentType entryType, const String& author,
|
|||||||
Touch("comments");
|
Touch("comments");
|
||||||
}
|
}
|
||||||
|
|
||||||
SetLastCommentID(id);
|
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ static std::map<String, std::set<Notification::WeakPtr> > l_NotificationsCache;
|
|||||||
static bool l_NotificationsCacheNeedsUpdate = false;
|
static bool l_NotificationsCacheNeedsUpdate = false;
|
||||||
static Timer::Ptr l_NotificationsCacheTimer;
|
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;
|
RequestMessage msg;
|
||||||
msg.SetMethod("icinga::SendNotifications");
|
msg.SetMethod("icinga::SendNotifications");
|
||||||
@ -47,12 +47,14 @@ void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr&
|
|||||||
params.SetService(GetName());
|
params.SetService(GetName());
|
||||||
params.SetType(type);
|
params.SetType(type);
|
||||||
params.SetCheckResult(cr);
|
params.SetCheckResult(cr);
|
||||||
|
params.SetAuthor(author);
|
||||||
|
params.SetText(text);
|
||||||
|
|
||||||
Log(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'");
|
Log(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'");
|
||||||
EndpointManager::GetInstance()->SendAnycastMessage(Endpoint::Ptr(), msg);
|
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;
|
bool force = false;
|
||||||
|
|
||||||
@ -75,7 +77,7 @@ void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr
|
|||||||
|
|
||||||
BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
|
BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
|
||||||
try {
|
try {
|
||||||
notification->BeginExecuteNotification(type, cr, force);
|
notification->BeginExecuteNotification(type, cr, force, author, text);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "Exception occured during notification for service '"
|
msgbuf << "Exception occured during notification for service '"
|
||||||
|
@ -297,7 +297,7 @@ void Service::AcknowledgeProblem(const String& author, const String& comment, Ac
|
|||||||
|
|
||||||
(void) AddComment(CommentAcknowledgement, author, comment, 0);
|
(void) AddComment(CommentAcknowledgement, author, comment, 0);
|
||||||
|
|
||||||
RequestNotifications(NotificationAcknowledgement, GetLastCheckResult());
|
RequestNotifications(NotificationAcknowledgement, GetLastCheckResult(), author, comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::ClearAcknowledgement(void)
|
void Service::ClearAcknowledgement(void)
|
||||||
|
@ -222,8 +222,6 @@ public:
|
|||||||
|
|
||||||
/* Comments */
|
/* Comments */
|
||||||
static int GetNextCommentID(void);
|
static int GetNextCommentID(void);
|
||||||
String GetLastCommentID(void) const;
|
|
||||||
void SetLastCommentID(String id);
|
|
||||||
|
|
||||||
Dictionary::Ptr GetComments(void) const;
|
Dictionary::Ptr GetComments(void) const;
|
||||||
|
|
||||||
@ -246,8 +244,8 @@ public:
|
|||||||
bool GetEnableNotifications(void) const;
|
bool GetEnableNotifications(void) const;
|
||||||
void SetEnableNotifications(bool enabled);
|
void SetEnableNotifications(bool enabled);
|
||||||
|
|
||||||
void RequestNotifications(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);
|
void SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = "");
|
||||||
|
|
||||||
std::set<Notification::Ptr> GetNotifications(void) const;
|
std::set<Notification::Ptr> GetNotifications(void) const;
|
||||||
|
|
||||||
@ -324,7 +322,6 @@ private:
|
|||||||
|
|
||||||
/* Comments */
|
/* Comments */
|
||||||
Attribute<Dictionary::Ptr> m_Comments;
|
Attribute<Dictionary::Ptr> m_Comments;
|
||||||
Attribute<String> m_LastCommentID;
|
|
||||||
|
|
||||||
static void CommentsExpireTimerHandler(void);
|
static void CommentsExpireTimerHandler(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user