]> granicus.if.org Git - icinga2/commitdiff
Implement HA functionality for Gelf feature
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 24 Oct 2018 11:43:38 +0000 (13:43 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Wed, 24 Oct 2018 11:50:10 +0000 (13:50 +0200)
lib/perfdata/gelfwriter.cpp
lib/perfdata/gelfwriter.hpp
lib/perfdata/gelfwriter.ti

index 78e15ff77c1b1779c681d847d4725e5039f58dcd..c4c0912d249491f5bbe1b9b4f6b2b9da80110ca5 100644 (file)
@@ -51,6 +51,15 @@ void GelfWriter::OnConfigLoaded()
        ObjectImpl<GelfWriter>::OnConfigLoaded();
 
        m_WorkQueue.SetName("GelfWriter, " + GetName());
+
+       if (!GetEnableHa()) {
+               Log(LogDebug, "GelfWriter")
+                       << "HA functionality disabled. Won't pause connection: " << GetName();
+
+               SetHAMode(HARunEverywhere);
+       } else {
+               SetHAMode(HARunOnce);
+       }
 }
 
 void GelfWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
@@ -75,12 +84,12 @@ void GelfWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perf
        status->Set("gelfwriter", new Dictionary(std::move(nodes)));
 }
 
-void GelfWriter::Start(bool runtimeCreated)
+void GelfWriter::Resume()
 {
-       ObjectImpl<GelfWriter>::Start(runtimeCreated);
+       ObjectImpl<GelfWriter>::Resume();
 
        Log(LogInformation, "GelfWriter")
-               << "'" << GetName() << "' started.";
+               << "'" << GetName() << "' resumed.";
 
        /* Register exception handler for WQ tasks. */
        m_WorkQueue.SetExceptionCallback(std::bind(&GelfWriter::ExceptionHandler, this, _1));
@@ -98,14 +107,14 @@ void GelfWriter::Start(bool runtimeCreated)
        Checkable::OnStateChange.connect(std::bind(&GelfWriter::StateChangeHandler, this, _1, _2, _3));
 }
 
-void GelfWriter::Stop(bool runtimeRemoved)
+void GelfWriter::Pause()
 {
        Log(LogInformation, "GelfWriter")
-               << "'" << GetName() << "' stopped.";
+               << "'" << GetName() << "' paused.";
 
        m_WorkQueue.Join();
 
-       ObjectImpl<GelfWriter>::Stop(runtimeRemoved);
+       ObjectImpl<GelfWriter>::Pause();
 }
 
 void GelfWriter::AssertOnWorkQueue()
@@ -131,6 +140,11 @@ void GelfWriter::Reconnect()
 {
        AssertOnWorkQueue();
 
+       if (IsPaused()) {
+               SetConnected(false);
+               return;
+       }
+
        double startTime = Utility::GetTime();
 
        CONTEXT("Reconnecting to Graylog Gelf '" + GetName() + "'");
@@ -180,6 +194,9 @@ void GelfWriter::Disconnect()
 
 void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
 {
+       if (IsPaused())
+               return;
+
        m_WorkQueue.Enqueue(std::bind(&GelfWriter::CheckResultHandlerInternal, this, checkable, cr));
 }
 
@@ -284,6 +301,9 @@ void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification
        const User::Ptr& user, NotificationType notificationType, CheckResult::Ptr const& cr,
        const String& author, const String& commentText, const String& commandName)
 {
+       if (IsPaused())
+               return;
+
        m_WorkQueue.Enqueue(std::bind(&GelfWriter::NotificationToUserHandlerInternal, this,
                notification, checkable, user, notificationType, cr, author, commentText, commandName));
 }
@@ -348,6 +368,9 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti
 
 void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)
 {
+       if (IsPaused())
+               return;
+
        m_WorkQueue.Enqueue(std::bind(&GelfWriter::StateChangeHandlerInternal, this, checkable, cr, type));
 }
 
index 4e27a3c92a8286504c312939af9e71f5020d860e..32e35da57d40097629f0dd32df106fbac6d0e3e9 100644 (file)
@@ -46,8 +46,8 @@ public:
 
 protected:
        void OnConfigLoaded() override;
-       void Start(bool runtimeCreated) override;
-       void Stop(bool runtimeRemoved) override;
+       void Resume() override;
+       void Pause() override;
 
 private:
        Stream::Ptr m_Stream;
index 6382541bb069c67fd2886695af08973acd62d99e..d13ee55d28245c2642889fd3c3087d1bc7ba3c40 100644 (file)
@@ -45,6 +45,9 @@ class GelfWriter : ConfigObject
        [no_user_modify] bool should_connect {
                default {{{ return true; }}}
        };
+       [config] bool enable_ha {
+               default {{{ return true; }}}
+       };
 };
 
 }