From 798c56b80961ecd3caecc0e6f2df017a20f3e70a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 3 Dec 2019 16:51:34 +0100 Subject: [PATCH 1/2] IcingaDB: update service state on Host#problem change refs #7673 --- lib/icinga/checkable-check.cpp | 15 ++++++++++++++- lib/icinga/service.cpp | 2 ++ lib/icinga/service.hpp | 2 ++ lib/icingadb/icingadb-objects.cpp | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index 8443fdc7f..42d563ea6 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -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; diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index ec80aa6dc..9d3495667 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -13,6 +13,8 @@ using namespace icinga; REGISTER_TYPE(Service); +boost::signals2::signal Service::OnHostProblemChanged; + String ServiceNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const { Service::Ptr service = dynamic_pointer_cast(context); diff --git a/lib/icinga/service.hpp b/lib/icinga/service.hpp index 0e6e4d8d3..493f261e2 100644 --- a/lib/icinga/service.hpp +++ b/lib/icinga/service.hpp @@ -44,6 +44,8 @@ public: static void EvaluateApplyRules(const Host::Ptr& host); + static boost::signals2::signal OnHostProblemChanged; + protected: void OnAllConfigLoaded() override; void CreateChildObjects(const Type::Ptr& childType) override; diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index 77d058f29..386983f09 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -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() From 5c45c198ff3b411fa0fc0346ff2f88bcba02cbad Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 3 Dec 2019 17:44:48 +0100 Subject: [PATCH 2/2] IcingaDB#SerializeState(): correct Checkable#is_{problem,handled} refs #7673 --- lib/icingadb/icingadb-objects.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index 386983f09..e13a4193b 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -1697,9 +1697,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());