From dceb29c742d5189a8f06e8957f740f37fca736e5 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 1e3fe851f..83b6a60a8 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -275,7 +275,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 83c39e923..ea2428588 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -321,7 +321,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr 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 135f35520..29fc65563 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 6a46425a9..96df5bd47 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -156,7 +156,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 4662d4477bd4a7fda508acd64f8fad25a8af7fed 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 29fc65563..71cfac619 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 96df5bd47..3d48b1445 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace icinga { @@ -156,7 +157,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 6414fd19f57e6a24c23075ab17ff223690f89de4 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 ea2428588..efa9477a2 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -321,7 +321,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr olock.Unlock(); if (remove_acknowledgement_comments) - RemoveAckComments(); + RemoveAckComments(String(), cr->GetExecutionEnd()); Dictionary::Ptr vars_after = new Dictionary({ { "state", new_state },