/v1/actions/remove-downtime: let users specify themselves

This commit is contained in:
Alexander A. Klimov 2019-11-21 15:28:25 +01:00
parent 7849da0b78
commit a361bf716e
3 changed files with 14 additions and 1 deletions

View File

@ -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);

View File

@ -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;
};
}

View File

@ -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()),