diff --git a/cib/service.cpp b/cib/service.cpp index 7ca10d6e3..0b29e8b6f 100644 --- a/cib/service.cpp +++ b/cib/service.cpp @@ -186,22 +186,35 @@ void Service::InvalidateDependencyCache(void) m_DependencyCacheValid = false; } -ServiceStatusMessage Service::CalculateCombinedStatus(ServiceStatusMessage *input, const vector& parents) +ServiceStatusMessage Service::CalculateCombinedStatus(Service *current, ServiceStatusMessage *input, const vector& parents) { vector failedServices; time_t nextCheck = -1; - time_t lastChange = -1; vector::const_iterator it; for (it = parents.begin(); it != parents.end(); it++) { Service parent = *it; - if (parent.GetState() != StateOK && parent.GetState() != StateWarning) - failedServices.push_back(parent); + if (current && current->GetName() == parent.GetName()) + continue; - if (lastChange == -1 || parent.GetLastStateChange() > lastChange) - lastChange = parent.GetLastStateChange(); + 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(); diff --git a/cib/service.h b/cib/service.h index 95796b8e0..431849ce7 100644 --- a/cib/service.h +++ b/cib/service.h @@ -50,7 +50,7 @@ public: static void UpdateDependencyCache(void); static void InvalidateDependencyCache(void); - static ServiceStatusMessage CalculateCombinedStatus(ServiceStatusMessage *input, const vector& parents); + static ServiceStatusMessage CalculateCombinedStatus(Service *current, ServiceStatusMessage *input, const vector& parents); void SetNextCheck(time_t nextCheck); time_t GetNextCheck(void); diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 9809bf81b..17ae39249 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -113,6 +113,9 @@ void CompatComponent::DumpServiceStatus(ofstream& fp, Service service) int state = service.GetState(); + if (state == StateUnreachable) + state = StateCritical; + if (state >= StateUnknown) state = StateUnknown; diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index ec9f6f616..beef490f1 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -315,7 +315,7 @@ void DelegationComponent::CheckResultRequestHandler(const Endpoint::Ptr& sender, vector affectedServices = child.GetParents(); affectedServices.push_back(child); - ServiceStatusMessage statusmsg = Service::CalculateCombinedStatus(NULL, affectedServices); + ServiceStatusMessage statusmsg = Service::CalculateCombinedStatus(&child, NULL, affectedServices); statusmsg.SetService(child.GetName()); ServiceState state = StateUnreachable; @@ -335,7 +335,7 @@ void DelegationComponent::CheckResultRequestHandler(const Endpoint::Ptr& sender, rm.SetMethod("delegation::ServiceStatus"); vector parents = service.GetParents(); - ServiceStatusMessage statusmsg = Service::CalculateCombinedStatus(¶ms, parents); + ServiceStatusMessage statusmsg = Service::CalculateCombinedStatus(&service, ¶ms, parents); statusmsg.SetService(service.GetName()); rm.SetParams(statusmsg);