From 7a012c062a0099322a3fa12265c7164f1445c992 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 09:24:04 +0100 Subject: [PATCH] Move CompatUtility::GetHostStateString() logic into DB IDO and CompatLogger features --- lib/compat/compatlogger.cpp | 18 +++++++++++++----- lib/compat/compatlogger.hpp | 2 ++ lib/db_ido/dbevents.cpp | 10 +++++++++- lib/db_ido/dbevents.hpp | 1 + lib/icinga/compatutility.cpp | 9 --------- lib/icinga/compatutility.hpp | 3 --- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/compat/compatlogger.cpp b/lib/compat/compatlogger.cpp index 498b434f3..253a557e2 100644 --- a/lib/compat/compatlogger.cpp +++ b/lib/compat/compatlogger.cpp @@ -142,7 +142,7 @@ void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const Che msgbuf << "HOST ALERT: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << attempt_after << ";" << output << "" @@ -258,7 +258,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification if (service) notification_type_str = Service::StateToString(service->GetState()); else - notification_type_str = CompatUtility::GetHostStateString(host); + notification_type_str = GetHostStateString(host); } String author_comment = ""; @@ -290,7 +290,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification << user->GetName() << ";" << host->GetName() << ";" << notification_type_str << " " - << "(" << CompatUtility::GetHostStateString(host) << ");" + << "(" << GetHostStateString(host) << ");" << command_name << ";" << output << ";" << author_comment @@ -422,7 +422,7 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable) } else { msgbuf << "HOST EVENT HANDLER: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << current_attempt << ";" << event_command_name; @@ -435,6 +435,14 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable) } } +String CompatLogger::GetHostStateString(const Host::Ptr& host) +{ + if (host->GetState() != HostUp && !host->IsReachable()) + return "UNREACHABLE"; /* hardcoded compat state */ + + return Host::StateToString(host->GetState()); +} + void CompatLogger::WriteLine(const String& line) { ASSERT(OwnsLock()); @@ -499,7 +507,7 @@ void CompatLogger::ReopenFile(bool rotate) std::ostringstream msgbuf; msgbuf << "CURRENT HOST STATE: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << host->GetCheckAttempt() << ";" << output << ""; diff --git a/lib/compat/compatlogger.hpp b/lib/compat/compatlogger.hpp index f12ae2e4a..1665b19ab 100644 --- a/lib/compat/compatlogger.hpp +++ b/lib/compat/compatlogger.hpp @@ -62,6 +62,8 @@ private: void ExternalCommandHandler(const String& command, const std::vector& arguments); void EventCommandHandler(const Checkable::Ptr& service); + static String GetHostStateString(const Host::Ptr& host); + Timer::Ptr m_RotationTimer; void RotationTimerHandler(); void ScheduleNextRotation(); diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index b2f2ba012..a0ec3e441 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -1025,7 +1025,7 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C } else { msgbuf << "HOST ALERT: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << attempt_after << ";" << output << "" @@ -1522,6 +1522,14 @@ int DbEvents::GetHostState(const Host::Ptr& host) return currentState; } +String DbEvents::GetHostStateString(const Host::Ptr& host) +{ + if (host->GetState() != HostUp && !host->IsReachable()) + return "UNREACHABLE"; /* hardcoded compat state */ + + return Host::StateToString(host->GetState()); +} + std::pair DbEvents::ConvertTimestamp(double time) { unsigned long time_sec = static_cast(time); diff --git a/lib/db_ido/dbevents.hpp b/lib/db_ido/dbevents.hpp index 91705e381..3e27d2960 100644 --- a/lib/db_ido/dbevents.hpp +++ b/lib/db_ido/dbevents.hpp @@ -134,6 +134,7 @@ private: static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled); static int GetHostState(const Host::Ptr& host); + static String GetHostStateString(const Host::Ptr& host); static std::pair ConvertTimestamp(double time); static int MapNotificationReasonType(NotificationType type); static int MapExternalCommandType(const String& name); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 6cb6f9b12..93b39b3b6 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -81,15 +81,6 @@ String CompatUtility::GetCommandName(const Command::Ptr& command) return GetCommandNamePrefix(command) + command->GetName(); } -/* Used in StatusDataWriter and DB IDO. */ -String CompatUtility::GetHostStateString(const Host::Ptr& host) -{ - if (host->GetState() != HostUp && !host->IsReachable()) - return "UNREACHABLE"; /* hardcoded compat state */ - - return Host::StateToString(host->GetState()); -} - /* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 98e71a8d7..859f4509f 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -39,9 +39,6 @@ public: static String GetCommandLine(const Command::Ptr& command); static String GetCommandName(const Command::Ptr& command); - /* host */ - static String GetHostStateString(const Host::Ptr& host); - /* service */ static String GetCheckableCommandArgs(const Checkable::Ptr& checkable); -- 2.40.0