]> granicus.if.org Git - icinga2/commitdiff
Fix wrong calculation for host compat state UNREACHABLE
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 4 Sep 2015 11:24:41 +0000 (13:24 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 4 Sep 2015 11:24:41 +0000 (13:24 +0200)
fixes #10058

lib/compat/compatlogger.cpp
lib/compat/statusdatawriter.cpp
lib/db_ido/dbevents.cpp
lib/db_ido/hostdbobject.cpp
lib/icinga/checkable-dependency.cpp
lib/icinga/compatutility.cpp
lib/icinga/compatutility.hpp
lib/icinga/dependency.cpp
lib/perfdata/gelfwriter.cpp

index 3f0b679476bb06d70990fb41c885041abe3a65a6..b23622f7ac2f8d24d5058c255a85cd430a3e6160 100644 (file)
@@ -119,21 +119,18 @@ void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const Che
                msgbuf << "SERVICE ALERT: "
                       << host->GetName() << ";"
                       << service->GetShortName() << ";"
-                      << Service::StateToString(static_cast<ServiceState>(state_after)) << ";"
-                      << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
+                      << Service::StateToString(service->GetState()) << ";"
+                      << Service::StateTypeToString(service->GetStateType()) << ";"
                       << attempt_after << ";"
                       << output << ""
                       << "";
        } else {
                String state = Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after)));
 
-               if (!reachable_after)
-                       state = "UNREACHABLE";
-
                msgbuf << "HOST ALERT: "
                       << host->GetName() << ";"
-                      << state << ";"
-                      << Host::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
+                      << CompatUtility::GetHostStateString(host) << ";"
+                      << Host::StateTypeToString(host->GetStateType()) << ";"
                       << attempt_after << ";"
                       << output << ""
                       << "";
@@ -248,7 +245,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification
                if (service)
                        notification_type_str = Service::StateToString(service->GetState());
                else
-                       notification_type_str = host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE";
+                       notification_type_str = CompatUtility::GetHostStateString(host);
        }
 
        String author_comment = "";
@@ -280,7 +277,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification
                        << user->GetName() << ";"
                        << host->GetName() << ";"
                        << notification_type_str << " "
-                       << "(" << (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ");"
+                       << "(" << CompatUtility::GetHostStateString(host) << ");"
                        << command_name << ";"
                        << output << ";"
                        << author_comment
@@ -412,7 +409,7 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable)
        } else {
                msgbuf << "HOST EVENT HANDLER: "
                        << host->GetName() << ";"
-                       << (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ";"
+                       << CompatUtility::GetHostStateString(host) << ";"
                        << Host::StateTypeToString(host->GetStateType()) << ";"
                        << current_attempt << ";"
                        << event_command_name;
@@ -489,7 +486,7 @@ void CompatLogger::ReopenFile(bool rotate)
                std::ostringstream msgbuf;
                msgbuf << "CURRENT HOST STATE: "
                       << host->GetName() << ";"
-                      << (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ";"
+                      << CompatUtility::GetHostStateString(host) << ";"
                       << Host::StateTypeToString(host->GetStateType()) << ";"
                       << host->GetCheckAttempt() << ";"
                       << output << "";
index 97f2528d7579c5a301c0f367b4e429333423744c..94f3e0477c828f359446147f212e7f8c2a219c77 100644 (file)
@@ -356,7 +356,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
                fp << "\t" << "current_state=" << service->GetState() << "\n"
                   << "\t" << "last_hard_state=" << service->GetLastHardState() << "\n";
        } else {
-               fp << "\t" << "current_state=" << (host->IsReachable() ? host->GetState() : 2) << "\n"
+               fp << "\t" << "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n"
                   << "\t" << "last_hard_state=" << host->GetLastHardState() << "\n";
        }
 
index 77b13e5068a19803ad4d07becc6d869797012537..afcd8e86be6bd4929055592135d295352b46a740 100644 (file)
@@ -983,8 +983,8 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C
                msgbuf << "SERVICE ALERT: "
                       << host->GetName() << ";"
                       << service->GetShortName() << ";"
-                      << Service::StateToString(static_cast<ServiceState>(state_after)) << ";"
-                      << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
+                      << Service::StateToString(service->GetState()) << ";"
+                      << Service::StateTypeToString(service->GetStateType()) << ";"
                       << attempt_after << ";"
                       << output << ""
                       << "";
@@ -1008,15 +1008,10 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C
                                return;
                }
        } else {
-               String state = Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after)));
-
-               if (!reachable_after)
-                       state = "UNREACHABLE";
-
                msgbuf << "HOST ALERT: "
                       << host->GetName() << ";"
-                      << state << ";"
-                      << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
+                      << CompatUtility::GetHostStateString(host) << ";"
+                      << Host::StateTypeToString(host->GetStateType()) << ";"
                       << attempt_after << ";"
                       << output << ""
                       << "";
index 3210c309531fdf626459fafada6fedda368c8306..919061c27398684468ba9a9bf41b09309c113f32 100644 (file)
@@ -122,7 +122,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields(void) const
                fields->Set("check_source", cr->GetCheckSource());
        }
 
-       fields->Set("current_state", host->IsReachable() ? host->GetState() : 2);
+       fields->Set("current_state", CompatUtility::GetHostCurrentState(host));
        fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(host));
        fields->Set("should_be_scheduled", host->GetEnableActiveChecks());
        fields->Set("current_check_attempt", host->GetCheckAttempt());
index 89f2a96de4701a44f16da00c4008a156dbb67913..f3769faec556647039bd7f8b19ba8dcee99efac8 100644 (file)
@@ -69,8 +69,8 @@ bool Checkable::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency
                return false;
        }
 
-       BOOST_FOREACH(const Checkable::Ptr& service, GetParents()) {
-               if (!service->IsReachable(dt, failedDependency, rstack + 1))
+       BOOST_FOREACH(const Checkable::Ptr& checkable, GetParents()) {
+               if (!checkable->IsReachable(dt, failedDependency, rstack + 1))
                        return false;
        }
 
index 11bb2370ecfab1844d2df9ed916354bf00bab584..709d9d5f9c2de94bb21974fc797279548a4981d1 100644 (file)
@@ -81,6 +81,22 @@ String CompatUtility::GetCommandName(const Command::Ptr command)
 }
 
 /* host */
+int CompatUtility::GetHostCurrentState(const Host::Ptr& host)
+{
+       if (host->GetState() != HostUp && !host->IsReachable())
+               return 2; /* hardcoded compat state */
+
+       return host->GetState();
+}
+
+String CompatUtility::GetHostStateString(const Host::Ptr& host)
+{
+       if (host->GetState() != HostUp && !host->IsReachable())
+               return "UNREACHABLE"; /* hardcoded compat state */
+
+       return Host::StateToString(host->GetState());
+}
+
 String CompatUtility::GetHostAlias(const Host::Ptr& host)
 {
        if (!host->GetDisplayName().IsEmpty())
index 5ee326c12b50d2dfed95ee8a70934f6b445d16f5..d97b4673f402aaf8ba1e378d1a7104ea52f30230 100644 (file)
@@ -44,6 +44,8 @@ public:
        static String GetCommandName(const Command::Ptr command);
 
        /* host */
+       static int GetHostCurrentState(const Host::Ptr& host);
+       static String GetHostStateString(const Host::Ptr& host);
        static String GetHostAlias(const Host::Ptr& host);
        static int GetHostNotifyOnDown(const Host::Ptr& host);
        static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
index b4d364011b01f21890a6561f03764afe21b652db..45f275b49c86eeaec854de6f6eab94114b9dab34 100644 (file)
@@ -135,21 +135,21 @@ bool Dependency::IsAvailable(DependencyType dt) const
 {
        Checkable::Ptr parent = GetParent();
 
-       Host::Ptr host;
-       Service::Ptr service;
-       tie(host, service) = GetHostService(parent);
+       Host::Ptr parentHost;
+       Service::Ptr parentService;
+       tie(parentHost, parentService) = GetHostService(parent);
 
        /* ignore if it's the same checkable object */
        if (parent == GetChild()) {
                Log(LogNotice, "Dependency")
-                   << "Dependency '" << GetName() << "' passed: Parent and child " << (service ? "service" : "host") << " are identical.";
+                   << "Dependency '" << GetName() << "' passed: Parent and child " << (parentService ? "service" : "host") << " are identical.";
                return true;
        }
 
        /* ignore pending  */
        if (!parent->GetLastCheckResult()) {
                Log(LogNotice, "Dependency")
-                   << "Dependency '" << GetName() << "' passed: " << (service ? "Service" : "Host") << " '" << parent->GetName() << "' hasn't been checked yet.";
+                   << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' hasn't been checked yet.";
                return true;
        }
 
@@ -157,25 +157,25 @@ bool Dependency::IsAvailable(DependencyType dt) const
                /* ignore soft states */
                if (parent->GetStateType() == StateTypeSoft) {
                        Log(LogNotice, "Dependency")
-                           << "Dependency '" << GetName() << "' passed: " << (service ? "Service" : "Host") << " '" << parent->GetName() << "' is in a soft state.";
+                           << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state.";
                        return true;
                }
        } else {
                Log(LogNotice, "Dependency")
-                   << "Dependency '" << GetName() << "' failed: " << (service ? "Service" : "Host") << " '" << parent->GetName() << "' is in a soft state.";
+                   << "Dependency '" << GetName() << "' failed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state.";
        }
 
        int state;
 
-       if (service)
-               state = ServiceStateToFilter(service->GetState());
+       if (parentService)
+               state = ServiceStateToFilter(parentService->GetState());
        else
-               state = HostStateToFilter(host->GetState());
+               state = HostStateToFilter(parentHost->GetState());
 
        /* check state */
        if (state & GetStateFilter()) {
                Log(LogNotice, "Dependency")
-                   << "Dependency '" << GetName() << "' passed: " << (service ? "Service" : "Host") << " '" << parent->GetName() << "' matches state filter.";
+                   << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' matches state filter.";
                return true;
        }
 
@@ -199,8 +199,8 @@ bool Dependency::IsAvailable(DependencyType dt) const
 
        Log(LogNotice, "Dependency")
            << "Dependency '" << GetName() << "' failed. Parent "
-           << (service ? "service" : "host") << " '" << parent->GetName() << "' is "
-           << (service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
+           << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is "
+           << (parentService ? Service::StateToString(parentService->GetState()) : Host::StateToString(parentHost->GetState()));
 
        return false;
 }
index 053a8f8dd92ab061961933dd764836233866718b..f3a2940ed1fbc64a800da6241ce26bff39e1c9f6 100644 (file)
@@ -150,7 +150,7 @@ void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification
                fields->Set("short_message", output);
        } else {
                fields->Set("_type", "HOST NOTIFICATION");
-               fields->Set("short_message", "(" + (host->IsReachable() ? Host::StateToString(host->GetState()) : String("UNREACHABLE")) + ")");
+               fields->Set("short_message", "(" + CompatUtility::GetHostStateString(host) + ")");
        }
 
        fields->Set("_state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));