2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-01-29 16:29:09 +01:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/service.hpp"
|
2015-08-20 17:18:48 +02:00
|
|
|
#include "remote/configobjectutility.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configtype.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/objectlock.hpp"
|
|
|
|
#include "base/timer.hpp"
|
|
|
|
#include "base/utility.hpp"
|
2014-10-19 14:21:12 +02:00
|
|
|
#include "base/logger.hpp"
|
2021-07-29 12:10:42 +02:00
|
|
|
#include <utility>
|
2013-01-29 16:29:09 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Checkable::RemoveAllComments()
|
2013-01-29 16:29:09 +01:00
|
|
|
{
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Comment::Ptr& comment : GetComments()) {
|
2015-08-20 17:18:48 +02:00
|
|
|
Comment::RemoveComment(comment->GetName());
|
2013-08-20 11:06:04 +02:00
|
|
|
}
|
2013-01-29 16:29:09 +01:00
|
|
|
}
|
|
|
|
|
2023-03-03 15:48:11 +01:00
|
|
|
void Checkable::RemoveAckComments(const String& removedBy, double createdBefore)
|
2013-02-27 15:23:25 +01:00
|
|
|
{
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Comment::Ptr& comment : GetComments()) {
|
2023-03-03 11:53:02 +01:00
|
|
|
if (comment->GetEntryType() == CommentAcknowledgement) {
|
|
|
|
/* Do not remove persistent comments from an acknowledgement */
|
|
|
|
if (comment->GetPersistent()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-25 21:21:22 +01:00
|
|
|
|
2023-03-03 15:48:11 +01:00
|
|
|
if (comment->GetEntryTime() > createdBefore) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-11-21 16:28:22 +01:00
|
|
|
{
|
|
|
|
ObjectLock oLock (comment);
|
|
|
|
comment->SetRemovedBy(removedBy);
|
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
Comment::RemoveComment(comment->GetName());
|
2019-11-21 16:28:22 +01:00
|
|
|
}
|
2013-01-30 14:28:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::set<Comment::Ptr> Checkable::GetComments() const
|
2013-06-19 10:57:07 +02:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_CommentMutex);
|
2015-08-20 17:18:48 +02:00
|
|
|
return m_Comments;
|
2013-06-19 10:57:07 +02:00
|
|
|
}
|
|
|
|
|
2021-07-29 12:10:42 +02:00
|
|
|
Comment::Ptr Checkable::GetLastComment() const
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock (m_CommentMutex);
|
|
|
|
Comment::Ptr lastComment;
|
|
|
|
|
|
|
|
for (auto& comment : m_Comments) {
|
|
|
|
if (!lastComment || comment->GetEntryTime() > lastComment->GetEntryTime()) {
|
|
|
|
lastComment = comment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 17:47:54 +01:00
|
|
|
return lastComment;
|
2021-07-29 12:10:42 +02:00
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void Checkable::RegisterComment(const Comment::Ptr& comment)
|
2013-01-30 14:28:13 +01:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_CommentMutex);
|
2015-08-20 17:18:48 +02:00
|
|
|
m_Comments.insert(comment);
|
2013-01-30 14:28:13 +01:00
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void Checkable::UnregisterComment(const Comment::Ptr& comment)
|
2013-01-30 14:28:13 +01:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_CommentMutex);
|
2015-08-20 17:18:48 +02:00
|
|
|
m_Comments.erase(comment);
|
2013-01-29 16:29:09 +01:00
|
|
|
}
|