1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
/* 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::RemoveAckComments(const String& removedBy, double createdBefore)
{
for (const Comment::Ptr& comment : GetComments()) {
if (comment->GetEntryType() == CommentAcknowledgement) {
/* Do not remove persistent comments from an acknowledgement */
if (comment->GetPersistent()) {
continue;
}
if (comment->GetEntryTime() > createdBefore) {
continue;
}
{
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 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);
}
|