From b8d495ae07694523d68c5c83cbfa286d1df98fa3 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 24 Sep 2019 17:54:20 +0200 Subject: [PATCH] Introduce Checkable#next_update --- lib/icinga/checkable.cpp | 13 +++++++++++++ lib/icinga/checkable.hpp | 1 + lib/icinga/checkable.ti | 3 +++ 3 files changed, 17 insertions(+) diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 04e462951..0ab090284 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -168,6 +168,19 @@ bool Checkable::GetHandled() const return GetProblem() && (IsInDowntime() || IsAcknowledged()); } +Timestamp Checkable::GetNextUpdate() const +{ + auto cr (GetLastCheckResult()); + + if (cr) { + return GetNextCheck() + + (GetProblem() && GetStateType() == StateTypeSoft ? GetRetryInterval() : GetCheckInterval()) + + 2 * (cr->GetExecutionEnd() - cr->GetScheduleStart()); + } else { + return GetNextCheck() + GetCheckInterval(); + } +} + void Checkable::NotifyFixedDowntimeStart(const Downtime::Ptr& downtime) { if (!downtime->GetFixed()) diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index caddd63f4..032910adb 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -91,6 +91,7 @@ public: int GetSeverity() const override; bool GetProblem() const override; bool GetHandled() const override; + Timestamp GetNextUpdate() const override; /* Checks */ intrusive_ptr GetCheckCommand() const; diff --git a/lib/icinga/checkable.ti b/lib/icinga/checkable.ti index 7969d6f46..a920d2589 100644 --- a/lib/icinga/checkable.ti +++ b/lib/icinga/checkable.ti @@ -132,6 +132,9 @@ abstract class Checkable : CustomVarObject [no_storage] bool handled { get; }; + [no_storage] Timestamp next_update { + get; + }; [state] bool force_next_check; [state] int acknowledgement (AcknowledgementRaw) {