From a361bf716eb68a1cfa14b9e2668e2e1275e52f4b Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 21 Nov 2019 15:28:25 +0100 Subject: [PATCH] /v1/actions/remove-downtime: let users specify themselves --- lib/icinga/apiactions.cpp | 11 +++++++++++ lib/icinga/downtime.ti | 2 ++ lib/icingadb/icingadb-objects.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) 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 0f8c01717..8c6598bb0 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -1375,7 +1375,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()),