diff --git a/doc/12-icinga2-api.md b/doc/12-icinga2-api.md index 616dd945f..f74591b7a 100644 --- a/doc/12-icinga2-api.md +++ b/doc/12-icinga2-api.md @@ -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: diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 757b37eca..71ccea0b1 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -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(object); if (checkable) { std::set 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); diff --git a/lib/icinga/downtime.ti b/lib/icinga/downtime.ti index a55942fb0..ea3c1a5ee 100644 --- a/lib/icinga/downtime.ti +++ b/lib/icinga/downtime.ti @@ -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; }; } diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index 4fa5e3b14..0cbc96d23 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -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()),