]> granicus.if.org Git - icinga2/commitdiff
Fix duplicate notifications on HA failover
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 4 Aug 2016 08:12:55 +0000 (10:12 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 4 Aug 2016 08:12:55 +0000 (10:12 +0200)
fixes #12267

lib/icinga/clusterevents.cpp
lib/icinga/notification.cpp
lib/remote/apilistener.cpp
lib/remote/apilistener.hpp
lib/remote/zone.cpp
lib/remote/zone.hpp

index 7d5a86713528a79bd4c33904334380519e753e75..95cb5db7dae88b67934724cc07c9b68acf6bc7f6 100644 (file)
@@ -240,6 +240,11 @@ Value ClusterEvents::NextCheckChangedAPIHandler(const MessageOrigin::Ptr& origin
                return Empty;
        }
 
+       double nextCheck = params->Get("next_check");
+
+       if (nextCheck < Application::GetStartTime() + 60)
+               return Empty;
+
        checkable->SetNextCheck(params->Get("next_check"), false, origin);
 
        return Empty;
@@ -288,7 +293,12 @@ Value ClusterEvents::NextNotificationChangedAPIHandler(const MessageOrigin::Ptr&
                return Empty;
        }
 
-       notification->SetNextNotification(params->Get("next_notification"), false, origin);
+       double nextNotification = params->Get("next_notification");
+
+       if (nextNotification < Utility::GetTime())
+               return Empty;
+
+       notification->SetNextNotification(nextNotification, false, origin);
 
        return Empty;
 }
index 41a6cf45f19833779584350b075e3a753b556512..885c6fd452d6e69b6ee435bc2fc312888684ebbc 100644 (file)
@@ -21,6 +21,7 @@
 #include "icinga/notification.tcpp"
 #include "icinga/notificationcommand.hpp"
 #include "icinga/service.hpp"
+#include "remote/apilistener.hpp"
 #include "base/objectlock.hpp"
 #include "base/logger.hpp"
 #include "base/utility.hpp"
@@ -144,12 +145,15 @@ void Notification::OnAllConfigLoaded(void)
 
 void Notification::Start(bool runtimeCreated)
 {
-       ObjectImpl<Notification>::Start(runtimeCreated);
-
        Checkable::Ptr obj = GetCheckable();
 
        if (obj)
                obj->RegisterNotification(this);
+
+       if (ApiListener::IsHACluster() && GetNextNotification() < Utility::GetTime() + 60)
+               SetNextNotification(Utility::GetTime() + 60, true);
+
+       ObjectImpl<Notification>::Start(runtimeCreated);
 }
 
 void Notification::Stop(bool runtimeRemoved)
index 3d967eff0676864c0bb881de08b9bcba160af6e7..007cfb9a85c963ba1b3959edfd573e458fce9fa3 100644 (file)
@@ -1190,3 +1190,14 @@ void ApiListener::ValidateTlsProtocolmin(const String& value, const ValidationUt
                    "Must be one of '" SSL_TXT_TLSV1 "', '" SSL_TXT_TLSV1_1 "' or '" SSL_TXT_TLSV1_2 "'"));
        }
 }
+
+bool ApiListener::IsHACluster(void)
+{
+       Zone::Ptr zone = Zone::GetLocalZone();
+
+       if (!zone)
+               return false;
+
+       return zone->IsSingleInstance();
+}
+
index 4c1771361f5983f6f998c8c26b6b9d8b6b15fbc7..49a57e181fa1c42e85a8c2844bdc02c7b9464a70 100644 (file)
@@ -100,6 +100,8 @@ public:
 
        static void UpdateObjectAuthority(void);
 
+       static bool IsHACluster(void);
+
 protected:
        virtual void OnConfigLoaded(void) override;
        virtual void OnAllConfigLoaded(void) override;
index ded60f62122b4b2921b554e4a363be55cfb2b25c..31286b859a9ba9abb5955946170df4a509699ea2 100644 (file)
@@ -112,6 +112,12 @@ bool Zone::IsGlobal(void) const
        return GetGlobal();
 }
 
+bool Zone::IsSingleInstance(void) const
+{
+       Array::Ptr endpoints = GetEndpointsRaw();
+       return !endpoints || endpoints->GetLength() < 2;
+}
+
 Zone::Ptr Zone::GetLocalZone(void)
 {
        Endpoint::Ptr local = Endpoint::GetLocalEndpoint();
index c633d496792c6436c188992d33b84f5f009ade63..76ed4c0cca43cebedf7e2c335734675a43b10199 100644 (file)
@@ -45,6 +45,7 @@ public:
        bool CanAccessObject(const ConfigObject::Ptr& object);
        bool IsChildOf(const Zone::Ptr& zone);
        bool IsGlobal(void) const;
+       bool IsSingleInstance(void) const;
 
        static Zone::Ptr GetLocalZone(void);