From: Michael Friedrich Date: Wed, 24 Oct 2018 11:43:38 +0000 (+0200) Subject: Implement HA functionality for Gelf feature X-Git-Tag: v2.11.0-rc1~312^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b905999f4bf71af6e408b35aa0381023d1c718ae;p=icinga2 Implement HA functionality for Gelf feature --- diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index 78e15ff77..c4c0912d2 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -51,6 +51,15 @@ void GelfWriter::OnConfigLoaded() ObjectImpl::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::Start(runtimeCreated); + ObjectImpl::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::Stop(runtimeRemoved); + ObjectImpl::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)); } diff --git a/lib/perfdata/gelfwriter.hpp b/lib/perfdata/gelfwriter.hpp index 4e27a3c92..32e35da57 100644 --- a/lib/perfdata/gelfwriter.hpp +++ b/lib/perfdata/gelfwriter.hpp @@ -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; diff --git a/lib/perfdata/gelfwriter.ti b/lib/perfdata/gelfwriter.ti index 6382541bb..d13ee55d2 100644 --- a/lib/perfdata/gelfwriter.ti +++ b/lib/perfdata/gelfwriter.ti @@ -45,6 +45,9 @@ class GelfWriter : ConfigObject [no_user_modify] bool should_connect { default {{{ return true; }}} }; + [config] bool enable_ha { + default {{{ return true; }}} + }; }; }