[icinga-checkins] icinga.org: icinga2/master: Fix downtime notification events and missing author/comment

git at icinga.org git at icinga.org
Wed Aug 10 16:04:55 CEST 2016


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Wed Aug 10 12:28:41 2016 +0200

Fix downtime notification events and missing author/comment

fixes #12333
fixes #11851

---

 lib/icinga/checkable-check.cpp |    4 ----
 lib/icinga/checkable.cpp       |   43 ++++++++++++++++++++++++++++++++++++++++
 lib/icinga/checkable.hpp       |    8 ++++++++
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp
index 8d4b0eb..9080d67 100644
--- a/lib/icinga/checkable-check.cpp
+++ b/lib/icinga/checkable-check.cpp
@@ -291,7 +291,6 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
 	if (is_volatile && IsStateOK(old_state) && IsStateOK(new_state))
 		send_notification = false; /* Don't send notifications for volatile OK -> OK changes. */
 
-	bool send_downtime_notification = (GetLastInDowntime() != in_downtime);
 	SetLastInDowntime(in_downtime);
 
 	olock.Unlock();
@@ -365,9 +364,6 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
 	    (is_volatile && !(IsStateOK(old_state) && IsStateOK(new_state))))
 		ExecuteEventHandler();
 
-	if (send_downtime_notification && IsActive())
-		OnNotificationsRequested(this, in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr, "", "", MessageOrigin::Ptr());
-
 	/* Flapping start/end notifications */
 	if (!was_flapping && is_flapping) {
 		if (!IsPaused())
diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp
index ec42dd2..f13ea34 100644
--- a/lib/icinga/checkable.cpp
+++ b/lib/icinga/checkable.cpp
@@ -30,10 +30,21 @@
 using namespace icinga;
 
 REGISTER_TYPE_WITH_PROTOTYPE(Checkable, Checkable::GetPrototype());
+INITIALIZE_ONCE(&Checkable::StaticInitialize);
 
 boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, bool, double, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementSet;
 boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementCleared;
 
+void Checkable::StaticInitialize(void)
+{
+	/* fixed downtime start */
+	Downtime::OnDowntimeAdded.connect(boost::bind(&Checkable::NotifyFixedDowntimeStart, _1));
+	/* flexible downtime start */
+	Downtime::OnDowntimeTriggered.connect(boost::bind(&Checkable::NotifyFlexibleDowntimeStart, _1));
+	/* fixed/flexible downtime end */
+	Downtime::OnDowntimeRemoved.connect(boost::bind(&Checkable::NotifyDowntimeEnd, _1));
+}
+
 Checkable::Checkable(void)
 	: m_CheckRunning(false)
 {
@@ -116,6 +127,38 @@ Endpoint::Ptr Checkable::GetCommandEndpoint(void) const
 	return Endpoint::GetByName(GetCommandEndpointRaw());
 }
 
+void Checkable::NotifyFixedDowntimeStart(const Downtime::Ptr& downtime)
+{
+	if (!downtime->GetFixed())
+		return;
+
+	NotifyDowntimeInternal(downtime);
+}
+
+void Checkable::NotifyFlexibleDowntimeStart(const Downtime::Ptr& downtime)
+{
+	if (downtime->GetFixed())
+		return;
+
+	NotifyDowntimeInternal(downtime);
+}
+
+void Checkable::NotifyDowntimeInternal(const Downtime::Ptr& downtime)
+{
+	Checkable::Ptr checkable = downtime->GetCheckable();
+
+	if (!checkable->IsPaused())
+		OnNotificationsRequested(checkable, NotificationDowntimeStart, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr());
+}
+
+void Checkable::NotifyDowntimeEnd(const Downtime::Ptr& downtime)
+{
+	Checkable::Ptr checkable = downtime->GetCheckable();
+
+	if (!checkable->IsPaused())
+		OnNotificationsRequested(checkable, NotificationDowntimeEnd, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr());
+}
+
 void Checkable::ValidateCheckInterval(double value, const ValidationUtils& utils)
 {
 	ObjectImpl<Checkable>::ValidateCheckInterval(value, utils);
diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp
index 7d75933..d40e1b7 100644
--- a/lib/icinga/checkable.hpp
+++ b/lib/icinga/checkable.hpp
@@ -68,6 +68,8 @@ public:
 	DECLARE_OBJECT(Checkable);
 	DECLARE_OBJECTNAME(Checkable);
 
+	static void StaticInitialize(void);
+
 	Checkable(void);
 
 	std::set<Checkable::Ptr> GetParents(void) const;
@@ -196,6 +198,12 @@ private:
 	std::set<Downtime::Ptr> m_Downtimes;
 	mutable boost::mutex m_DowntimeMutex;
 
+	static void NotifyFixedDowntimeStart(const Downtime::Ptr& downtime);
+	static void NotifyFlexibleDowntimeStart(const Downtime::Ptr& downtime);
+	static void NotifyDowntimeInternal(const Downtime::Ptr& downtime);
+
+	static void NotifyDowntimeEnd(const Downtime::Ptr& downtime);
+
 	/* Comments */
 	std::set<Comment::Ptr> m_Comments;
 	mutable boost::mutex m_CommentMutex;



More information about the icinga-checkins mailing list