| 293 | } |
| 294 | |
| 295 | bool Dependency::IsAvailable(DependencyType dt) const |
| 296 | { |
| 297 | Checkable::Ptr parent = GetParent(); |
| 298 | |
| 299 | Host::Ptr parentHost; |
| 300 | Service::Ptr parentService; |
| 301 | tie(parentHost, parentService) = GetHostService(parent); |
| 302 | |
| 303 | /* ignore if it's the same checkable object */ |
| 304 | if (parent == GetChild()) { |
| 305 | Log(LogNotice, "Dependency") |
| 306 | << "Dependency '" << GetName() << "' passed: Parent and child " << (parentService ? "service" : "host") << " are identical."; |
| 307 | return true; |
| 308 | } |
| 309 | |
| 310 | /* ignore pending */ |
| 311 | if (!parent->GetLastCheckResult()) { |
| 312 | Log(LogNotice, "Dependency") |
| 313 | << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' hasn't been checked yet."; |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | if (GetIgnoreSoftStates()) { |
| 318 | /* ignore soft states */ |
| 319 | if (parent->GetStateType() == StateTypeSoft) { |
| 320 | Log(LogNotice, "Dependency") |
| 321 | << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state."; |
| 322 | return true; |
| 323 | } |
| 324 | } else { |
| 325 | Log(LogNotice, "Dependency") |
| 326 | << "Dependency '" << GetName() << "' failed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state."; |
| 327 | } |
| 328 | |
| 329 | int state; |
| 330 | |
| 331 | if (parentService) |
| 332 | state = ServiceStateToFilter(parentService->GetState()); |
| 333 | else |
| 334 | state = HostStateToFilter(parentHost->GetState()); |
| 335 | |
| 336 | /* check state */ |
| 337 | if (state & GetStateFilter()) { |
| 338 | Log(LogNotice, "Dependency") |
| 339 | << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' matches state filter."; |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | /* ignore if not in time period */ |
| 344 | TimePeriod::Ptr tp = GetPeriod(); |
| 345 | if (tp && !tp->IsInside(Utility::GetTime())) { |
| 346 | Log(LogNotice, "Dependency") |
| 347 | << "Dependency '" << GetName() << "' passed: Outside time period."; |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | if (dt == DependencyCheckExecution && !GetDisableChecks()) { |
| 352 | Log(LogNotice, "Dependency") |
no test coverage detected