Fix: Expired downtimes are not removed

fixes #11711
This commit is contained in:
Michael Friedrich 2016-05-02 15:32:46 +02:00 committed by Gunnar Beutner
parent 0e70165bc9
commit e0d1c2f020
7 changed files with 11 additions and 9 deletions

View File

@ -181,7 +181,7 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Checkable::Ptr& che
"\t" "triggered_by=" << triggeredByLegacy << "\n" "\t" "triggered_by=" << triggeredByLegacy << "\n"
"\t" "fixed=" << static_cast<long>(downtime->GetFixed()) << "\n" "\t" "fixed=" << static_cast<long>(downtime->GetFixed()) << "\n"
"\t" "duration=" << static_cast<long>(downtime->GetDuration()) << "\n" "\t" "duration=" << static_cast<long>(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" "author=" << downtime->GetAuthor() << "\n"
"\t" "comment=" << downtime->GetComment() << "\n" "\t" "comment=" << downtime->GetComment() << "\n"
"\t" "trigger_time=" << downtime->GetTriggerTime() << "\n" "\t" "trigger_time=" << downtime->GetTriggerTime() << "\n"

View File

@ -506,7 +506,7 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime
fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
fields1->Set("was_started", ((downtime->GetStartTime() <= Utility::GetTime()) ? 1 : 0)); 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("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ 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("was_started", 1);
fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first)); fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first));
fields1->Set("actual_start_time_usec", time_bag.second); 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("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */

View File

@ -44,7 +44,7 @@ void Checkable::TriggerDowntimes(void)
bool Checkable::IsInDowntime(void) const bool Checkable::IsInDowntime(void) const
{ {
BOOST_FOREACH(const Downtime::Ptr& downtime, GetDowntimes()) { BOOST_FOREACH(const Downtime::Ptr& downtime, GetDowntimes()) {
if (downtime->IsActive()) if (downtime->IsInEffect())
return true; return true;
} }
@ -56,7 +56,7 @@ int Checkable::GetDowntimeDepth(void) const
int downtime_depth = 0; int downtime_depth = 0;
BOOST_FOREACH(const Downtime::Ptr& downtime, GetDowntimes()) { BOOST_FOREACH(const Downtime::Ptr& downtime, GetDowntimes()) {
if (downtime->IsActive()) if (downtime->IsInEffect())
downtime_depth++; downtime_depth++;
} }

View File

@ -244,6 +244,7 @@ void Comment::CommentsExpireTimerHandler(void)
} }
BOOST_FOREACH(const Comment::Ptr& comment, comments) { BOOST_FOREACH(const Comment::Ptr& comment, comments) {
/* Only remove comment which are activated after daemon start. */
if (comment->IsActive() && comment->IsExpired()) if (comment->IsActive() && comment->IsExpired())
RemoveComment(comment->GetName()); RemoveComment(comment->GetName());
} }

View File

@ -150,7 +150,7 @@ Checkable::Ptr Downtime::GetCheckable(void) const
return static_pointer_cast<Checkable>(m_Checkable); return static_pointer_cast<Checkable>(m_Checkable);
} }
bool Downtime::IsActive(void) const bool Downtime::IsInEffect(void) const
{ {
double now = Utility::GetTime(); double now = Utility::GetTime();
@ -294,7 +294,7 @@ void Downtime::RemoveDowntime(const String& id, bool cancelled, bool expired, co
void Downtime::TriggerDowntime(void) void Downtime::TriggerDowntime(void)
{ {
if (IsActive() && IsTriggered()) { if (IsInEffect() && IsTriggered()) {
Log(LogDebug, "Downtime") Log(LogDebug, "Downtime")
<< "Not triggering downtime '" << GetName() << "': already triggered."; << "Not triggering downtime '" << GetName() << "': already triggered.";
return; return;
@ -358,6 +358,7 @@ void Downtime::DowntimesExpireTimerHandler(void)
} }
BOOST_FOREACH(const Downtime::Ptr& downtime, downtimes) { BOOST_FOREACH(const Downtime::Ptr& downtime, downtimes) {
/* Only remove downtimes which are activated after daemon start. */
if (downtime->IsActive() && downtime->IsExpired()) if (downtime->IsActive() && downtime->IsExpired())
RemoveDowntime(downtime->GetName(), false, true); RemoveDowntime(downtime->GetName(), false, true);
} }

View File

@ -45,7 +45,7 @@ public:
intrusive_ptr<Checkable> GetCheckable(void) const; intrusive_ptr<Checkable> GetCheckable(void) const;
bool IsActive(void) const; bool IsInEffect(void) const;
bool IsTriggered(void) const; bool IsTriggered(void) const;
bool IsExpired(void) const; bool IsExpired(void) const;

View File

@ -129,7 +129,7 @@ Value DowntimesTable::TypeAccessor(const Value& row)
{ {
Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
// 1 .. active, 0 .. pending // 1 .. active, 0 .. pending
return (downtime->IsActive() ? 1 : 0); return (downtime->IsInEffect() ? 1 : 0);
} }
Value DowntimesTable::IsServiceAccessor(const Value& row) Value DowntimesTable::IsServiceAccessor(const Value& row)