mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 15:44:11 +02:00
Merge pull request #7646 from Icinga/feature/remove-comment-author
/v1/actions/remove-comment: let users specify themselves
This commit is contained in:
commit
ed1cede0a7
@ -1204,7 +1204,11 @@ been removed the next notification will be sent again.
|
|||||||
|
|
||||||
Send a `POST` request to the URL endpoint `/v1/actions/remove-acknowledgement`.
|
Send a `POST` request to the URL endpoint `/v1/actions/remove-acknowledgement`.
|
||||||
|
|
||||||
A [filter](12-icinga2-api.md#icinga2-api-filters) must be provided. The valid types for this action are `Host` and `Service`.
|
Parameter | Type | Description
|
||||||
|
----------|--------|--------------
|
||||||
|
author | String | **Optional.** Name of the removal requestor.
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
The example removes all service acknowledgements:
|
The example removes all service acknowledgements:
|
||||||
|
|
||||||
@ -1272,7 +1276,11 @@ Icinga 2 when [adding a comment](12-icinga2-api.md#icinga2-api-actions-add-comme
|
|||||||
|
|
||||||
Send a `POST` request to the URL endpoint `/v1/actions/remove-comment`.
|
Send a `POST` request to the URL endpoint `/v1/actions/remove-comment`.
|
||||||
|
|
||||||
A [filter](12-icinga2-api.md#icinga2-api-filters) must be provided. The valid types for this action are `Host`, `Service` and `Comment`.
|
Parameter | Type | Description
|
||||||
|
----------|--------|--------------
|
||||||
|
author | String | **Optional.** Name of the removal requestor.
|
||||||
|
|
||||||
|
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`, `Service` and `Comment`.
|
||||||
|
|
||||||
Example for a simple filter using the `comment` URL parameter:
|
Example for a simple filter using the `comment` URL parameter:
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ Dictionary::Ptr ApiActions::RemoveAcknowledgement(const ConfigObject::Ptr& objec
|
|||||||
+ object->GetName() + ".");
|
+ object->GetName() + ".");
|
||||||
|
|
||||||
checkable->ClearAcknowledgement();
|
checkable->ClearAcknowledgement();
|
||||||
checkable->RemoveCommentsByType(CommentAcknowledgement);
|
checkable->RemoveCommentsByType(CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"));
|
||||||
|
|
||||||
return ApiActions::CreateResult(200, "Successfully removed acknowledgement for object '" + checkable->GetName() + "'.");
|
return ApiActions::CreateResult(200, "Successfully removed acknowledgement for object '" + checkable->GetName() + "'.");
|
||||||
}
|
}
|
||||||
@ -280,12 +280,18 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object,
|
|||||||
Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object,
|
Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object,
|
||||||
const Dictionary::Ptr& params)
|
const Dictionary::Ptr& params)
|
||||||
{
|
{
|
||||||
|
auto author (HttpUtility::GetLastParameter(params, "author"));
|
||||||
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
|
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
|
||||||
|
|
||||||
if (checkable) {
|
if (checkable) {
|
||||||
std::set<Comment::Ptr> comments = checkable->GetComments();
|
std::set<Comment::Ptr> comments = checkable->GetComments();
|
||||||
|
|
||||||
for (const Comment::Ptr& comment : comments) {
|
for (const Comment::Ptr& comment : comments) {
|
||||||
|
{
|
||||||
|
ObjectLock oLock (comment);
|
||||||
|
comment->SetRemovedBy(author);
|
||||||
|
}
|
||||||
|
|
||||||
Comment::RemoveComment(comment->GetName());
|
Comment::RemoveComment(comment->GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,6 +303,11 @@ Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object,
|
|||||||
if (!comment)
|
if (!comment)
|
||||||
return ApiActions::CreateResult(404, "Cannot remove non-existent comment object.");
|
return ApiActions::CreateResult(404, "Cannot remove non-existent comment object.");
|
||||||
|
|
||||||
|
{
|
||||||
|
ObjectLock oLock (comment);
|
||||||
|
comment->SetRemovedBy(author);
|
||||||
|
}
|
||||||
|
|
||||||
String commentName = comment->GetName();
|
String commentName = comment->GetName();
|
||||||
|
|
||||||
Comment::RemoveComment(commentName);
|
Comment::RemoveComment(commentName);
|
||||||
|
@ -18,17 +18,23 @@ void Checkable::RemoveAllComments()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Checkable::RemoveCommentsByType(int type)
|
void Checkable::RemoveCommentsByType(int type, const String& removedBy)
|
||||||
{
|
{
|
||||||
for (const Comment::Ptr& comment : GetComments()) {
|
for (const Comment::Ptr& comment : GetComments()) {
|
||||||
/* Do not remove persistent comments from an acknowledgement */
|
/* Do not remove persistent comments from an acknowledgement */
|
||||||
if (comment->GetEntryType() == CommentAcknowledgement && comment->GetPersistent())
|
if (comment->GetEntryType() == CommentAcknowledgement && comment->GetPersistent())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (comment->GetEntryType() == type)
|
if (comment->GetEntryType() == type) {
|
||||||
|
{
|
||||||
|
ObjectLock oLock (comment);
|
||||||
|
comment->SetRemovedBy(removedBy);
|
||||||
|
}
|
||||||
|
|
||||||
Comment::RemoveComment(comment->GetName());
|
Comment::RemoveComment(comment->GetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::set<Comment::Ptr> Checkable::GetComments() const
|
std::set<Comment::Ptr> Checkable::GetComments() const
|
||||||
{
|
{
|
||||||
|
@ -133,7 +133,7 @@ public:
|
|||||||
|
|
||||||
/* Comments */
|
/* Comments */
|
||||||
void RemoveAllComments();
|
void RemoveAllComments();
|
||||||
void RemoveCommentsByType(int type);
|
void RemoveCommentsByType(int type, const String& removedBy = String());
|
||||||
|
|
||||||
std::set<Comment::Ptr> GetComments() const;
|
std::set<Comment::Ptr> GetComments() const;
|
||||||
void RegisterComment(const Comment::Ptr& comment);
|
void RegisterComment(const Comment::Ptr& comment);
|
||||||
|
@ -71,6 +71,8 @@ class Comment : ConfigObject < CommentNameComposer
|
|||||||
[config] bool persistent;
|
[config] bool persistent;
|
||||||
[config] Timestamp expire_time;
|
[config] Timestamp expire_time;
|
||||||
[state] int legacy_id;
|
[state] int legacy_id;
|
||||||
|
|
||||||
|
[no_user_view, no_user_modify] String removed_by;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1489,7 +1489,7 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
|
|||||||
"comment_id", GetObjectIdentifier(comment),
|
"comment_id", GetObjectIdentifier(comment),
|
||||||
"environment_id", SHA1(GetEnvironment()),
|
"environment_id", SHA1(GetEnvironment()),
|
||||||
"entry_time", Convert::ToString(TimestampToMilliseconds(comment->GetEntryTime())),
|
"entry_time", Convert::ToString(TimestampToMilliseconds(comment->GetEntryTime())),
|
||||||
"author", Utility::ValidateUTF8(comment->GetAuthor()),
|
"author", Utility::ValidateUTF8(comment->GetRemovedBy()),
|
||||||
"comment", Utility::ValidateUTF8(comment->GetText()),
|
"comment", Utility::ValidateUTF8(comment->GetText()),
|
||||||
"entry_type", Convert::ToString(comment->GetEntryType()),
|
"entry_type", Convert::ToString(comment->GetEntryType()),
|
||||||
"is_persistent", Convert::ToString((unsigned short)comment->GetPersistent()),
|
"is_persistent", Convert::ToString((unsigned short)comment->GetPersistent()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user