Merge pull request #9718 from Icinga/acknowledgement-sync-between-masters-are-not-working-9652

Checkable#ProcessCheckResult(): only clean up ack comments older than check result
This commit is contained in:
Julian Brost 2023-05-05 15:29:38 +02:00 committed by GitHub
commit eca8890d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 10 deletions

View File

@ -288,7 +288,7 @@ Dictionary::Ptr ApiActions::RemoveAcknowledgement(const ConfigObject::Ptr& objec
String removedBy (HttpUtility::GetLastParameter(params, "author"));
checkable->ClearAcknowledgement(removedBy);
checkable->RemoveCommentsByType(CommentAcknowledgement, removedBy);
checkable->RemoveAckComments(removedBy);
return ApiActions::CreateResult(200, "Successfully removed acknowledgement for object '" + checkable->GetName() + "'.");
}

View File

@ -321,7 +321,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
olock.Unlock();
if (remove_acknowledgement_comments)
RemoveCommentsByType(CommentAcknowledgement);
RemoveAckComments(String(), cr->GetExecutionEnd());
Dictionary::Ptr vars_after = new Dictionary({
{ "state", new_state },

View File

@ -19,14 +19,19 @@ void Checkable::RemoveAllComments()
}
}
void Checkable::RemoveCommentsByType(int type, const String& removedBy)
void Checkable::RemoveAckComments(const String& removedBy, double createdBefore)
{
for (const Comment::Ptr& comment : GetComments()) {
/* Do not remove persistent comments from an acknowledgement */
if (comment->GetEntryType() == CommentAcknowledgement && comment->GetPersistent())
continue;
if (comment->GetEntryType() == CommentAcknowledgement) {
/* Do not remove persistent comments from an acknowledgement */
if (comment->GetPersistent()) {
continue;
}
if (comment->GetEntryTime() > createdBefore) {
continue;
}
if (comment->GetEntryType() == type) {
{
ObjectLock oLock (comment);
comment->SetRemovedBy(removedBy);

View File

@ -17,6 +17,7 @@
#include <condition_variable>
#include <cstdint>
#include <functional>
#include <limits>
namespace icinga
{
@ -156,7 +157,7 @@ public:
/* Comments */
void RemoveAllComments();
void RemoveCommentsByType(int type, const String& removedBy = String());
void RemoveAckComments(const String& removedBy = String(), double createdBefore = std::numeric_limits<double>::max());
std::set<Comment::Ptr> GetComments() const;
Comment::Ptr GetLastComment() const;

View File

@ -665,7 +665,7 @@ void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vecto
service->ClearAcknowledgement("");
}
service->RemoveCommentsByType(CommentAcknowledgement);
service->RemoveAckComments();
}
void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector<String>& arguments)
@ -738,7 +738,7 @@ void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const std::vect
ObjectLock olock(host);
host->ClearAcknowledgement("");
}
host->RemoveCommentsByType(CommentAcknowledgement);
host->RemoveAckComments();
}
void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const std::vector<String>& arguments)