Remove Downtime objects w/o reference to ScheduledDowntime objects

fixes #11423
This commit is contained in:
Michael Friedrich 2016-08-13 15:18:50 +02:00
parent afc1b9bdc5
commit 8f03adf76f
2 changed files with 14 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include "icinga/downtime.hpp" #include "icinga/downtime.hpp"
#include "icinga/downtime.tcpp" #include "icinga/downtime.tcpp"
#include "icinga/host.hpp" #include "icinga/host.hpp"
#include "icinga/scheduleddowntime.hpp"
#include "remote/configobjectutility.hpp" #include "remote/configobjectutility.hpp"
#include "base/configtype.hpp" #include "base/configtype.hpp"
#include "base/utility.hpp" #include "base/utility.hpp"
@ -196,6 +197,17 @@ bool Downtime::IsExpired(void) const
} }
} }
bool Downtime::HasValidConfigOwner(void) const
{
String configOwner = GetConfigOwner();
if (!configOwner.IsEmpty()) {
return (GetObject("ScheduledDowntime", configOwner) != ScheduledDowntime::Ptr());
}
return true;
}
int Downtime::GetNextDowntimeID(void) int Downtime::GetNextDowntimeID(void)
{ {
boost::mutex::scoped_lock lock(l_DowntimeMutex); boost::mutex::scoped_lock lock(l_DowntimeMutex);
@ -375,7 +387,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. */ /* Only remove downtimes which are activated after daemon start. */
if (downtime->IsActive() && downtime->IsExpired()) if (downtime->IsActive() && (downtime->IsExpired() || !downtime->HasValidConfigOwner()))
RemoveDowntime(downtime->GetName(), false, true); RemoveDowntime(downtime->GetName(), false, true);
} }
} }

View File

@ -48,6 +48,7 @@ public:
bool IsInEffect(void) const; bool IsInEffect(void) const;
bool IsTriggered(void) const; bool IsTriggered(void) const;
bool IsExpired(void) const; bool IsExpired(void) const;
bool HasValidConfigOwner(void) const;
static int GetNextDowntimeID(void); static int GetNextDowntimeID(void);