Merge pull request #7684 from Icinga/bugfix/is_handled-host-down-7673

IcingaDB: update service state on Host#problem change
This commit is contained in:
Noah Hilverling 2019-12-04 14:43:09 +01:00 committed by GitHub
commit 92e51a3f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 4 deletions

View File

@ -248,7 +248,20 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
SetCheckAttempt(attempt);
ServiceState new_state = cr->GetState();
SetStateRaw(new_state);
if (service) {
SetStateRaw(new_state);
} else {
bool wasProblem = GetProblem();
SetStateRaw(new_state);
if (GetProblem() != wasProblem) {
for (auto& service : host->GetServices()) {
Service::OnHostProblemChanged(service, cr, origin);
}
}
}
bool stateChange;

View File

@ -13,6 +13,8 @@ using namespace icinga;
REGISTER_TYPE(Service);
boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, const MessageOrigin::Ptr&)> Service::OnHostProblemChanged;
String ServiceNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const
{
Service::Ptr service = dynamic_pointer_cast<Service>(context);

View File

@ -44,6 +44,8 @@ public:
static void EvaluateApplyRules(const Host::Ptr& host);
static boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, const MessageOrigin::Ptr&)> OnHostProblemChanged;
protected:
void OnAllConfigLoaded() override;
void CreateChildObjects(const Type::Ptr& childType) override;

View File

@ -94,6 +94,10 @@ void IcingaDB::ConfigStaticInitialize()
Checkable::OnNewCheckResult.connect([](const Checkable::Ptr& checkable, const CheckResult::Ptr&, const MessageOrigin::Ptr&) {
IcingaDB::NewCheckResultHandler(checkable);
});
Service::OnHostProblemChanged.connect([](const Service::Ptr& service, const CheckResult::Ptr&, const MessageOrigin::Ptr&) {
IcingaDB::StateChangeHandler(service);
});
}
void IcingaDB::UpdateAllConfigObjects()
@ -1717,9 +1721,8 @@ Dictionary::Ptr IcingaDB::SerializeState(const Checkable::Ptr& checkable)
attrs->Set("check_source", cr->GetCheckSource());
}
bool isProblem = checkable->HasBeenChecked() && !checkable->IsStateOK(checkable->GetStateRaw());
attrs->Set("is_problem", isProblem);
attrs->Set("is_handled", isProblem && (checkable->IsInDowntime() || checkable->IsAcknowledged()));
attrs->Set("is_problem", checkable->GetProblem());
attrs->Set("is_handled", checkable->GetHandled());
attrs->Set("is_reachable", checkable->IsReachable());
attrs->Set("is_flapping", checkable->IsFlapping());