mirror of https://github.com/Icinga/icinga2.git
Remove -and notify- expired downtimes immediately, not every 60s
Don't look for expired downtimes in a timer fired every 60s, but fire one timer per downtime once at expire time.
This commit is contained in:
parent
ba7102cae3
commit
6adf2d19e4
|
@ -10,6 +10,7 @@
|
||||||
#include "base/timer.hpp"
|
#include "base/timer.hpp"
|
||||||
#include <boost/thread/once.hpp>
|
#include <boost/thread/once.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
@ -159,6 +160,21 @@ void Downtime::Stop(bool runtimeRemoved)
|
||||||
ObjectImpl<Downtime>::Stop(runtimeRemoved);
|
ObjectImpl<Downtime>::Stop(runtimeRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Downtime::Pause()
|
||||||
|
{
|
||||||
|
if (m_CleanupTimer) {
|
||||||
|
m_CleanupTimer->Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectImpl<Downtime>::Pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Downtime::Resume()
|
||||||
|
{
|
||||||
|
ObjectImpl<Downtime>::Resume();
|
||||||
|
SetupCleanupTimer();
|
||||||
|
}
|
||||||
|
|
||||||
Checkable::Ptr Downtime::GetCheckable() const
|
Checkable::Ptr Downtime::GetCheckable() const
|
||||||
{
|
{
|
||||||
return static_pointer_cast<Checkable>(m_Checkable);
|
return static_pointer_cast<Checkable>(m_Checkable);
|
||||||
|
@ -427,6 +443,28 @@ bool Downtime::CanBeTriggered()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Downtime::SetupCleanupTimer()
|
||||||
|
{
|
||||||
|
if (!m_CleanupTimer) {
|
||||||
|
m_CleanupTimer = Timer::Create();
|
||||||
|
|
||||||
|
auto name (GetName());
|
||||||
|
|
||||||
|
m_CleanupTimer->OnTimerExpired.connect([name=std::move(name)](const Timer * const&) {
|
||||||
|
auto downtime (Downtime::GetByName(name));
|
||||||
|
|
||||||
|
if (downtime && downtime->IsExpired()) {
|
||||||
|
RemoveDowntime(name, false, false, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
auto triggerTime (GetTriggerTime());
|
||||||
|
|
||||||
|
m_CleanupTimer->Reschedule((GetFixed() || triggerTime <= 0 ? GetEndTime() : triggerTime + GetDuration()) + 0.1);
|
||||||
|
m_CleanupTimer->Start();
|
||||||
|
}
|
||||||
|
|
||||||
void Downtime::TriggerDowntime(double triggerTime)
|
void Downtime::TriggerDowntime(double triggerTime)
|
||||||
{
|
{
|
||||||
if (!CanBeTriggered())
|
if (!CanBeTriggered())
|
||||||
|
@ -441,6 +479,11 @@ void Downtime::TriggerDowntime(double triggerTime)
|
||||||
SetTriggerTime(triggerTime);
|
SetTriggerTime(triggerTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ObjectLock olock (this);
|
||||||
|
SetupCleanupTimer();
|
||||||
|
}
|
||||||
|
|
||||||
Array::Ptr triggers = GetTriggers();
|
Array::Ptr triggers = GetTriggers();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -501,7 +544,7 @@ void Downtime::DowntimesExpireTimerHandler()
|
||||||
{
|
{
|
||||||
for (const Downtime::Ptr& downtime : ConfigType::GetObjectsByType<Downtime>()) {
|
for (const Downtime::Ptr& downtime : ConfigType::GetObjectsByType<Downtime>()) {
|
||||||
/* Only remove downtimes which are activated after daemon start. */
|
/* Only remove downtimes which are activated after daemon start. */
|
||||||
if (downtime->IsActive() && (downtime->IsExpired() || !downtime->HasValidConfigOwner()))
|
if (downtime->IsActive() && !downtime->HasValidConfigOwner())
|
||||||
RemoveDowntime(downtime->GetName(), false, false, true);
|
RemoveDowntime(downtime->GetName(), false, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,9 @@ protected:
|
||||||
void Start(bool runtimeCreated) override;
|
void Start(bool runtimeCreated) override;
|
||||||
void Stop(bool runtimeRemoved) override;
|
void Stop(bool runtimeRemoved) override;
|
||||||
|
|
||||||
|
void Pause() override;
|
||||||
|
void Resume() override;
|
||||||
|
|
||||||
void ValidateStartTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
|
void ValidateStartTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
|
||||||
void ValidateEndTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
|
void ValidateEndTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
|
||||||
|
|
||||||
|
@ -81,8 +84,12 @@ private:
|
||||||
std::set<Downtime::Ptr> m_Children;
|
std::set<Downtime::Ptr> m_Children;
|
||||||
mutable std::mutex m_ChildrenMutex;
|
mutable std::mutex m_ChildrenMutex;
|
||||||
|
|
||||||
|
Timer::Ptr m_CleanupTimer;
|
||||||
|
|
||||||
bool CanBeTriggered();
|
bool CanBeTriggered();
|
||||||
|
|
||||||
|
void SetupCleanupTimer();
|
||||||
|
|
||||||
static void DowntimesStartTimerHandler();
|
static void DowntimesStartTimerHandler();
|
||||||
static void DowntimesExpireTimerHandler();
|
static void DowntimesExpireTimerHandler();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue