From 80bf316e7b5553264d43e1e3c845f230a1cb1f94 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 21 Nov 2019 16:28:22 +0100 Subject: [PATCH] /v1/actions/remove-acknowledgement: let users specify themselves --- lib/icinga/apiactions.cpp | 2 +- lib/icinga/checkable-comment.cpp | 10 ++++++++-- lib/icinga/checkable.hpp | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 3f0d2346f..ce2c2d653 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -245,7 +245,7 @@ Dictionary::Ptr ApiActions::RemoveAcknowledgement(const ConfigObject::Ptr& objec + object->GetName() + "."); checkable->ClearAcknowledgement(); - checkable->RemoveCommentsByType(CommentAcknowledgement); + checkable->RemoveCommentsByType(CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author")); return ApiActions::CreateResult(200, "Successfully removed acknowledgement for object '" + checkable->GetName() + "'."); } diff --git a/lib/icinga/checkable-comment.cpp b/lib/icinga/checkable-comment.cpp index b2184e1ff..88f5a5207 100644 --- a/lib/icinga/checkable-comment.cpp +++ b/lib/icinga/checkable-comment.cpp @@ -18,15 +18,21 @@ void Checkable::RemoveAllComments() } } -void Checkable::RemoveCommentsByType(int type) +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) + if (comment->GetEntryType() == type) { + { + ObjectLock oLock (comment); + comment->SetRemovedBy(removedBy); + } + Comment::RemoveComment(comment->GetName()); + } } } diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index 498cb1d8f..a5d34725b 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -133,7 +133,7 @@ public: /* Comments */ void RemoveAllComments(); - void RemoveCommentsByType(int type); + void RemoveCommentsByType(int type, const String& removedBy = String()); std::set GetComments() const; void RegisterComment(const Comment::Ptr& comment);