]> granicus.if.org Git - icinga2/commitdiff
Move CompatUtility::GetHostStateString() logic into DB IDO and CompatLogger features
authorMichael Friedrich <michael.friedrich@icinga.com>
Thu, 21 Dec 2017 08:24:04 +0000 (09:24 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 15 Jan 2018 12:39:34 +0000 (13:39 +0100)
lib/compat/compatlogger.cpp
lib/compat/compatlogger.hpp
lib/db_ido/dbevents.cpp
lib/db_ido/dbevents.hpp
lib/icinga/compatutility.cpp
lib/icinga/compatutility.hpp

index 498b434f3f977abdf95f22e08b74e7a975852eb7..253a557e27647a5a42379764745f193366437385 100644 (file)
@@ -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 << "";
index f12ae2e4ad32d6c44f1de612e95f84acf87d403d..1665b19abc8770c9c099f5201c6f661210a5d1fa 100644 (file)
@@ -62,6 +62,8 @@ private:
        void ExternalCommandHandler(const String& command, const std::vector<String>& arguments);
        void EventCommandHandler(const Checkable::Ptr& service);
 
+       static String GetHostStateString(const Host::Ptr& host);
+
        Timer::Ptr m_RotationTimer;
        void RotationTimerHandler();
        void ScheduleNextRotation();
index b2f2ba0124b9d09d36a67ccc144cf23418560b09..a0ec3e441f14223023c34906860d23374bef6c2b 100644 (file)
@@ -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<unsigned long, unsigned long> DbEvents::ConvertTimestamp(double time)
 {
        unsigned long time_sec = static_cast<long>(time);
index 91705e38179b1e36698c0d6bfc32d502d6c7b806..3e27d296099f50ed4a0c4e5ad9807b9f4069f111 100644 (file)
@@ -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<unsigned long, unsigned long> ConvertTimestamp(double time);
        static int MapNotificationReasonType(NotificationType type);
        static int MapExternalCommandType(const String& name);
index 6cb6f9b1254c8e7d1cd3b1f31af2bfe4eebae0b3..93b39b3b61898cfc1aea31434b9d5d84c5e278dd 100644 (file)
@@ -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)
 {
index 98e71a8d7e65ce69b4facb82b3b48bdbeebc8da5..859f4509f49bc7b2f50da0360123a3c1ff931803 100644 (file)
@@ -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);