]> granicus.if.org Git - icinga2/commitdiff
Fix downtime notification events and missing author/comment
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 10 Aug 2016 10:28:41 +0000 (12:28 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 10 Aug 2016 14:04:37 +0000 (16:04 +0200)
fixes #12333
fixes #11851

lib/icinga/checkable-check.cpp
lib/icinga/checkable.cpp
lib/icinga/checkable.hpp

index 8d4b0eb18aaacf4e6281d03a27b55deeb5a171be..9080d67397f00f8357fa924f80466fe41b1d3ba2 100644 (file)
@@ -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())
index ec42dd298807f7c667353678c5b5835ffc691037..f13ea34e4f5b415da14b45c16019d1ca30a2e89f 100644 (file)
 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);
index 7d7593385572831aab0df73d6651f9b7a6ca2194..d40e1b76e114c64e50dbbfd221d6d0055612a2c5 100644 (file)
@@ -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;