From 0470fe12a7921d292f055bf9a02116f8697fae87 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 3 Mar 2023 11:53:02 +0100 Subject: [PATCH 1/3] Checkable#RemoveCommentsByType(): remove redundant parameter --- lib/icinga/apiactions.cpp | 2 +- lib/icinga/checkable-check.cpp | 2 +- lib/icinga/checkable-comment.cpp | 11 ++++++----- lib/icinga/checkable.hpp | 2 +- lib/icinga/externalcommandprocessor.cpp | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index bda0e336b..0ea4e8a88 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -263,7 +263,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() + "'."); } diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index a302bd923..737482f0f 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -319,7 +319,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig olock.Unlock(); if (remove_acknowledgement_comments) - RemoveCommentsByType(CommentAcknowledgement); + RemoveAckComments(); Dictionary::Ptr vars_after = new Dictionary({ { "state", new_state }, diff --git a/lib/icinga/checkable-comment.cpp b/lib/icinga/checkable-comment.cpp index bb26a6d3c..bc679e43d 100644 --- a/lib/icinga/checkable-comment.cpp +++ b/lib/icinga/checkable-comment.cpp @@ -19,14 +19,15 @@ void Checkable::RemoveAllComments() } } -void Checkable::RemoveCommentsByType(int type, const String& removedBy) +void Checkable::RemoveAckComments(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() == CommentAcknowledgement) { + /* Do not remove persistent comments from an acknowledgement */ + if (comment->GetPersistent()) { + continue; + } - if (comment->GetEntryType() == type) { { ObjectLock oLock (comment); comment->SetRemovedBy(removedBy); diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index bb8e567b4..54932e7be 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -149,7 +149,7 @@ public: /* Comments */ void RemoveAllComments(); - void RemoveCommentsByType(int type, const String& removedBy = String()); + void RemoveAckComments(const String& removedBy = String()); std::set GetComments() const; Comment::Ptr GetLastComment() const; diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index f781a3412..9850da030 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -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& 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& arguments) From c160c4b62e83a0c915698ce6f2f543b004d6769c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 3 Mar 2023 15:48:11 +0100 Subject: [PATCH 2/3] Checkable#RemoveAckComments(): add optional comment entry time filter --- lib/icinga/checkable-comment.cpp | 6 +++++- lib/icinga/checkable.hpp | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/icinga/checkable-comment.cpp b/lib/icinga/checkable-comment.cpp index bc679e43d..eab3bcaa8 100644 --- a/lib/icinga/checkable-comment.cpp +++ b/lib/icinga/checkable-comment.cpp @@ -19,7 +19,7 @@ void Checkable::RemoveAllComments() } } -void Checkable::RemoveAckComments(const String& removedBy) +void Checkable::RemoveAckComments(const String& removedBy, double createdBefore) { for (const Comment::Ptr& comment : GetComments()) { if (comment->GetEntryType() == CommentAcknowledgement) { @@ -28,6 +28,10 @@ void Checkable::RemoveAckComments(const String& removedBy) continue; } + if (comment->GetEntryTime() > createdBefore) { + continue; + } + { ObjectLock oLock (comment); comment->SetRemovedBy(removedBy); diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index 54932e7be..b0a96dc8f 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace icinga { @@ -149,7 +150,7 @@ public: /* Comments */ void RemoveAllComments(); - void RemoveAckComments(const String& removedBy = String()); + void RemoveAckComments(const String& removedBy = String(), double createdBefore = std::numeric_limits::max()); std::set GetComments() const; Comment::Ptr GetLastComment() const; From 6dffc57a3714822bfad75423a1e08c4940172a7b Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 3 Mar 2023 12:07:37 +0100 Subject: [PATCH 3/3] Checkable#ProcessCheckResult(): only clean up ack comments older than check result Normally if for some reason an ack comment still exists on a checkable not acked anymore, still clean it up. But while replaying log config objects incl. ack comments come before check results and acks. I.e. 1) ack comment, 2) DOWN check result and 3) ack. Not 1) DOWN check result, 2) ack and 3) ack comment. So the checkable is temporarily not acked, but already has the ack comment. In this case the DOWN check result which is older than the ack comment shall not clean up the latter. --- lib/icinga/checkable-check.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index 737482f0f..a70f8d69c 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -319,7 +319,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig olock.Unlock(); if (remove_acknowledgement_comments) - RemoveAckComments(); + RemoveAckComments(String(), cr->GetExecutionEnd()); Dictionary::Ptr vars_after = new Dictionary({ { "state", new_state },