void Downtime::RemoveDowntime(const String& id, bool cancelled, bool expired, const MessageOrigin::Ptr& origin) { Downtime::Ptr downtime = Downtime::GetByName(id); if (!downtime) return; String config_owner = downtime->GetConfigOwner(); if (!config_owner.IsEmpty() && !expired) { Log(LogWarning, "Downtime") << "Cannot remove downtime '" << downtime->GetName() << "'. It is owned by scheduled downtime object '" << config_owner << "'"; return; } downtime->SetWasCancelled(cancelled); Log(LogNotice, "Downtime") << "Removed downtime '" << downtime->GetName() << "' from object '" << downtime->GetCheckable()->GetName() << "'."; if (downtime->GetPackage() != "_api") return; Array::Ptr errors = new Array(); if (!ConfigObjectUtility::DeleteObject(downtime, false, errors)) { ObjectLock olock(errors); for (const String& error : errors) { Log(LogCritical, "Downtime", error); } BOOST_THROW_EXCEPTION(std::runtime_error("Could not remove downtime.")); } }
void Checkable::RemoveDowntime(const String& id, bool cancelled, const MessageOrigin::Ptr& origin) { Checkable::Ptr owner = GetOwnerByDowntimeID(id); if (!owner) return; Dictionary::Ptr downtimes = owner->GetDowntimes(); Downtime::Ptr downtime = downtimes->Get(id); if (!downtime) return; int legacy_id = downtime->GetLegacyId(); String config_owner = downtime->GetConfigOwner(); if (!config_owner.IsEmpty()) { Log(LogWarning, "Checkable") << "Cannot remove downtime with ID '" << legacy_id << "'. It is owned by scheduled downtime object '" << config_owner << "'"; return; } downtimes->Remove(id); { boost::mutex::scoped_lock lock(l_DowntimeMutex); l_LegacyDowntimesCache.erase(legacy_id); l_DowntimesCache.erase(id); } downtime->SetWasCancelled(cancelled); Log(LogNotice, "Checkable") << "Removed downtime with ID '" << downtime->GetLegacyId() << "' from service '" << owner->GetName() << "'."; OnDowntimeRemoved(owner, downtime, origin); }