compatlog: refactor custom/acknowledgement notifications with author/commenttext

refs #4361
This commit is contained in:
Michael Friedrich 2013-07-01 11:17:58 +02:00
parent cd48a4946a
commit 6f7b231302
10 changed files with 53 additions and 40 deletions

View 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);
}

View 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);
}
}
}

View 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);

View 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 = "");
};
}

View 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);
}

View 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);
};
}

View 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;
}

View 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 '"

View 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)

View 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);