From 3f209d7e1f64db3f8f1c36270cca5365653f6d30 Mon Sep 17 00:00:00 2001 From: William Calliari Date: Tue, 21 Jan 2025 15:00:48 +0100 Subject: [PATCH] Remove downtimes when objects are deactivated. --- lib/icinga/downtime.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index 98a65d4174b..f556aaaa7f8 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -1,10 +1,12 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +#include "icinga/checkable.hpp" #include "icinga/downtime.hpp" #include "icinga/downtime-ti.cpp" #include "icinga/host.hpp" #include "icinga/scheduleddowntime.hpp" #include "remote/configobjectutility.hpp" +#include "base/configobject.hpp" #include "base/configtype.hpp" #include "base/utility.hpp" #include "base/timer.hpp" @@ -35,6 +37,22 @@ void Downtime::StaticInitialize() ScriptGlobal::Set("Icinga.DowntimeNoChildren", "DowntimeNoChildren"); ScriptGlobal::Set("Icinga.DowntimeTriggeredChildren", "DowntimeTriggeredChildren"); ScriptGlobal::Set("Icinga.DowntimeNonTriggeredChildren", "DowntimeNonTriggeredChildren"); + + ConfigObject::OnActiveChanged.connect([](const ConfigObject::Ptr& object, const Value&) { + Type::Ptr type = object->GetReflectionType(); + + // Only execute on deactivated checkable objects. + if (object->IsActive() || !(type == Host::TypeInstance || type == Service::TypeInstance)) { + return; + } + + auto checkable = dynamic_pointer_cast(object); + auto downtimes = checkable->GetDowntimes(); + + for (const Downtime::Ptr& downtime : downtimes) { + OnDowntimeRemoved(downtime); + } + }); } String DowntimeNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const