From e5f5284838860cce51bc3a260fb24819fc6914a1 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 8 Feb 2017 14:53:52 +0100 Subject: [PATCH] Add logging for started/stopped features fixes #3557 --- lib/checker/checkercomponent.cpp | 7 ++++++- lib/compat/checkresultreader.cpp | 16 ++++++++++++++++ lib/compat/checkresultreader.hpp | 1 + lib/compat/compatlogger.cpp | 14 ++++++++++++++ lib/compat/compatlogger.hpp | 1 + lib/compat/externalcommandlistener.cpp | 14 ++++++++++++++ lib/compat/externalcommandlistener.hpp | 1 + lib/compat/statusdatawriter.cpp | 14 ++++++++++++++ lib/compat/statusdatawriter.hpp | 1 + lib/db_ido/dbconnection.cpp | 11 +++++++++++ lib/db_ido/dbconnection.hpp | 1 + lib/db_ido_mysql/idomysqlconnection.cpp | 6 ++++++ lib/db_ido_pgsql/idopgsqlconnection.cpp | 6 ++++++ lib/livestatus/livestatuslistener.cpp | 6 ++++++ lib/notification/notificationcomponent.cpp | 11 +++++++++++ lib/notification/notificationcomponent.hpp | 1 + lib/perfdata/gelfwriter.cpp | 11 +++++++++++ lib/perfdata/gelfwriter.hpp | 1 + lib/perfdata/graphitewriter.cpp | 11 +++++++++++ lib/perfdata/graphitewriter.hpp | 1 + lib/perfdata/influxdbwriter.cpp | 11 +++++++++++ lib/perfdata/influxdbwriter.hpp | 1 + lib/perfdata/opentsdbwriter.cpp | 11 +++++++++++ lib/perfdata/opentsdbwriter.hpp | 1 + lib/perfdata/perfdatawriter.cpp | 11 +++++++++++ lib/perfdata/perfdatawriter.hpp | 1 + lib/remote/apilistener.cpp | 6 ++++++ 27 files changed, 176 insertions(+), 1 deletion(-) diff --git a/lib/checker/checkercomponent.cpp b/lib/checker/checkercomponent.cpp index a35eae769..6e524d9ef 100644 --- a/lib/checker/checkercomponent.cpp +++ b/lib/checker/checkercomponent.cpp @@ -75,6 +75,10 @@ void CheckerComponent::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "CheckerComponent") + << "'" << GetName() << "' started."; + + m_Thread = boost::thread(boost::bind(&CheckerComponent::CheckThreadProc, this)); m_ResultTimer = new Timer(); @@ -85,7 +89,8 @@ void CheckerComponent::Start(bool runtimeCreated) void CheckerComponent::Stop(bool runtimeRemoved) { - Log(LogInformation, "CheckerComponent", "Checker stopped."); + Log(LogInformation, "CheckerComponent") + << "'" << GetName() << "' stopped."; { boost::mutex::scoped_lock lock(m_Mutex); diff --git a/lib/compat/checkresultreader.cpp b/lib/compat/checkresultreader.cpp index 366dcfa79..af374da9f 100644 --- a/lib/compat/checkresultreader.cpp +++ b/lib/compat/checkresultreader.cpp @@ -58,10 +58,26 @@ void CheckResultReader::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "CheckResultReader") + << "'" << GetName() << "' started."; + +#ifndef _WIN32 m_ReadTimer = new Timer(); m_ReadTimer->OnTimerExpired.connect(boost::bind(&CheckResultReader::ReadTimerHandler, this)); m_ReadTimer->SetInterval(5); m_ReadTimer->Start(); +#endif /* _WIN32 */ +} + +/** + * @threadsafety Always. + */ +void CheckResultReader::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "CheckResultReader") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); } /** diff --git a/lib/compat/checkresultreader.hpp b/lib/compat/checkresultreader.hpp index 0d869bcd1..f3e6b1496 100644 --- a/lib/compat/checkresultreader.hpp +++ b/lib/compat/checkresultreader.hpp @@ -42,6 +42,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: Timer::Ptr m_ReadTimer; diff --git a/lib/compat/compatlogger.cpp b/lib/compat/compatlogger.cpp index 233e53f54..a7d3d91f0 100644 --- a/lib/compat/compatlogger.cpp +++ b/lib/compat/compatlogger.cpp @@ -60,6 +60,9 @@ void CompatLogger::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "CompatLogger") + << "'" << GetName() << "' started."; + Checkable::OnNewCheckResult.connect(bind(&CompatLogger::CheckResultHandler, this, _1, _2)); Checkable::OnNotificationSentToUser.connect(bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8)); Downtime::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1)); @@ -79,6 +82,17 @@ void CompatLogger::Start(bool runtimeCreated) ScheduleNextRotation(); } +/** + * @threadsafety Always. + */ +void CompatLogger::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "CompatLogger") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + /** * @threadsafety Always. */ diff --git a/lib/compat/compatlogger.hpp b/lib/compat/compatlogger.hpp index fd73aeab8..fbb72aaad 100644 --- a/lib/compat/compatlogger.hpp +++ b/lib/compat/compatlogger.hpp @@ -45,6 +45,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: void WriteLine(const String& line); diff --git a/lib/compat/externalcommandlistener.cpp b/lib/compat/externalcommandlistener.cpp index 2064e5700..3278831a7 100644 --- a/lib/compat/externalcommandlistener.cpp +++ b/lib/compat/externalcommandlistener.cpp @@ -50,12 +50,26 @@ void ExternalCommandListener::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "ExternalCommandListener") + << "'" << GetName() << "' started."; + #ifndef _WIN32 m_CommandThread = boost::thread(boost::bind(&ExternalCommandListener::CommandPipeThread, this, GetCommandPath())); m_CommandThread.detach(); #endif /* _WIN32 */ } +/** + * Stops the component. + */ +void ExternalCommandListener::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "ExternalCommandListener") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + #ifndef _WIN32 void ExternalCommandListener::CommandPipeThread(const String& commandPath) { diff --git a/lib/compat/externalcommandlistener.hpp b/lib/compat/externalcommandlistener.hpp index 0af245323..02df0ded3 100644 --- a/lib/compat/externalcommandlistener.hpp +++ b/lib/compat/externalcommandlistener.hpp @@ -43,6 +43,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: #ifndef _WIN32 diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index d3517d93c..a9b506912 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -73,6 +73,9 @@ void StatusDataWriter::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "StatusDataWriter") + << "'" << GetName() << "' started."; + m_ObjectsCacheOutdated = true; m_StatusTimer = new Timer(); @@ -85,6 +88,17 @@ void StatusDataWriter::Start(bool runtimeCreated) ConfigObject::OnActiveChanged.connect(boost::bind(&StatusDataWriter::ObjectHandler, this)); } +/** + * Stops the component. + */ +void StatusDataWriter::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "StatusDataWriter") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + void StatusDataWriter::DumpComments(std::ostream& fp, const Checkable::Ptr& checkable) { Host::Ptr host; diff --git a/lib/compat/statusdatawriter.hpp b/lib/compat/statusdatawriter.hpp index 595c7ca26..3a0460fd3 100644 --- a/lib/compat/statusdatawriter.hpp +++ b/lib/compat/statusdatawriter.hpp @@ -47,6 +47,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: Timer::Ptr m_StatusTimer; diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index ad97f9a49..e27e18cb1 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -72,10 +72,21 @@ void DbConnection::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "DbConnection") + << "'" << GetName() << "' started."; + DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1)); DbObject::OnMultipleQueries.connect(boost::bind(&DbConnection::ExecuteMultipleQueries, this, _1)); } +void DbConnection::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "DbConnection") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + void DbConnection::EnableActiveChangedHandler(void) { if (!m_ActiveChangedHandler) { diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp index 3cfbd8f57..08933b5d7 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -81,6 +81,7 @@ public: protected: virtual void OnConfigLoaded(void) override; virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; virtual void Resume(void) override; virtual void Pause(void) override; diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 34969c3a0..e71dec1b8 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -77,6 +77,9 @@ void IdoMysqlConnection::Resume(void) { DbConnection::Resume(); + Log(LogInformation, "IdoMysqlConnection") + << "'" << GetName() << "' resumed."; + SetConnected(false); m_QueryQueue.SetExceptionCallback(boost::bind(&IdoMysqlConnection::ExceptionHandler, this, _1)); @@ -97,6 +100,9 @@ void IdoMysqlConnection::Resume(void) void IdoMysqlConnection::Pause(void) { + Log(LogInformation, "IdoMysqlConnection") + << "'" << GetName() << "' paused."; + m_ReconnectTimer.reset(); DbConnection::Pause(); diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index c16f9f50f..4b37965d3 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -81,6 +81,9 @@ void IdoPgsqlConnection::Resume(void) { DbConnection::Resume(); + Log(LogInformation, "IdoPgsqlConnection") + << "'" << GetName() << "' resumed."; + SetConnected(false); m_QueryQueue.SetExceptionCallback(boost::bind(&IdoPgsqlConnection::ExceptionHandler, this, _1)); @@ -101,6 +104,9 @@ void IdoPgsqlConnection::Resume(void) void IdoPgsqlConnection::Pause(void) { + Log(LogInformation, "IdoPgsqlConnection") + << "'" << GetName() << "' paused."; + m_ReconnectTimer.reset(); DbConnection::Pause(); diff --git a/lib/livestatus/livestatuslistener.cpp b/lib/livestatus/livestatuslistener.cpp index c8163ec06..9c8f7701f 100644 --- a/lib/livestatus/livestatuslistener.cpp +++ b/lib/livestatus/livestatuslistener.cpp @@ -66,6 +66,9 @@ void LivestatusListener::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "LivestatusListener") + << "'" << GetName() << "' started."; + if (GetSocketType() == "tcp") { TcpSocket::Ptr socket = new TcpSocket(); @@ -123,6 +126,9 @@ void LivestatusListener::Stop(bool runtimeRemoved) { ObjectImpl::Stop(runtimeRemoved); + Log(LogInformation, "LivestatusListener") + << "'" << GetName() << "' stopped."; + m_Listener->Close(); if (m_Thread.joinable()) diff --git a/lib/notification/notificationcomponent.cpp b/lib/notification/notificationcomponent.cpp index b00a8a27f..3eebcf164 100644 --- a/lib/notification/notificationcomponent.cpp +++ b/lib/notification/notificationcomponent.cpp @@ -52,6 +52,9 @@ void NotificationComponent::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "NotificationComponent") + << "'" << GetName() << "' started."; + Checkable::OnNotificationsRequested.connect(boost::bind(&NotificationComponent::SendNotificationsHandler, this, _1, _2, _3, _4, _5)); @@ -61,6 +64,14 @@ void NotificationComponent::Start(bool runtimeCreated) m_NotificationTimer->Start(); } +void NotificationComponent::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "NotificationComponent") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + /** * Periodically sends notifications. * diff --git a/lib/notification/notificationcomponent.hpp b/lib/notification/notificationcomponent.hpp index 96388e6f5..53fd8992d 100644 --- a/lib/notification/notificationcomponent.hpp +++ b/lib/notification/notificationcomponent.hpp @@ -40,6 +40,7 @@ public: static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: Timer::Ptr m_NotificationTimer; diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index 3385ddfe3..2707640e4 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -43,6 +43,9 @@ void GelfWriter::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "GelfWriter") + << "'" << GetName() << "' started."; + m_ReconnectTimer = new Timer(); m_ReconnectTimer->SetInterval(10); m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&GelfWriter::ReconnectTimerHandler, this)); @@ -57,6 +60,14 @@ void GelfWriter::Start(bool runtimeCreated) Service::OnStateChange.connect(boost::bind(&GelfWriter::StateChangeHandler, this, _1, _2, _3)); } +void GelfWriter::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "GelfWriter") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + void GelfWriter::ReconnectTimerHandler(void) { if (m_Stream) diff --git a/lib/perfdata/gelfwriter.hpp b/lib/perfdata/gelfwriter.hpp index 25841fb48..26bb1c426 100644 --- a/lib/perfdata/gelfwriter.hpp +++ b/lib/perfdata/gelfwriter.hpp @@ -43,6 +43,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: Stream::Ptr m_Stream; diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 263960a63..2463d3299 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -61,6 +61,9 @@ void GraphiteWriter::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "GraphiteWriter") + << "'" << GetName() << "' started."; + m_ReconnectTimer = new Timer(); m_ReconnectTimer->SetInterval(10); m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&GraphiteWriter::ReconnectTimerHandler, this)); @@ -70,6 +73,14 @@ void GraphiteWriter::Start(bool runtimeCreated) Service::OnNewCheckResult.connect(boost::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2)); } +void GraphiteWriter::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "GraphiteWriter") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + void GraphiteWriter::ReconnectTimerHandler(void) { if (m_Stream) diff --git a/lib/perfdata/graphitewriter.hpp b/lib/perfdata/graphitewriter.hpp index 8d42529e4..8eca129b4 100644 --- a/lib/perfdata/graphitewriter.hpp +++ b/lib/perfdata/graphitewriter.hpp @@ -48,6 +48,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: Stream::Ptr m_Stream; diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 252deeb4e..198d0658f 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -69,6 +69,9 @@ void InfluxdbWriter::Start(bool runtimeCreated) ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "InfluxdbWriter") + << "'" << GetName() << "' started."; + m_FlushTimer = new Timer(); m_FlushTimer->SetInterval(GetFlushInterval()); m_FlushTimer->OnTimerExpired.connect(boost::bind(&InfluxdbWriter::FlushTimeout, this)); @@ -78,6 +81,14 @@ void InfluxdbWriter::Start(bool runtimeCreated) Service::OnNewCheckResult.connect(boost::bind(&InfluxdbWriter::CheckResultHandler, this, _1, _2)); } +void InfluxdbWriter::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "InfluxdbWriter") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + Stream::Ptr InfluxdbWriter::Connect(TcpSocket::Ptr& socket) { socket = new TcpSocket(); diff --git a/lib/perfdata/influxdbwriter.hpp b/lib/perfdata/influxdbwriter.hpp index 528af2c81..d7fbe6e18 100644 --- a/lib/perfdata/influxdbwriter.hpp +++ b/lib/perfdata/influxdbwriter.hpp @@ -48,6 +48,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: Timer::Ptr m_FlushTimer; diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index 01cb9f2bb..2e2f0fc7d 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -61,6 +61,9 @@ void OpenTsdbWriter::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "OpentsdbWriter") + << "'" << GetName() << "' started."; + m_ReconnectTimer = new Timer(); m_ReconnectTimer->SetInterval(10); m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&OpenTsdbWriter::ReconnectTimerHandler, this)); @@ -70,6 +73,14 @@ void OpenTsdbWriter::Start(bool runtimeCreated) Service::OnNewCheckResult.connect(boost::bind(&OpenTsdbWriter::CheckResultHandler, this, _1, _2)); } +void OpenTsdbWriter::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "OpentsdbWriter") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + void OpenTsdbWriter::ReconnectTimerHandler(void) { if (m_Stream) diff --git a/lib/perfdata/opentsdbwriter.hpp b/lib/perfdata/opentsdbwriter.hpp index c399ce967..b6c177567 100644 --- a/lib/perfdata/opentsdbwriter.hpp +++ b/lib/perfdata/opentsdbwriter.hpp @@ -45,6 +45,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: Stream::Ptr m_Stream; diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 1c8b0a6b6..0ba3e8940 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -53,6 +53,9 @@ void PerfdataWriter::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + Log(LogInformation, "PerfdataWriter") + << "'" << GetName() << "' started."; + Checkable::OnNewCheckResult.connect(boost::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2)); m_RotationTimer = new Timer(); @@ -64,6 +67,14 @@ void PerfdataWriter::Start(bool runtimeCreated) RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath()); } +void PerfdataWriter::Stop(bool runtimeRemoved) +{ + Log(LogInformation, "PerfdataWriter") + << "'" << GetName() << "' stopped."; + + ObjectImpl::Stop(runtimeRemoved); +} + Value PerfdataWriter::EscapeMacroMetric(const Value& value) { if (value.IsObjectType()) diff --git a/lib/perfdata/perfdatawriter.hpp b/lib/perfdata/perfdatawriter.hpp index 82b2e3a06..fd4fa4de8 100644 --- a/lib/perfdata/perfdatawriter.hpp +++ b/lib/perfdata/perfdatawriter.hpp @@ -47,6 +47,7 @@ public: protected: virtual void Start(bool runtimeCreated) override; + virtual void Stop(bool runtimeRemoved) override; private: void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index e9345f4d4..55f628fa8 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -127,6 +127,9 @@ void ApiListener::OnAllConfigLoaded(void) */ void ApiListener::Start(bool runtimeCreated) { + Log(LogInformation, "ApiListener") + << "'" << GetName() << "' started."; + SyncZoneDirs(); ObjectImpl::Start(runtimeCreated); @@ -168,6 +171,9 @@ void ApiListener::Stop(bool runtimeDeleted) { ObjectImpl::Stop(runtimeDeleted); + Log(LogInformation, "ApiListener") + << "'" << GetName() << "' stopped."; + boost::mutex::scoped_lock lock(m_LogLock); CloseLogFile(); }