diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index f18a494b5..0ac997749 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -95,16 +95,17 @@ void ElasticsearchWriter::Resume() m_FlushTimer->Reschedule(0); /* Register for new metrics. */ - Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { + m_HandleCheckResults = Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, + const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { CheckResultHandler(checkable, cr); }); - Checkable::OnStateChange.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type, - const MessageOrigin::Ptr&) { + m_HandleStateChanges = Checkable::OnStateChange.connect([this](const Checkable::Ptr& checkable, + const CheckResult::Ptr& cr, StateType type, const MessageOrigin::Ptr&) { StateChangeHandler(checkable, cr, type); }); - Checkable::OnNotificationSentToAllUsers.connect([this](const Notification::Ptr& notification, const Checkable::Ptr& checkable, - const std::set& users, const NotificationType& type, const CheckResult::Ptr& cr, const String& author, - const String& text, const MessageOrigin::Ptr&) { + m_HandleNotifications = Checkable::OnNotificationSentToAllUsers.connect([this](const Notification::Ptr& notification, + const Checkable::Ptr& checkable, const std::set& users, const NotificationType& type, + const CheckResult::Ptr& cr, const String& author, const String& text, const MessageOrigin::Ptr&) { NotificationSentToAllUsersHandler(notification, checkable, users, type, cr, author, text); }); } @@ -112,6 +113,10 @@ void ElasticsearchWriter::Resume() /* Pause is equivalent to Stop, but with HA capabilities to resume at runtime. */ void ElasticsearchWriter::Pause() { + m_HandleCheckResults.disconnect(); + m_HandleStateChanges.disconnect(); + m_HandleNotifications.disconnect(); + Flush(); m_WorkQueue.Join(); Flush(); diff --git a/lib/perfdata/elasticsearchwriter.hpp b/lib/perfdata/elasticsearchwriter.hpp index 33bc832e7..a988094d8 100644 --- a/lib/perfdata/elasticsearchwriter.hpp +++ b/lib/perfdata/elasticsearchwriter.hpp @@ -31,6 +31,7 @@ protected: private: String m_EventPrefix; WorkQueue m_WorkQueue{10000000, 1}; + boost::signals2::connection m_HandleCheckResults, m_HandleStateChanges, m_HandleNotifications; Timer::Ptr m_FlushTimer; std::vector m_DataBuffer; std::mutex m_DataBufferMutex; diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index f8ebb61d3..843f56a1e 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -90,16 +90,17 @@ void GelfWriter::Resume() m_ReconnectTimer->Reschedule(0); /* Register event handlers. */ - Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { + m_HandleCheckResults = Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, + const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { CheckResultHandler(checkable, cr); }); - Checkable::OnNotificationSentToUser.connect([this](const Notification::Ptr& notification, const Checkable::Ptr& checkable, - const User::Ptr& user, const NotificationType& type, const CheckResult::Ptr& cr, const String& author, - const String& commentText, const String& commandName, const MessageOrigin::Ptr&) { + m_HandleNotifications = Checkable::OnNotificationSentToUser.connect([this](const Notification::Ptr& notification, + const Checkable::Ptr& checkable, const User::Ptr& user, const NotificationType& type, const CheckResult::Ptr& cr, + const String& author, const String& commentText, const String& commandName, const MessageOrigin::Ptr&) { NotificationToUserHandler(notification, checkable, user, type, cr, author, commentText, commandName); }); - Checkable::OnStateChange.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type, - const MessageOrigin::Ptr&) { + m_HandleStateChanges = Checkable::OnStateChange.connect([this](const Checkable::Ptr& checkable, + const CheckResult::Ptr& cr, StateType type, const MessageOrigin::Ptr&) { StateChangeHandler(checkable, cr, type); }); } @@ -107,6 +108,10 @@ void GelfWriter::Resume() /* Pause is equivalent to Stop, but with HA capabilities to resume at runtime. */ void GelfWriter::Pause() { + m_HandleCheckResults.disconnect(); + m_HandleNotifications.disconnect(); + m_HandleStateChanges.disconnect(); + m_ReconnectTimer.reset(); try { diff --git a/lib/perfdata/gelfwriter.hpp b/lib/perfdata/gelfwriter.hpp index 1fee2f0e7..ce9ee3545 100644 --- a/lib/perfdata/gelfwriter.hpp +++ b/lib/perfdata/gelfwriter.hpp @@ -36,6 +36,7 @@ private: OptionalTlsStream m_Stream; WorkQueue m_WorkQueue{10000000, 1}; + boost::signals2::connection m_HandleCheckResults, m_HandleNotifications, m_HandleStateChanges; Timer::Ptr m_ReconnectTimer; void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index dd99cdb1b..fc1c7edff 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -95,7 +95,8 @@ void GraphiteWriter::Resume() m_ReconnectTimer->Reschedule(0); /* Register event handlers. */ - Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { + m_HandleCheckResults = Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, + const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { CheckResultHandler(checkable, cr); }); } @@ -105,6 +106,7 @@ void GraphiteWriter::Resume() */ void GraphiteWriter::Pause() { + m_HandleCheckResults.disconnect(); m_ReconnectTimer.reset(); try { diff --git a/lib/perfdata/graphitewriter.hpp b/lib/perfdata/graphitewriter.hpp index a43ebbce5..e0c8b7846 100644 --- a/lib/perfdata/graphitewriter.hpp +++ b/lib/perfdata/graphitewriter.hpp @@ -41,6 +41,7 @@ private: std::mutex m_StreamMutex; WorkQueue m_WorkQueue{10000000, 1}; + boost::signals2::connection m_HandleCheckResults; Timer::Ptr m_ReconnectTimer; void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); diff --git a/lib/perfdata/influxdbcommonwriter.cpp b/lib/perfdata/influxdbcommonwriter.cpp index 220841001..a42d9e182 100644 --- a/lib/perfdata/influxdbcommonwriter.cpp +++ b/lib/perfdata/influxdbcommonwriter.cpp @@ -97,7 +97,8 @@ void InfluxdbCommonWriter::Resume() m_FlushTimer->Reschedule(0); /* Register for new metrics. */ - Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { + m_HandleCheckResults = Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, + const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { CheckResultHandler(checkable, cr); }); } @@ -105,6 +106,8 @@ void InfluxdbCommonWriter::Resume() /* Pause is equivalent to Stop, but with HA capabilities to resume at runtime. */ void InfluxdbCommonWriter::Pause() { + m_HandleCheckResults.disconnect(); + /* Force a flush. */ Log(LogDebug, GetReflectionType()->GetName()) << "Processing pending tasks and flushing data buffers."; diff --git a/lib/perfdata/influxdbcommonwriter.hpp b/lib/perfdata/influxdbcommonwriter.hpp index 791a326b4..380b20c9f 100644 --- a/lib/perfdata/influxdbcommonwriter.hpp +++ b/lib/perfdata/influxdbcommonwriter.hpp @@ -47,6 +47,7 @@ protected: virtual Url::Ptr AssembleUrl() = 0; private: + boost::signals2::connection m_HandleCheckResults; Timer::Ptr m_FlushTimer; WorkQueue m_WorkQueue{10000000, 1}; std::vector m_DataBuffer; diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index d9dd2cd80..2d5720ec0 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -81,7 +81,7 @@ void OpenTsdbWriter::Resume() m_ReconnectTimer->Start(); m_ReconnectTimer->Reschedule(0); - Service::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { + m_HandleCheckResults = Service::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { CheckResultHandler(checkable, cr); }); } @@ -91,6 +91,7 @@ void OpenTsdbWriter::Resume() */ void OpenTsdbWriter::Pause() { + m_HandleCheckResults.disconnect(); m_ReconnectTimer.reset(); Log(LogInformation, "OpentsdbWriter") diff --git a/lib/perfdata/opentsdbwriter.hpp b/lib/perfdata/opentsdbwriter.hpp index 5531bdae2..e37ef4257 100644 --- a/lib/perfdata/opentsdbwriter.hpp +++ b/lib/perfdata/opentsdbwriter.hpp @@ -37,6 +37,7 @@ protected: private: Shared::Ptr m_Stream; + boost::signals2::connection m_HandleCheckResults; Timer::Ptr m_ReconnectTimer; Dictionary::Ptr m_ServiceConfigTemplate; diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 5472988e3..bb6fda3a2 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -53,7 +53,8 @@ void PerfdataWriter::Resume() Log(LogInformation, "PerfdataWriter") << "'" << GetName() << "' resumed."; - Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { + m_HandleCheckResults = Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, + const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) { CheckResultHandler(checkable, cr); }); @@ -68,6 +69,7 @@ void PerfdataWriter::Resume() void PerfdataWriter::Pause() { + m_HandleCheckResults.disconnect(); m_RotationTimer.reset(); #ifdef I2_DEBUG diff --git a/lib/perfdata/perfdatawriter.hpp b/lib/perfdata/perfdatawriter.hpp index f02ff7226..961d4e954 100644 --- a/lib/perfdata/perfdatawriter.hpp +++ b/lib/perfdata/perfdatawriter.hpp @@ -34,6 +34,7 @@ protected: void Pause() override; private: + boost::signals2::connection m_HandleCheckResults; Timer::Ptr m_RotationTimer; std::ofstream m_ServiceOutputFile; std::ofstream m_HostOutputFile;