diff --git a/doc/12-icinga2-api.md b/doc/12-icinga2-api.md index db10da0f1d8..cb028c7e270 100644 --- a/doc/12-icinga2-api.md +++ b/doc/12-icinga2-api.md @@ -901,13 +901,14 @@ are disabled. Send a `POST` request to the URL endpoint `/v1/actions/acknowledge-problem`. - Parameter | Type | Description - ----------|-----------|-------------- - author | string | **Required.** Name of the author, may be empty. - comment | string | **Required.** Comment text, may be empty. - expiry | timestamp | **Optional.** If set, the acknowledgement will vanish after this timestamp. - sticky | boolean | **Optional.** If `true`, the default, the acknowledgement will remain until the service or host fully recovers. - notify | boolean | **Optional.** If `true`, a notification will be sent out to contacts to indicate this problem has been acknowledged. The default is false. + Parameter | Type | Description + -----------|-----------|-------------- + author | string | **Required.** Name of the author, may be empty. + comment | string | **Required.** Comment text, may be empty. + expiry | timestamp | **Optional.** If set, the acknowledgement will vanish after this timestamp. + sticky | boolean | **Optional.** If `true`, the default, the acknowledgement will remain until the service or host fully recovers. + notify | boolean | **Optional.** If `true`, a notification will be sent out to contacts to indicate this problem has been acknowledged. The default is false. + persistent | boolean | **Optional.** If `true`, the comment will remain after the acknowledgement either recovers or expires. In addition to these parameters a [filter](12-icinga2-api.md#icinga2-api-filters) must be provided. The valid types for this action are `Host` and `Service`. diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 0cd4ae57b63..86a564eb471 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -202,7 +202,7 @@ Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object, if (params->Contains("notify")) notify = true; if (params->Contains("persistent")) - persistent = (Convert::ToLong(HttpUtility::GetLastParameter(params, "persistent")) > 0 ? true : false ); + persistent = HttpUtility::GetLastParameter(params, "persistent"); if (params->Contains("expiry")) timestamp = HttpUtility::GetLastParameter(params, "expiry"); else diff --git a/lib/icinga/checkable-comment.cpp b/lib/icinga/checkable-comment.cpp index 344b0ef8a3f..54dd50cd59c 100644 --- a/lib/icinga/checkable-comment.cpp +++ b/lib/icinga/checkable-comment.cpp @@ -38,7 +38,11 @@ void Checkable::RemoveAllComments(void) void Checkable::RemoveCommentsByType(int type) { for (const Comment::Ptr& comment : GetComments()) { - if (comment->GetEntryType() == type && comment->GetPersistent() == false) + /* Do not remove comments set as persistent when it originates from an Acknowledgement */ + if (comment->GetEntryType() == CommentAcknowledgement && comment->GetPersistent()) + continue; + + if (comment->GetEntryType() == type) Comment::RemoveComment(comment->GetName()); } } diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index efa62f8c467..637c528f6f8 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -248,8 +248,12 @@ void Comment::CommentsExpireTimerHandler(void) } for (const Comment::Ptr& comment : comments) { + /* Do not remove comments set as persistent when it originates from an Acknowledgement */ + if (comment->GetEntryType() == CommentAcknowledgement && comment->IsActive() && comment->IsExpired() && comment->GetPersistent()) + continue; + /* Only remove comment which are activated after daemon start. */ - if (comment->IsActive() && comment->IsExpired() && comment->GetPersistent() == false) + if (comment->IsActive() && comment->IsExpired()) RemoveComment(comment->GetName()); } } diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti index d3c0f4120e8..aaf3e39863b 100644 --- a/lib/icinga/comment.ti +++ b/lib/icinga/comment.ti @@ -87,7 +87,7 @@ class Comment : ConfigObject < CommentNameComposer }; [config, required] String author; [config, required] String text; - [config] int persistent; + [config] bool persistent; [config] Timestamp expire_time; [state] int legacy_id; };