Fix duplicate notifications on HA failover

fixes #12267
This commit is contained in:
Gunnar Beutner 2016-08-04 10:12:55 +02:00
parent bd3660fe5a
commit 905380b436
6 changed files with 37 additions and 3 deletions

View File

@ -240,6 +240,11 @@ Value ClusterEvents::NextCheckChangedAPIHandler(const MessageOrigin::Ptr& origin
return Empty; return Empty;
} }
double nextCheck = params->Get("next_check");
if (nextCheck < Application::GetStartTime() + 60)
return Empty;
checkable->SetNextCheck(params->Get("next_check"), false, origin); checkable->SetNextCheck(params->Get("next_check"), false, origin);
return Empty; return Empty;
@ -288,7 +293,12 @@ Value ClusterEvents::NextNotificationChangedAPIHandler(const MessageOrigin::Ptr&
return Empty; 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; return Empty;
} }

View File

@ -21,6 +21,7 @@
#include "icinga/notification.tcpp" #include "icinga/notification.tcpp"
#include "icinga/notificationcommand.hpp" #include "icinga/notificationcommand.hpp"
#include "icinga/service.hpp" #include "icinga/service.hpp"
#include "remote/apilistener.hpp"
#include "base/objectlock.hpp" #include "base/objectlock.hpp"
#include "base/logger.hpp" #include "base/logger.hpp"
#include "base/utility.hpp" #include "base/utility.hpp"
@ -144,12 +145,15 @@ void Notification::OnAllConfigLoaded(void)
void Notification::Start(bool runtimeCreated) void Notification::Start(bool runtimeCreated)
{ {
ObjectImpl<Notification>::Start(runtimeCreated);
Checkable::Ptr obj = GetCheckable(); Checkable::Ptr obj = GetCheckable();
if (obj) if (obj)
obj->RegisterNotification(this); obj->RegisterNotification(this);
if (ApiListener::IsHACluster() && GetNextNotification() < Utility::GetTime() + 60)
SetNextNotification(Utility::GetTime() + 60, true);
ObjectImpl<Notification>::Start(runtimeCreated);
} }
void Notification::Stop(bool runtimeRemoved) void Notification::Stop(bool runtimeRemoved)

View 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 "'")); "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();
}

View File

@ -100,6 +100,8 @@ public:
static void UpdateObjectAuthority(void); static void UpdateObjectAuthority(void);
static bool IsHACluster(void);
protected: protected:
virtual void OnConfigLoaded(void) override; virtual void OnConfigLoaded(void) override;
virtual void OnAllConfigLoaded(void) override; virtual void OnAllConfigLoaded(void) override;

View File

@ -112,6 +112,12 @@ bool Zone::IsGlobal(void) const
return GetGlobal(); return GetGlobal();
} }
bool Zone::IsSingleInstance(void) const
{
Array::Ptr endpoints = GetEndpointsRaw();
return !endpoints || endpoints->GetLength() < 2;
}
Zone::Ptr Zone::GetLocalZone(void) Zone::Ptr Zone::GetLocalZone(void)
{ {
Endpoint::Ptr local = Endpoint::GetLocalEndpoint(); Endpoint::Ptr local = Endpoint::GetLocalEndpoint();

View File

@ -45,6 +45,7 @@ public:
bool CanAccessObject(const ConfigObject::Ptr& object); bool CanAccessObject(const ConfigObject::Ptr& object);
bool IsChildOf(const Zone::Ptr& zone); bool IsChildOf(const Zone::Ptr& zone);
bool IsGlobal(void) const; bool IsGlobal(void) const;
bool IsSingleInstance(void) const;
static Zone::Ptr GetLocalZone(void); static Zone::Ptr GetLocalZone(void);