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);
}
service->Flush();
}
- service->RequestNotifications(NotificationCustom, service->GetLastCheckResult());
+ service->RequestNotifications(NotificationCustom, service->GetLastCheckResult(), arguments[2], arguments[3]);
}
}
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)
service->SetEnableFlapping(false);
}
-}
\ No newline at end of file
+}
}
}
-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());
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());
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);
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);
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 = "");
};
}
{
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);
+}
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);
};
}
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;
Touch("comments");
}
- SetLastCommentID(id);
-
return id;
}
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");
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;
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 '"
(void) AddComment(CommentAcknowledgement, author, comment, 0);
- RequestNotifications(NotificationAcknowledgement, GetLastCheckResult());
+ RequestNotifications(NotificationAcknowledgement, GetLastCheckResult(), author, comment);
}
void Service::ClearAcknowledgement(void)
/* Comments */
static int GetNextCommentID(void);
- String GetLastCommentID(void) const;
- void SetLastCommentID(String id);
Dictionary::Ptr GetComments(void) const;
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;
/* Comments */
Attribute<Dictionary::Ptr> m_Comments;
- Attribute<String> m_LastCommentID;
static void CommentsExpireTimerHandler(void);