From 23ab6cf78b9cd7322e02538ac78ae5ab6939ecc0 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 2 May 2016 15:32:46 +0200 Subject: [PATCH] Fix: Expired downtimes are not removed fixes #11711 --- lib/compat/statusdatawriter.cpp | 2 +- lib/db_ido/dbevents.cpp | 4 ++-- lib/icinga/checkable-downtime.cpp | 4 ++-- lib/icinga/comment.cpp | 1 + lib/icinga/downtime.cpp | 5 +++-- lib/icinga/downtime.hpp | 2 +- lib/livestatus/downtimestable.cpp | 2 +- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 134174f70..d6073f57c 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -181,7 +181,7 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Checkable::Ptr& che "\t" "triggered_by=" << triggeredByLegacy << "\n" "\t" "fixed=" << static_cast(downtime->GetFixed()) << "\n" "\t" "duration=" << static_cast(downtime->GetDuration()) << "\n" - "\t" "is_in_effect=" << (downtime->IsActive() ? 1 : 0) << "\n" + "\t" "is_in_effect=" << (downtime->IsInEffect() ? 1 : 0) << "\n" "\t" "author=" << downtime->GetAuthor() << "\n" "\t" "comment=" << downtime->GetComment() << "\n" "\t" "trigger_time=" << downtime->GetTriggerTime() << "\n" diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 1afbe9c3b..fc870f78a 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -506,7 +506,7 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); fields1->Set("was_started", ((downtime->GetStartTime() <= Utility::GetTime()) ? 1 : 0)); - fields1->Set("is_in_effect", (downtime->IsActive() ? 1 : 0)); + fields1->Set("is_in_effect", (downtime->IsInEffect() ? 1 : 0)); fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -658,7 +658,7 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) fields1->Set("was_started", 1); fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first)); fields1->Set("actual_start_time_usec", time_bag.second); - fields1->Set("is_in_effect", (downtime->IsActive() ? 1 : 0)); + fields1->Set("is_in_effect", (downtime->IsInEffect() ? 1 : 0)); fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ diff --git a/lib/icinga/checkable-downtime.cpp b/lib/icinga/checkable-downtime.cpp index 82c0110be..f1eec03ef 100644 --- a/lib/icinga/checkable-downtime.cpp +++ b/lib/icinga/checkable-downtime.cpp @@ -44,7 +44,7 @@ void Checkable::TriggerDowntimes(void) bool Checkable::IsInDowntime(void) const { BOOST_FOREACH(const Downtime::Ptr& downtime, GetDowntimes()) { - if (downtime->IsActive()) + if (downtime->IsInEffect()) return true; } @@ -56,7 +56,7 @@ int Checkable::GetDowntimeDepth(void) const int downtime_depth = 0; BOOST_FOREACH(const Downtime::Ptr& downtime, GetDowntimes()) { - if (downtime->IsActive()) + if (downtime->IsInEffect()) downtime_depth++; } diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 85c5f1a17..eeb7b2b60 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -244,6 +244,7 @@ void Comment::CommentsExpireTimerHandler(void) } BOOST_FOREACH(const Comment::Ptr& comment, comments) { + /* Only remove comment which are activated after daemon start. */ if (comment->IsActive() && comment->IsExpired()) RemoveComment(comment->GetName()); } diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index 2d1838302..62bdb7c71 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -150,7 +150,7 @@ Checkable::Ptr Downtime::GetCheckable(void) const return static_pointer_cast(m_Checkable); } -bool Downtime::IsActive(void) const +bool Downtime::IsInEffect(void) const { double now = Utility::GetTime(); @@ -294,7 +294,7 @@ void Downtime::RemoveDowntime(const String& id, bool cancelled, bool expired, co void Downtime::TriggerDowntime(void) { - if (IsActive() && IsTriggered()) { + if (IsInEffect() && IsTriggered()) { Log(LogDebug, "Downtime") << "Not triggering downtime '" << GetName() << "': already triggered."; return; @@ -358,6 +358,7 @@ void Downtime::DowntimesExpireTimerHandler(void) } BOOST_FOREACH(const Downtime::Ptr& downtime, downtimes) { + /* Only remove downtimes which are activated after daemon start. */ if (downtime->IsActive() && downtime->IsExpired()) RemoveDowntime(downtime->GetName(), false, true); } diff --git a/lib/icinga/downtime.hpp b/lib/icinga/downtime.hpp index c2185cc75..e2ef520f6 100644 --- a/lib/icinga/downtime.hpp +++ b/lib/icinga/downtime.hpp @@ -45,7 +45,7 @@ public: intrusive_ptr GetCheckable(void) const; - bool IsActive(void) const; + bool IsInEffect(void) const; bool IsTriggered(void) const; bool IsExpired(void) const; diff --git a/lib/livestatus/downtimestable.cpp b/lib/livestatus/downtimestable.cpp index a5798bfb9..db02a9e4e 100644 --- a/lib/livestatus/downtimestable.cpp +++ b/lib/livestatus/downtimestable.cpp @@ -129,7 +129,7 @@ Value DowntimesTable::TypeAccessor(const Value& row) { Downtime::Ptr downtime = static_cast(row); // 1 .. active, 0 .. pending - return (downtime->IsActive() ? 1 : 0); + return (downtime->IsInEffect() ? 1 : 0); } Value DowntimesTable::IsServiceAccessor(const Value& row)