From: Gunnar Beutner Date: Tue, 3 Jul 2012 13:11:11 +0000 (+0200) Subject: Re-designed reachability detection. X-Git-Tag: v0.0.1~315 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d26d8e7bb7a449b551acee7d174b935a24e43900;p=icinga2 Re-designed reachability detection. --- diff --git a/cib/service.cpp b/cib/service.cpp index 0b29e8b6f..f15e30de1 100644 --- a/cib/service.cpp +++ b/cib/service.cpp @@ -186,74 +186,17 @@ void Service::InvalidateDependencyCache(void) m_DependencyCacheValid = false; } -ServiceStatusMessage Service::CalculateCombinedStatus(Service *current, ServiceStatusMessage *input, const vector& parents) +bool Service::IsReachable(void) const { - vector failedServices; + vector parents = GetParents(); - time_t nextCheck = -1; - - vector::const_iterator it; + vector::iterator it; for (it = parents.begin(); it != parents.end(); it++) { - Service parent = *it; - - if (current && current->GetName() == parent.GetName()) - continue; - - if (!parent.HasLastCheckResult()) - continue; - - string svcname; - ServiceState state = StateUnknown; - ServiceStateType type = StateTypeHard; - if (input && input->GetService(&svcname) && svcname == parent.GetName()) { - input->GetState(&state); - input->GetStateType(&type); - } else { - state = parent.GetState(); - type = parent.GetStateType(); - } - - if (state != StateOK && state != StateWarning && type == StateTypeHard) - failedServices.push_back(parent); - - if (nextCheck == -1 || parent.GetNextCheck() < nextCheck) - nextCheck = parent.GetNextCheck(); - } - - string message; - ServiceState state; - - if (failedServices.empty()) { - if (input) - return *input; - - state = StateOK; - message = "Dependant services are available."; - } else { - state = StateUnreachable; - message = "One or more dependant services have failed."; + if (!it->IsReachable()) + return false; } - - ServiceStatusMessage result; - result.SetState(state); - result.SetStateType(StateTypeHard); - result.SetCurrentCheckAttempt(1); - result.SetNextCheck(nextCheck); - - time_t now; - time(&now); - - CheckResult cr; - cr.SetScheduleStart(now); - cr.SetScheduleEnd(now); - cr.SetExecutionStart(now); - cr.SetExecutionEnd(now); - cr.SetOutput(message); - cr.SetState(state); - - result.SetCheckResult(cr); - - return result; + + return true; } void Service::SetNextCheck(time_t nextCheck) @@ -407,7 +350,6 @@ ServiceState Service::StateFromString(const string& state) stateLookup["ok"] = StateOK; stateLookup["warning"] = StateWarning; stateLookup["critical"] = StateCritical; - stateLookup["unreachable"] = StateUnreachable; stateLookup["uncheckable"] = StateUncheckable; stateLookup["unknown"] = StateUnknown; } @@ -430,8 +372,6 @@ string Service::StateToString(ServiceState state) return "warning"; case StateCritical: return "critical"; - case StateUnreachable: - return "unreachable"; case StateUncheckable: return "uncheckable"; case StateUnknown: diff --git a/cib/service.h b/cib/service.h index 431849ce7..67eddb9ff 100644 --- a/cib/service.h +++ b/cib/service.h @@ -10,7 +10,6 @@ enum ServiceState StateWarning, StateCritical, StateUnknown, - StateUnreachable, StateUncheckable, }; @@ -50,7 +49,7 @@ public: static void UpdateDependencyCache(void); static void InvalidateDependencyCache(void); - static ServiceStatusMessage CalculateCombinedStatus(Service *current, ServiceStatusMessage *input, const vector& parents); + bool IsReachable(void) const; void SetNextCheck(time_t nextCheck); time_t GetNextCheck(void); diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 17ae39249..bc670b0ff 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -113,8 +113,16 @@ void CompatComponent::DumpServiceStatus(ofstream& fp, Service service) int state = service.GetState(); - if (state == StateUnreachable) + if (!service.IsReachable()) { state = StateCritical; + + string text = "One or more parent services are unavailable."; + + if (output.empty()) + output = text; + else + output = text + " (" + output + ")"; + } if (state >= StateUnknown) state = StateUnknown; diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index beef490f1..5729d8d00 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -306,39 +306,10 @@ void DelegationComponent::CheckResultRequestHandler(const Endpoint::Ptr& sender, if (!service.IsAllowedChecker(sender->GetIdentity())) return; - vector children = service.GetChildren(); - - vector::iterator it; - for (it = children.begin(); it != children.end(); it++) { - Service child = *it; - - vector affectedServices = child.GetParents(); - affectedServices.push_back(child); - - ServiceStatusMessage statusmsg = Service::CalculateCombinedStatus(&child, NULL, affectedServices); - statusmsg.SetService(child.GetName()); - - ServiceState state = StateUnreachable; - statusmsg.GetState(&state); - - if (child.GetState() == StateUnreachable || state == StateUnreachable) { - RequestMessage rm; - rm.SetMethod("delegation::ServiceStatus"); - rm.SetParams(statusmsg); - - EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, rm); - } - } - /* send state update */ RequestMessage rm; rm.SetMethod("delegation::ServiceStatus"); - - vector parents = service.GetParents(); - ServiceStatusMessage statusmsg = Service::CalculateCombinedStatus(&service, ¶ms, parents); - statusmsg.SetService(service.GetName()); - - rm.SetParams(statusmsg); + rm.SetParams(params); EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, rm); }