diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
commit | 0915b3ef56dfac3113cce55a59a5765dc94976be (patch) | |
tree | a8fea11d50b4f083e1bf0f90025ece7f0824784a /lib/icinga/checkable-comment.cpp | |
parent | Initial commit. (diff) | |
download | icinga2-upstream.tar.xz icinga2-upstream.zip |
Adding upstream version 2.13.6.upstream/2.13.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/icinga/checkable-comment.cpp')
-rw-r--r-- | lib/icinga/checkable-comment.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/icinga/checkable-comment.cpp b/lib/icinga/checkable-comment.cpp new file mode 100644 index 0000000..bb26a6d --- /dev/null +++ b/lib/icinga/checkable-comment.cpp @@ -0,0 +1,70 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#include "icinga/service.hpp" +#include "remote/configobjectutility.hpp" +#include "base/configtype.hpp" +#include "base/objectlock.hpp" +#include "base/timer.hpp" +#include "base/utility.hpp" +#include "base/logger.hpp" +#include <utility> + +using namespace icinga; + + +void Checkable::RemoveAllComments() +{ + for (const Comment::Ptr& comment : GetComments()) { + Comment::RemoveComment(comment->GetName()); + } +} + +void Checkable::RemoveCommentsByType(int type, const String& removedBy) +{ + for (const Comment::Ptr& comment : GetComments()) { + /* Do not remove persistent comments from an acknowledgement */ + if (comment->GetEntryType() == CommentAcknowledgement && comment->GetPersistent()) + continue; + + if (comment->GetEntryType() == type) { + { + ObjectLock oLock (comment); + comment->SetRemovedBy(removedBy); + } + + Comment::RemoveComment(comment->GetName()); + } + } +} + +std::set<Comment::Ptr> Checkable::GetComments() const +{ + std::unique_lock<std::mutex> lock(m_CommentMutex); + return m_Comments; +} + +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; + } + } + + return std::move(lastComment); +} + +void Checkable::RegisterComment(const Comment::Ptr& comment) +{ + std::unique_lock<std::mutex> lock(m_CommentMutex); + m_Comments.insert(comment); +} + +void Checkable::UnregisterComment(const Comment::Ptr& comment) +{ + std::unique_lock<std::mutex> lock(m_CommentMutex); + m_Comments.erase(comment); +} |