From 4399e82d9d648dec0d3f529c3c92c4cf3e4dd399 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 21 Mar 2022 15:41:22 +0100 Subject: [PATCH] Introduce Comment#sticky Carries whether ack was sticky for ack comments. --- lib/icinga/apiactions.cpp | 2 +- lib/icinga/comment.cpp | 3 ++- lib/icinga/comment.hpp | 2 +- lib/icinga/comment.ti | 1 + lib/icinga/externalcommandprocessor.cpp | 8 ++++---- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index f6999dbf0..bda0e336b 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -243,7 +243,7 @@ Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object, } Comment::AddComment(checkable, CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"), - HttpUtility::GetLastParameter(params, "comment"), persistent, timestamp); + HttpUtility::GetLastParameter(params, "comment"), persistent, timestamp, sticky == AcknowledgementSticky); checkable->AcknowledgeProblem(HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"), sticky, notify, persistent, Utility::GetTime(), timestamp); diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 7af67df25..aa3d5e52c 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -131,7 +131,7 @@ int Comment::GetNextCommentID() } String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryType, const String& author, - const String& text, bool persistent, double expireTime, const String& id, const MessageOrigin::Ptr& origin) + const String& text, bool persistent, double expireTime, bool sticky, const String& id, const MessageOrigin::Ptr& origin) { String fullName; @@ -147,6 +147,7 @@ String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryTyp attrs->Set("persistent", persistent); attrs->Set("expire_time", expireTime); attrs->Set("entry_type", entryType); + attrs->Set("sticky", sticky); attrs->Set("entry_time", Utility::GetTime()); Host::Ptr host; diff --git a/lib/icinga/comment.hpp b/lib/icinga/comment.hpp index 54410f63d..653208478 100644 --- a/lib/icinga/comment.hpp +++ b/lib/icinga/comment.hpp @@ -35,7 +35,7 @@ public: static int GetNextCommentID(); static String AddComment(const intrusive_ptr& checkable, CommentType entryType, - const String& author, const String& text, bool persistent, double expireTime, + const String& author, const String& text, bool persistent, double expireTime, bool sticky = false, const String& id = String(), const MessageOrigin::Ptr& origin = nullptr); static void RemoveComment(const String& id, bool removedManually = false, const String& removedBy = "", diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti index 3c45bf17c..853c28fac 100644 --- a/lib/icinga/comment.ti +++ b/lib/icinga/comment.ti @@ -66,6 +66,7 @@ class Comment : ConfigObject < CommentNameComposer [config, enum] CommentType entry_type { default {{{ return CommentUser; }}} }; + [config, no_user_view, no_user_modify] bool sticky; [config, required] String author; [config, required] String text; [config] bool persistent; diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index e79607761..f781a3412 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -616,7 +616,7 @@ void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vectorGetName() << "'" << (notify ? "" : ". Disabled notification"); - Comment::AddComment(service, CommentAcknowledgement, arguments[5], arguments[6], persistent, 0); + Comment::AddComment(service, CommentAcknowledgement, arguments[5], arguments[6], persistent, 0, sticky); service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent); } @@ -646,7 +646,7 @@ void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::ve Log(LogNotice, "ExternalCommandProcessor") << "Setting timed acknowledgement for service '" << service->GetName() << "'" << (notify ? "" : ". Disabled notification"); - Comment::AddComment(service, CommentAcknowledgement, arguments[6], arguments[7], persistent, timestamp); + Comment::AddComment(service, CommentAcknowledgement, arguments[6], arguments[7], persistent, timestamp, sticky); service->AcknowledgeProblem(arguments[6], arguments[7], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent, timestamp); } @@ -690,7 +690,7 @@ void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector< BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[1] + "' is already acknowledged.")); } - Comment::AddComment(host, CommentAcknowledgement, arguments[4], arguments[5], persistent, 0); + Comment::AddComment(host, CommentAcknowledgement, arguments[4], arguments[5], persistent, 0, sticky); host->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent); } @@ -720,7 +720,7 @@ void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::v BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[1] + "' is already acknowledged.")); } - Comment::AddComment(host, CommentAcknowledgement, arguments[5], arguments[6], persistent, timestamp); + Comment::AddComment(host, CommentAcknowledgement, arguments[5], arguments[6], persistent, timestamp, sticky); host->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent, timestamp); }