mirror of https://github.com/Icinga/icinga2.git
Merge pull request #7645 from Icinga/feature/remove-downtime-author
/v1/actions/remove-downtime: let users specify themselves
This commit is contained in:
commit
a98c5e965c
|
@ -1381,7 +1381,11 @@ Icinga 2 when [scheduling a downtime](12-icinga2-api.md#icinga2-api-actions-sche
|
|||
|
||||
Send a `POST` request to the URL endpoint `/v1/actions/remove-downtime`.
|
||||
|
||||
A [filter](12-icinga2-api.md#icinga2-api-filters) must be provided. The valid types for this action are `Host`, `Service` and `Downtime`.
|
||||
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 `Downtime`.
|
||||
|
||||
Example for a simple filter using the `downtime` URL parameter:
|
||||
|
||||
|
|
|
@ -457,12 +457,18 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
|
|||
Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object,
|
||||
const Dictionary::Ptr& params)
|
||||
{
|
||||
auto author (HttpUtility::GetLastParameter(params, "author"));
|
||||
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
|
||||
|
||||
if (checkable) {
|
||||
std::set<Downtime::Ptr> downtimes = checkable->GetDowntimes();
|
||||
|
||||
for (const Downtime::Ptr& downtime : downtimes) {
|
||||
{
|
||||
ObjectLock oLock (downtime);
|
||||
downtime->SetRemovedBy(author);
|
||||
}
|
||||
|
||||
Downtime::RemoveDowntime(downtime->GetName(), true);
|
||||
}
|
||||
|
||||
|
@ -474,6 +480,11 @@ Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object,
|
|||
if (!downtime)
|
||||
return ApiActions::CreateResult(404, "Cannot remove non-existent downtime object.");
|
||||
|
||||
{
|
||||
ObjectLock oLock (downtime);
|
||||
downtime->SetRemovedBy(author);
|
||||
}
|
||||
|
||||
String downtimeName = downtime->GetName();
|
||||
|
||||
Downtime::RemoveDowntime(downtimeName, true);
|
||||
|
|
|
@ -70,6 +70,8 @@ class Downtime : ConfigObject < DowntimeNameComposer
|
|||
[state] bool was_cancelled;
|
||||
[config] String config_owner;
|
||||
[config] String authoritative_zone;
|
||||
|
||||
[no_user_view, no_user_modify] String removed_by;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1379,7 +1379,7 @@ void IcingaDB::SendRemovedDowntime(const Downtime::Ptr& downtime)
|
|||
"downtime_id", GetObjectIdentifier(downtime),
|
||||
"environment_id", SHA1(GetEnvironment()),
|
||||
"entry_time", Convert::ToString(TimestampToMilliseconds(downtime->GetEntryTime())),
|
||||
"author", Utility::ValidateUTF8(downtime->GetAuthor()),
|
||||
"author", Utility::ValidateUTF8(downtime->GetRemovedBy()),
|
||||
"comment", Utility::ValidateUTF8(downtime->GetComment()),
|
||||
"is_flexible", Convert::ToString((unsigned short)!downtime->GetFixed()),
|
||||
"flexible_duration", Convert::ToString(downtime->GetDuration()),
|
||||
|
|
Loading…
Reference in New Issue