diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 0f4d1399b..9d6493351 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -20,6 +20,7 @@ boost::signals2::signal Checkable::OnFlappingChange; static Timer::Ptr l_CheckablesFireSuppressedNotifications; +static Timer::Ptr l_CleanDeadlinedExecutions; void Checkable::StaticInitialize() { @@ -78,6 +79,11 @@ void Checkable::Start(bool runtimeCreated) l_CheckablesFireSuppressedNotifications->SetInterval(5); l_CheckablesFireSuppressedNotifications->OnTimerExpired.connect(&Checkable::FireSuppressedNotifications); l_CheckablesFireSuppressedNotifications->Start(); + + l_CleanDeadlinedExecutions = new Timer(); + l_CleanDeadlinedExecutions->SetInterval(300); + l_CleanDeadlinedExecutions->OnTimerExpired.connect(&Checkable::CleanDeadlinedExecutions); + l_CleanDeadlinedExecutions->Start(); }); } @@ -257,3 +263,34 @@ void Checkable::ValidateMaxCheckAttempts(const Lazy& lvalue, const Validati if (lvalue() <= 0) BOOST_THROW_EXCEPTION(ValidationError(this, { "max_check_attempts" }, "Value must be greater than 0.")); } + +void Checkable::CleanDeadlinedExecutions(const Timer * const&) +{ + double now = Utility::GetTime(); + Dictionary::Ptr executions; + Dictionary::Ptr execution; + + for (auto& host : ConfigType::GetObjectsByType()) { + executions = host->GetExecutions(); + if (executions) { + for (const String& key : executions->GetKeys()) { + execution = executions->Get(key); + if (execution->Contains("deadline") && now > execution->Get("deadline")) { + executions->Remove(key); + } + } + } + } + + for (auto& service : ConfigType::GetObjectsByType()) { + executions = service->GetExecutions(); + if (executions) { + for (const String& key : executions->GetKeys()) { + execution = executions->Get(key); + if (execution->Contains("deadline") && now > execution->Get("deadline")) { + executions->Remove(key); + } + } + } + } +} \ No newline at end of file diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index 0eb1c5950..853c76a8a 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -202,6 +202,7 @@ private: static void NotifyDowntimeEnd(const Downtime::Ptr& downtime); static void FireSuppressedNotifications(const Timer * const&); + static void CleanDeadlinedExecutions(const Timer * const&); /* Comments */ std::set m_Comments;