Skip to content

Commit

Permalink
Merge branch 'feature/v1-actions-execute-command-8034-deadline-timer'…
Browse files Browse the repository at this point in the history
… into feature/v1-actions-execute-command-8034

refs #8034
  • Loading branch information
Al2Klimov committed Sep 15, 2020
2 parents eb5414a + 6801419 commit fe4a440
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/icinga/checkable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ boost::signals2::signal<void (const Checkable::Ptr&, const String&, double, cons
boost::signals2::signal<void (const Checkable::Ptr&, double)> Checkable::OnFlappingChange;

static Timer::Ptr l_CheckablesFireSuppressedNotifications;
static Timer::Ptr l_CleanDeadlinedExecutions;

thread_local std::function<void(const Value& commandLine, const ProcessResult&)> Checkable::ExecuteCommandProcessFinishedHandler;

void Checkable::StaticInitialize()
Expand Down Expand Up @@ -79,6 +81,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();
});
}

Expand Down Expand Up @@ -258,3 +265,34 @@ void Checkable::ValidateMaxCheckAttempts(const Lazy<int>& 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<Host>()) {
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<Service>()) {
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);
}
}
}
}
}
1 change: 1 addition & 0 deletions lib/icinga/checkable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Checkable : public ObjectImpl<Checkable>
static void NotifyDowntimeEnd(const Downtime::Ptr& downtime);

static void FireSuppressedNotifications(const Timer * const&);
static void CleanDeadlinedExecutions(const Timer * const&);

/* Comments */
std::set<Comment::Ptr> m_Comments;
Expand Down

0 comments on commit fe4a440

Please sign in to comment.