[icinga-checkins] icinga.org: icinga2/master: Remove Downtime objects w/ o reference to ScheduledDowntime objects

git at icinga.org git at icinga.org
Sat Aug 13 15:21:18 CEST 2016


Module: icinga2
Branch: master
Commit: 8f03adf76f59e5108c6c9e13fe03646da20ec504
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=8f03adf76f59e5108c6c9e13fe03646da20ec504

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Sat Aug 13 15:18:50 2016 +0200

Remove Downtime objects w/o reference to ScheduledDowntime objects

fixes #11423

---

 lib/icinga/downtime.cpp |   14 +++++++++++++-
 lib/icinga/downtime.hpp |    1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp
index a179526..24b5312 100644
--- a/lib/icinga/downtime.cpp
+++ b/lib/icinga/downtime.cpp
@@ -20,6 +20,7 @@
 #include "icinga/downtime.hpp"
 #include "icinga/downtime.tcpp"
 #include "icinga/host.hpp"
+#include "icinga/scheduleddowntime.hpp"
 #include "remote/configobjectutility.hpp"
 #include "base/configtype.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)
 {
 	boost::mutex::scoped_lock lock(l_DowntimeMutex);
@@ -375,7 +387,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())
+		if (downtime->IsActive() && (downtime->IsExpired() || !downtime->HasValidConfigOwner()))
 			RemoveDowntime(downtime->GetName(), false, true);
 	}
 }
diff --git a/lib/icinga/downtime.hpp b/lib/icinga/downtime.hpp
index f52a99a..8122ebe 100644
--- a/lib/icinga/downtime.hpp
+++ b/lib/icinga/downtime.hpp
@@ -48,6 +48,7 @@ public:
 	bool IsInEffect(void) const;
 	bool IsTriggered(void) const;
 	bool IsExpired(void) const;
+	bool HasValidConfigOwner(void) const;
 
 	static int GetNextDowntimeID(void);
 



More information about the icinga-checkins mailing list