From 97c1296e9994a396f9017be4c6b30ad351ac7a12 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 24 Oct 2018 13:55:19 +0200 Subject: [PATCH] Implement HA functionality for OpenTsdb feature --- lib/perfdata/opentsdbwriter.cpp | 32 ++++++++++++++++++++++++++------ lib/perfdata/opentsdbwriter.hpp | 5 +++-- lib/perfdata/opentsdbwriter.ti | 3 +++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index 1099f4449..78feea8f2 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -44,6 +44,20 @@ REGISTER_TYPE(OpenTsdbWriter); REGISTER_STATSFUNCTION(OpenTsdbWriter, &OpenTsdbWriter::StatsFunc); +void OpenTsdbWriter::OnConfigLoaded() +{ + ObjectImpl::OnConfigLoaded(); + + if (!GetEnableHa()) { + Log(LogDebug, "OpenTsdbWriter") + << "HA functionality disabled. Won't pause connection: " << GetName(); + + SetHAMode(HARunEverywhere); + } else { + SetHAMode(HARunOnce); + } +} + void OpenTsdbWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&) { DictionaryData nodes; @@ -55,12 +69,12 @@ void OpenTsdbWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&) status->Set("opentsdbwriter", new Dictionary(std::move(nodes))); } -void OpenTsdbWriter::Start(bool runtimeCreated) +void OpenTsdbWriter::Resume() { - ObjectImpl::Start(runtimeCreated); + ObjectImpl::Resume(); Log(LogInformation, "OpentsdbWriter") - << "'" << GetName() << "' started."; + << "'" << GetName() << "' resumed."; m_ReconnectTimer = new Timer(); m_ReconnectTimer->SetInterval(10); @@ -71,16 +85,19 @@ void OpenTsdbWriter::Start(bool runtimeCreated) Service::OnNewCheckResult.connect(std::bind(&OpenTsdbWriter::CheckResultHandler, this, _1, _2)); } -void OpenTsdbWriter::Stop(bool runtimeRemoved) +void OpenTsdbWriter::Pause() { Log(LogInformation, "OpentsdbWriter") - << "'" << GetName() << "' stopped."; + << "'" << GetName() << "' paused."; - ObjectImpl::Stop(runtimeRemoved); + ObjectImpl::Pause(); } void OpenTsdbWriter::ReconnectTimerHandler() { + if (IsPaused()) + return; + if (m_Stream) return; @@ -102,6 +119,9 @@ void OpenTsdbWriter::ReconnectTimerHandler() void OpenTsdbWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr) { + if (IsPaused()) + return; + CONTEXT("Processing check result for '" + checkable->GetName() + "'"); if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata()) diff --git a/lib/perfdata/opentsdbwriter.hpp b/lib/perfdata/opentsdbwriter.hpp index 4d40387dd..193d6b31a 100644 --- a/lib/perfdata/opentsdbwriter.hpp +++ b/lib/perfdata/opentsdbwriter.hpp @@ -44,8 +44,9 @@ public: static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); protected: - void Start(bool runtimeCreated) override; - void Stop(bool runtimeRemoved) override; + void OnConfigLoaded() override; + void Resume() override; + void Pause() override; private: Stream::Ptr m_Stream; diff --git a/lib/perfdata/opentsdbwriter.ti b/lib/perfdata/opentsdbwriter.ti index fbec3a491..3418e1606 100644 --- a/lib/perfdata/opentsdbwriter.ti +++ b/lib/perfdata/opentsdbwriter.ti @@ -34,6 +34,9 @@ class OpenTsdbWriter : ConfigObject [config] String port { default {{{ return "4242"; }}} }; + [config] bool enable_ha { + default {{{ return true; }}} + }; }; } -- 2.40.0